From f127f5504082ccfff5858a8b3be22f44411dfe60 Mon Sep 17 00:00:00 2001 From: Evgeny Kuzyakov Date: Thu, 5 Mar 2020 16:17:00 -0800 Subject: [PATCH] fix(runtime): Fix state change check during view call (#2229) Fixes #2226 The current behavior of a view call is to prohibit state changes. This change moves check from the end of the state viewer to VMLogic by prohibiting state changes functions during view calls. ## Test plan: - Fixed state change tests. Previously the test didn't verify error type. The error was `MethodNotFound` and also alice account was wrong. - Added unit tests for the new prohibited methods. --- runtime/near-vm-logic/src/logic.rs | 12 +++++++++++ .../near-vm-logic/tests/test_view_method.rs | 2 ++ .../tests/res/test_contract_rs.wasm | Bin 81870 -> 82385 bytes .../tests/test-contract-rs/build.sh | 2 +- .../tests/test-contract-rs/src/lib.rs | 7 +++++++ runtime/runtime/src/state_viewer.rs | 19 ++++++++++-------- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/runtime/near-vm-logic/src/logic.rs b/runtime/near-vm-logic/src/logic.rs index a289646938e..f472efda5e6 100644 --- a/runtime/near-vm-logic/src/logic.rs +++ b/runtime/near-vm-logic/src/logic.rs @@ -1850,6 +1850,7 @@ impl<'a> VMLogic<'a> { /// * If the length of the key exceeds `max_length_storage_key` returns `KeyLengthExceeded`. /// * If the length of the value exceeds `max_length_storage_value` returns /// `ValueLengthExceeded`. + /// * If called as view function returns `ProhibitedInView``. /// /// # Cost /// @@ -1866,6 +1867,11 @@ impl<'a> VMLogic<'a> { register_id: u64, ) -> Result { self.gas_counter.pay_base(base)?; + if self.context.is_view { + return Err( + HostError::ProhibitedInView { method_name: "storage_write".to_string() }.into() + ); + } self.gas_counter.pay_base(storage_write_base)?; // All iterators that were valid now become invalid for invalidated_iter_idx in self.valid_iterators.drain() { @@ -1998,6 +2004,7 @@ impl<'a> VMLogic<'a> { /// * If returning the preempted value into the registers exceed the memory container it returns /// `MemoryAccessViolation`. /// * If the length of the key exceeds `max_length_storage_key` returns `KeyLengthExceeded`. + /// * If called as view function returns `ProhibitedInView``. /// /// # Cost /// @@ -2005,6 +2012,11 @@ impl<'a> VMLogic<'a> { /// + cost to read the key + cost to write the value`. pub fn storage_remove(&mut self, key_len: u64, key_ptr: u64, register_id: u64) -> Result { self.gas_counter.pay_base(base)?; + if self.context.is_view { + return Err( + HostError::ProhibitedInView { method_name: "storage_remove".to_string() }.into() + ); + } self.gas_counter.pay_base(storage_remove_base)?; // All iterators that were valid now become invalid for invalidated_iter_idx in self.valid_iterators.drain() { diff --git a/runtime/near-vm-logic/tests/test_view_method.rs b/runtime/near-vm-logic/tests/test_view_method.rs index 86e6e3762fb..84d551945c3 100644 --- a/runtime/near-vm-logic/tests/test_view_method.rs +++ b/runtime/near-vm-logic/tests/test_view_method.rs @@ -40,6 +40,8 @@ fn test_prohibited_view_methods() { test_prohibited!(promise_results_count); test_prohibited!(promise_result, 0, 0); test_prohibited!(promise_return, 0); + test_prohibited!(storage_write, 0, 0, 0, 0, 0); + test_prohibited!(storage_remove, 0, 0, 0); } #[test] diff --git a/runtime/near-vm-runner/tests/res/test_contract_rs.wasm b/runtime/near-vm-runner/tests/res/test_contract_rs.wasm index 1d28244f36ba3ea8e2d4ea88e60d8221a30a9150..dda54bea68e14824c1eeb0f8bcd88f953b4e219c 100755 GIT binary patch delta 14231 zcmd6O34ByVv+wCXlVp;aNe(7tCE?5f61Idb3(E(bC@8C+Vi+JpNJ0{D`*Z@b zuYpEDKtx=KiWnU~Ob`VW5tSW9WJlRlR8&-ysP|ueW+oxg`|j`e-tWCPFw>{2s;jH2 ztE>A|clP{g+5cEb^&X3Qnf)O4Te@U2`BCsoUwmv#u_Z<)+M-#kU9l)ht5u1% zDoS*;O>G{nC{~df($%Y|_$0O9DyMeI%~6YuRk@m?f(hd)9_hcTwqy!EiHx3A6{u(x zJgJd2T45^surX^gi;d=t=>dlrCDf#>Sabn#a6}URg8*N+X7{%VhdXm z(pr2S(s{r<7IlAVLAg73y!*l2$$5p7+{%0wQR>bc?XN9hj>6)xxn;!@+~wm6ipDAn zSybMA#iixB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Ru|Q8COF`P(lbkq43}(dbmzc4Df`*lT)NB zk;%Q#`l|p!;D3_z09+j}PMTQoxFi2@d;Sz2{?mxkW+0jXmHVOZjsQL7!|lq)+Lgf> z+R$HaSN@@0`PX)3iHY`Ah3T}LZ@NOrA#LOo|9Yhgi@*stCb+=ws8Nh-2Go;}Nv1Ksj(e~xy$ zt|w5i7n0*B;S&i@RI75d`@LT~(YOVEcuj?nO#nLpjDZLLz#t@+vm2>#%}|3n{tVCt z@B~0)Rs_2FR2>;eWB5Zi5~I?Lvhapc04=S^X7g1yx|crEyLaz@goCcIqLZo^jntz% z0X#a=o#0je0B1sdAi((mQS@g3$^hHbX97K1;xVX4r+gZOM(F9s3Vgdj`5ym{vhdi^ zfIwB+GkSnO`1^#Rj}fvG2*A9=rAssix=(CXF4oJs?Q;r>97&V&N|N#lCV}aD_wF;h z>U=7l%%iBthGD^g(bNK`5;c!!62H}2dF&u*#y#~y~d41YZB4`c0+B^!N1gP zSX4>IPUoX!Dq-UfT&h>)ko>HV-+1lCnO|58UH9e z=rlMy9<^|2y1~l6#xJL diff --git a/runtime/near-vm-runner/tests/test-contract-rs/build.sh b/runtime/near-vm-runner/tests/test-contract-rs/build.sh index d076eafa7b5..8b78ebcc34b 100755 --- a/runtime/near-vm-runner/tests/test-contract-rs/build.sh +++ b/runtime/near-vm-runner/tests/test-contract-rs/build.sh @@ -1,5 +1,5 @@ #!/bin/bash -RUSTFLAGS='-C link-arg=-s' cargo +nightly build --target wasm32-unknown-unknown --release +RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release cp target/wasm32-unknown-unknown/release/test_contract_rs.wasm ../res/ rm -rf target diff --git a/runtime/near-vm-runner/tests/test-contract-rs/src/lib.rs b/runtime/near-vm-runner/tests/test-contract-rs/src/lib.rs index 1145766b510..f68f59da193 100644 --- a/runtime/near-vm-runner/tests/test-contract-rs/src/lib.rs +++ b/runtime/near-vm-runner/tests/test-contract-rs/src/lib.rs @@ -271,6 +271,13 @@ pub unsafe fn run_test() { value_return(value.len() as u64, value.as_ptr() as _); } +#[no_mangle] +pub unsafe fn run_test_with_storage_change() { + let key = b"hello"; + let value = b"world"; + storage_write(key.len() as _, key.as_ptr() as _, value.len() as _, value.as_ptr() as _, 0); +} + #[no_mangle] pub unsafe fn sum_with_input() { input(0); diff --git a/runtime/runtime/src/state_viewer.rs b/runtime/runtime/src/state_viewer.rs index 9135dd60a6b..8bd37431121 100644 --- a/runtime/runtime/src/state_viewer.rs +++ b/runtime/runtime/src/state_viewer.rs @@ -161,10 +161,6 @@ impl TrieViewer { let outcome = outcome.unwrap(); debug!(target: "runtime", "(exec time {}) result of execution: {:#?}", time_str, outcome); logs.extend(outcome.logs); - let trie_update = state_update.finalize()?; - if trie_update.new_root != root { - return Err("function call for viewing tried to change storage".into()); - } let mut result = vec![]; if let ReturnData::Value(buf) = &outcome.return_data { result = buf.clone(); @@ -218,7 +214,11 @@ mod tests { &mut logs, ); - assert!(result.is_err()); + let err = result.unwrap_err(); + assert!( + err.to_string().contains(r#"Contract ID "bad!contract" is not valid"#), + format!("Got different error that doesn't match: {}", err) + ); } #[test] @@ -230,13 +230,16 @@ mod tests { root, 1, 1, - &alice_account(), + &AccountId::from("test.contract"), "run_test_with_storage_change", &[], &mut logs, ); - // run_test tries to change storage, so it should fail - assert!(result.is_err()); + let err = result.unwrap_err(); + assert!( + err.to_string().contains(r#"ProhibitedInView { method_name: "storage_write" }"#), + format!("Got different error that doesn't match: {}", err) + ); } #[test]