From 801dc0cc33ecd01b6f8064644289879757114b56 Mon Sep 17 00:00:00 2001 From: Mikers Date: Tue, 19 Nov 2024 16:35:58 -1000 Subject: [PATCH 01/46] initial implementation of EIP-1153: Transient Storage - TODOs remain around comparing the liveliness of the transient data and validating that functionality in a test --- actors/evm/src/interpreter/execution.rs | 4 + .../evm/src/interpreter/instructions/mod.rs | 2 + .../src/interpreter/instructions/storage.rs | 73 +++++++++++++++++++ actors/evm/src/interpreter/system.rs | 61 +++++++++++++++- actors/evm/src/state.rs | 14 ++++ 5 files changed, 152 insertions(+), 2 deletions(-) diff --git a/actors/evm/src/interpreter/execution.rs b/actors/evm/src/interpreter/execution.rs index 22f013b8d..0775f8054 100644 --- a/actors/evm/src/interpreter/execution.rs +++ b/actors/evm/src/interpreter/execution.rs @@ -163,6 +163,8 @@ pub mod opcodes { 0x59: MSIZE, 0x5a: GAS, 0x5b: JUMPDEST, + 0x5c: TLOAD, + 0x5d: TSTORE, 0x5e: MCOPY, 0x5F: PUSH0, 0x60: PUSH1, @@ -400,6 +402,8 @@ mod tests { MSTORE8, SLOAD, SSTORE, + TLOAD, + TSTORE, LOG0, LOG1, LOG2, diff --git a/actors/evm/src/interpreter/instructions/mod.rs b/actors/evm/src/interpreter/instructions/mod.rs index b97b407e1..b5175726b 100644 --- a/actors/evm/src/interpreter/instructions/mod.rs +++ b/actors/evm/src/interpreter/instructions/mod.rs @@ -338,6 +338,8 @@ def_stdproc! { MSTORE(a, b) => memory::mstore } def_stdproc! { MSTORE8(a, b) => memory::mstore8 } def_stdfun! { SLOAD(a) => storage::sload } def_stdproc! { SSTORE(a, b) => storage::sstore } +def_stdfun! { TLOAD(a) => storage::tload } +def_stdproc! { TSTORE(a, b) => storage::tstore } def_stdfun! { MSIZE() => memory::msize } def_stdfun! { GAS() => context::gas } def_stdlog! { LOG0(0, ()) } diff --git a/actors/evm/src/interpreter/instructions/storage.rs b/actors/evm/src/interpreter/instructions/storage.rs index 06e66cc8a..5ecefdc1e 100644 --- a/actors/evm/src/interpreter/instructions/storage.rs +++ b/actors/evm/src/interpreter/instructions/storage.rs @@ -30,6 +30,30 @@ pub fn sstore( system.set_storage(key, value) } +#[inline] +pub fn tload( + _state: &mut ExecutionState, + system: &mut System, + location: U256, +) -> Result { + // get from storage and place on stack + system.get_transient_storage(location) +} + +#[inline] +pub fn tstore( + _state: &mut ExecutionState, + system: &mut System, + key: U256, + value: U256, +) -> Result<(), ActorError> { + if system.readonly { + return Err(ActorError::read_only("store called while read-only".into())); + } + + system.set_transient_storage(key, value) +} + #[cfg(test)] mod tests { use fil_actors_evm_shared::uints::U256; @@ -82,4 +106,53 @@ mod tests { assert_eq!(m.system.get_storage(U256::from(0)).unwrap(), U256::from(0x42)); }; } + + // TODO test transient storage lifecycle + + #[test] + fn test_tload() { + // happy path + evm_unit_test! { + (m) { + TLOAD; + } + m.system.set_transient_storage(U256::from(0), U256::from(0x42)).unwrap(); + m.state.stack.push(U256::from(0)).unwrap(); + let result = m.step(); + assert!(result.is_ok(), "execution step failed"); + assert_eq!(m.state.stack.len(), 1); + assert_eq!(m.state.stack.pop().unwrap(), U256::from(0x42)); + }; + } + + #[test] + fn test_tload_oob() { + // oob access -- it is a zero + evm_unit_test! { + (m) { + TLOAD; + } + m.state.stack.push(U256::from(1234)).unwrap(); + let result = m.step(); + assert!(result.is_ok(), "execution step failed"); + assert_eq!(m.state.stack.len(), 1); + assert_eq!(m.state.stack.pop().unwrap(), U256::from(0)); + }; + } + + #[test] + fn test_tstore() { + evm_unit_test! { + (m) { + TSTORE; + } + + m.state.stack.push(U256::from(0x42)).unwrap(); + m.state.stack.push(U256::from(0)).unwrap(); + let result = m.step(); + assert!(result.is_ok(), "execution step failed"); + assert_eq!(m.state.stack.len(), 0); + assert_eq!(m.system.get_transient_storage(U256::from(0)).unwrap(), U256::from(0x42)); + }; + } } diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index ceb247496..f6df0755d 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -16,7 +16,7 @@ use fvm_shared::error::{ErrorNumber, ExitCode}; use fvm_shared::sys::SendFlags; use fvm_shared::{MethodNum, Response, IPLD_RAW, METHOD_SEND}; -use crate::state::{State, Tombstone}; +use crate::state::{State, Tombstone, TransientDataLifespan}; use crate::BytecodeHash; use cid::Cid; @@ -91,6 +91,11 @@ pub struct System<'r, RT: Runtime> { bytecode: Option, /// The contract's EVM storage slots. slots: StateKamt, + + /// The contract's EVM transient storage slots. + transient_slots: StateKamt, + pub(crate) transient_data_lifespan: Option, + /// The contracts "nonce" (incremented when creating new actors). pub(crate) nonce: u64, /// The last saved state root. None if the current state hasn't been saved yet. @@ -111,9 +116,12 @@ impl<'r, RT: Runtime> System<'r, RT> { RT::Blockstore: Clone, { let store = rt.store().clone(); + let transient_store = rt.store().clone(); Self { rt, slots: StateKamt::new_with_config(store, KAMT_CONFIG.clone()), + transient_slots: StateKamt::new_with_config(transient_store, KAMT_CONFIG.clone()), + transient_data_lifespan: None, nonce: 1, saved_state_root: None, bytecode: None, @@ -164,6 +172,7 @@ impl<'r, RT: Runtime> System<'r, RT> { RT::Blockstore: Clone, { let store = rt.store().clone(); + let transient_store = rt.store().clone(); let state_root = rt.get_state_root()?; let state: State = store .get_cbor(&state_root) @@ -182,6 +191,13 @@ impl<'r, RT: Runtime> System<'r, RT> { rt, slots: StateKamt::load_with_config(&state.contract_state, store, KAMT_CONFIG.clone()) .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?, + transient_slots: StateKamt::load_with_config( + &state.transient_state, + transient_store, + KAMT_CONFIG.clone(), + ) + .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?, + transient_data_lifespan: state.transient_data_lifespan, nonce: state.nonce, saved_state_root: Some(state_root), bytecode: Some(EvmBytecode::new(state.bytecode, state.bytecode_hash)), @@ -255,7 +271,7 @@ impl<'r, RT: Runtime> System<'r, RT> { Ok(result.map_err(|e| e.0)) } - /// Flush the actor state (bytecode, nonce, and slots). + /// Flush the actor state (bytecode, nonce, transient data and slots). pub fn flush(&mut self) -> Result<(), ActorError> { if self.saved_state_root.is_some() { return Ok(()); @@ -281,6 +297,11 @@ impl<'r, RT: Runtime> System<'r, RT> { ExitCode::USR_ILLEGAL_STATE, "failed to flush contract state", )?, + transient_state: self.transient_slots.flush().context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to flush contract state", + )?, + transient_data_lifespan: self.transient_data_lifespan, nonce: self.nonce, tombstone: self.tombstone, }, @@ -314,6 +335,10 @@ impl<'r, RT: Runtime> System<'r, RT> { self.slots .set_root(&state.contract_state) .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?; + self.transient_slots + .set_root(&state.transient_state) + .context_code(ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore")?; + self.transient_data_lifespan = state.transient_data_lifespan; self.nonce = state.nonce; self.saved_state_root = Some(root); self.bytecode = Some(EvmBytecode::new(state.bytecode, state.bytecode_hash)); @@ -384,6 +409,38 @@ impl<'r, RT: Runtime> System<'r, RT> { }; Ok(()) } + /// + /// Get value of a storage key. + pub fn get_transient_storage(&mut self, key: U256) -> Result { + //TODO check tombstone for liveliness of data + Ok(self + .transient_slots + .get(&key) + .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to clear storage slot")? + .cloned() + .unwrap_or_default()) + } + + /// Set value of a storage key. + pub fn set_transient_storage(&mut self, key: U256, value: U256) -> Result<(), ActorError> { + //TODO check tombstone for liveliness of data + let changed = if value.is_zero() { + self.transient_slots + .delete(&key) + .map(|v| v.is_some()) + .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to clear storage slot")? + } else { + self.transient_slots + .set(key, value) + .map(|v| v != Some(value)) + .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to update storage slot")? + }; + + if changed { + self.saved_state_root = None; // dirty. + }; + Ok(()) + } /// Resolve the address to the ethereum equivalent, if possible. /// diff --git a/actors/evm/src/state.rs b/actors/evm/src/state.rs index 040064ee4..837bdd1d5 100644 --- a/actors/evm/src/state.rs +++ b/actors/evm/src/state.rs @@ -17,6 +17,15 @@ pub struct Tombstone { pub nonce: u64, } +/// A structure representing the transient data lifespan. +#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize_tuple, Deserialize_tuple)] +pub struct TransientDataLifespan { + /// The origin actor ID associated with the transient data. + pub origin: ActorID, + /// A unique nonce identifying the transaction. + pub nonce: u64, +} + /// A Keccak256 digest of EVM bytecode. #[derive(Deserialize, Serialize, Clone, Copy, Eq, PartialEq)] #[serde(transparent)] @@ -106,6 +115,11 @@ pub struct State { /// KAMT pub contract_state: Cid, + /// The EVM contract state diciontary that represents the transient storage + pub transient_state: Cid, + /// The nonce and actor id that represents the lifespan of the transient storage data + pub transient_data_lifespan: Option, + /// The EVM nonce used to track how many times CREATE or CREATE2 have been called. pub nonce: u64, From ef679de10ddd00ff4a28674f3045d811ac103877 Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 21 Nov 2024 10:57:52 -1000 Subject: [PATCH 02/46] fix transient state error message --- actors/evm/src/interpreter/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index f6df0755d..2b907af9e 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -196,7 +196,7 @@ impl<'r, RT: Runtime> System<'r, RT> { transient_store, KAMT_CONFIG.clone(), ) - .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?, + .context_code(ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore")?, transient_data_lifespan: state.transient_data_lifespan, nonce: state.nonce, saved_state_root: Some(state_root), From a98c058526c027812064986f81cd02f43dece4fb Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 21 Nov 2024 11:04:48 -1000 Subject: [PATCH 03/46] remove pub visibility from transient_data_lifespan. TODO still is combine transient_slots with transient_data_lifespan anyway. --- actors/evm/src/interpreter/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 2b907af9e..3cc3e1bc6 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -94,7 +94,7 @@ pub struct System<'r, RT: Runtime> { /// The contract's EVM transient storage slots. transient_slots: StateKamt, - pub(crate) transient_data_lifespan: Option, + transient_data_lifespan: Option, /// The contracts "nonce" (incremented when creating new actors). pub(crate) nonce: u64, From 9f3e90d6c61233e227b1d50e24dd8e9240a7ebd6 Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 21 Nov 2024 13:22:25 -1000 Subject: [PATCH 04/46] further implementation of lifecycle management for transient data, TODO reinitialize does not properly clear state KAMT due to clone/reference issues that are being debugged --- actors/evm/src/interpreter/system.rs | 95 +++++++++++++++++++++------- 1 file changed, 73 insertions(+), 22 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 3cc3e1bc6..45d16f53e 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -409,36 +409,87 @@ impl<'r, RT: Runtime> System<'r, RT> { }; Ok(()) } - /// - /// Get value of a storage key. + + /// Returns the current transient data lifespan based on the execution environment. + pub fn get_current_transient_data_lifespan(&self) -> Option { + match self.rt.message().origin().id() { + Ok(origin_id) => Some(TransientDataLifespan { + origin: origin_id, + nonce: self.rt.message().nonce(), + }), + Err(_) => None, // Handle the error case by returning None + } + } + + /// Get value of a transient storage key. pub fn get_transient_storage(&mut self, key: U256) -> Result { - //TODO check tombstone for liveliness of data - Ok(self - .transient_slots - .get(&key) - .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to clear storage slot")? - .cloned() - .unwrap_or_default()) + if self.transient_data_lifespan == self.get_current_transient_data_lifespan() { + // Lifespan matches, retrieve value + Ok(self + .transient_slots + .get(&key) + .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to access transient storage slot")? + .cloned() + .unwrap_or_default()) + } else { + // Lifespan mismatch, return default value + Ok(U256::zero()) + } } - /// Set value of a storage key. + + /// Set value of a transient storage key. pub fn set_transient_storage(&mut self, key: U256, value: U256) -> Result<(), ActorError> { - //TODO check tombstone for liveliness of data - let changed = if value.is_zero() { - self.transient_slots - .delete(&key) - .map(|v| v.is_some()) - .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to clear storage slot")? + let current_lifespan = self.get_current_transient_data_lifespan(); + + if self.transient_data_lifespan == current_lifespan { + // Lifespan matches, proceed to set value + let changed = if value.is_zero() { + self.transient_slots + .delete(&key) + .map(|v| v.is_some()) + .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to clear transient storage slot")? + } else { + self.transient_slots + .set(key, value) + .map(|v| v != Some(value)) + .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to update transient storage slot")? + }; + + if changed { + self.saved_state_root = None; // Mark state as dirty + } } else { + // Lifespan mismatch + if value.is_zero() { + // If setting to default value, skip storage reset + return Ok(()); + } + + // Reset transient storage and update lifespan + self.reset_transient_storage(current_lifespan)?; self.transient_slots .set(key, value) - .map(|v| v != Some(value)) - .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to update storage slot")? - }; + .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to set transient storage after reset")?; + + } + + Ok(()) + } + + /// Reset transient storage and update lifespan. + pub fn reset_transient_storage(&mut self, new_lifespan: Option) -> Result<(), ActorError> { + // Update lifespan + self.transient_data_lifespan = new_lifespan; + + // Reinitialize the transient_slots with a fresh KAMT + //let transient_store = self.rt.store().clone(); + //self.transient_slots = StateKamt::new_with_config(transient_store, KAMT_CONFIG.clone()); + // TODO XXX reinitialize does not currently work due to blockstore reference issues + + // Mark state as dirty + self.saved_state_root = None; - if changed { - self.saved_state_root = None; // dirty. - }; Ok(()) } From 2ee1d9d8536eb39d3b118a1007d37b8ef3094189 Mon Sep 17 00:00:00 2001 From: Mikers Date: Mon, 2 Dec 2024 15:00:44 -0700 Subject: [PATCH 05/46] update evm contract State to use transient_data a composite of transient_data_state and transient_data_lifespan --- actors/evm/src/interpreter/system.rs | 25 +++++++++++++++---------- actors/evm/src/state.rs | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 45d16f53e..c4f468c2d 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -16,7 +16,7 @@ use fvm_shared::error::{ErrorNumber, ExitCode}; use fvm_shared::sys::SendFlags; use fvm_shared::{MethodNum, Response, IPLD_RAW, METHOD_SEND}; -use crate::state::{State, Tombstone, TransientDataLifespan}; +use crate::state::{State, Tombstone, TransientData, TransientDataLifespan}; use crate::BytecodeHash; use cid::Cid; @@ -192,12 +192,12 @@ impl<'r, RT: Runtime> System<'r, RT> { slots: StateKamt::load_with_config(&state.contract_state, store, KAMT_CONFIG.clone()) .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?, transient_slots: StateKamt::load_with_config( - &state.transient_state, + &state.transient_data.unwrap().transient_data_state.unwrap(), transient_store, KAMT_CONFIG.clone(), ) .context_code(ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore")?, - transient_data_lifespan: state.transient_data_lifespan, + transient_data_lifespan: state.transient_data.unwrap().transient_data_lifespan, nonce: state.nonce, saved_state_root: Some(state_root), bytecode: Some(EvmBytecode::new(state.bytecode, state.bytecode_hash)), @@ -297,11 +297,16 @@ impl<'r, RT: Runtime> System<'r, RT> { ExitCode::USR_ILLEGAL_STATE, "failed to flush contract state", )?, - transient_state: self.transient_slots.flush().context_code( - ExitCode::USR_ILLEGAL_STATE, - "failed to flush contract state", - )?, - transient_data_lifespan: self.transient_data_lifespan, + transient_data: + { Some(TransientData { + transient_data_state: Some(self.transient_slots.flush().context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to flush contract state", + )?), + transient_data_lifespan: self.transient_data_lifespan, + }) + + }, nonce: self.nonce, tombstone: self.tombstone, }, @@ -336,9 +341,9 @@ impl<'r, RT: Runtime> System<'r, RT> { .set_root(&state.contract_state) .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?; self.transient_slots - .set_root(&state.transient_state) + .set_root(&state.transient_data.unwrap().transient_data_state.unwrap()) .context_code(ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore")?; - self.transient_data_lifespan = state.transient_data_lifespan; + self.transient_data_lifespan = state.transient_data.unwrap().transient_data_lifespan; self.nonce = state.nonce; self.saved_state_root = Some(root); self.bytecode = Some(EvmBytecode::new(state.bytecode, state.bytecode_hash)); diff --git a/actors/evm/src/state.rs b/actors/evm/src/state.rs index 837bdd1d5..98dce5ffb 100644 --- a/actors/evm/src/state.rs +++ b/actors/evm/src/state.rs @@ -17,6 +17,17 @@ pub struct Tombstone { pub nonce: u64, } +/// A structure representing Transient Data +#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize_tuple, Deserialize_tuple)] +pub struct TransientData { + /// The contract transient data state dictionary. + /// Transient Data State is a map of U256 -> U256 values. + /// KAMT + pub transient_data_state: Option, + /// The data representing the transient data lifespan + pub transient_data_lifespan: Option, +} + /// A structure representing the transient data lifespan. #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize_tuple, Deserialize_tuple)] pub struct TransientDataLifespan { @@ -115,10 +126,10 @@ pub struct State { /// KAMT pub contract_state: Cid, - /// The EVM contract state diciontary that represents the transient storage - pub transient_state: Cid, - /// The nonce and actor id that represents the lifespan of the transient storage data - pub transient_data_lifespan: Option, + /// The data that containers tranisent state. The struct includes the CID of the KAMT that + /// contains the state data and the tuple of nonce and actor id that represents + /// the lifespan of the transient storage data + pub transient_data: Option, /// The EVM nonce used to track how many times CREATE or CREATE2 have been called. pub nonce: u64, From 31180a1b4e28f64e61ccf78f4fc84152ebf08a97 Mon Sep 17 00:00:00 2001 From: Mikers Date: Mon, 2 Dec 2024 15:01:27 -0700 Subject: [PATCH 06/46] cargo fmt --- actors/evm/src/interpreter/system.rs | 59 +++++++++++++++------------- actors/evm/src/state.rs | 4 +- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index c4f468c2d..3663a9ef5 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -297,15 +297,14 @@ impl<'r, RT: Runtime> System<'r, RT> { ExitCode::USR_ILLEGAL_STATE, "failed to flush contract state", )?, - transient_data: - { Some(TransientData { - transient_data_state: Some(self.transient_slots.flush().context_code( - ExitCode::USR_ILLEGAL_STATE, - "failed to flush contract state", - )?), - transient_data_lifespan: self.transient_data_lifespan, - }) - + transient_data: { + Some(TransientData { + transient_data_state: Some(self.transient_slots.flush().context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to flush contract state", + )?), + transient_data_lifespan: self.transient_data_lifespan, + }) }, nonce: self.nonce, tombstone: self.tombstone, @@ -418,10 +417,9 @@ impl<'r, RT: Runtime> System<'r, RT> { /// Returns the current transient data lifespan based on the execution environment. pub fn get_current_transient_data_lifespan(&self) -> Option { match self.rt.message().origin().id() { - Ok(origin_id) => Some(TransientDataLifespan { - origin: origin_id, - nonce: self.rt.message().nonce(), - }), + Ok(origin_id) => { + Some(TransientDataLifespan { origin: origin_id, nonce: self.rt.message().nonce() }) + } Err(_) => None, // Handle the error case by returning None } } @@ -433,7 +431,10 @@ impl<'r, RT: Runtime> System<'r, RT> { Ok(self .transient_slots .get(&key) - .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to access transient storage slot")? + .context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to access transient storage slot", + )? .cloned() .unwrap_or_default()) } else { @@ -442,7 +443,6 @@ impl<'r, RT: Runtime> System<'r, RT> { } } - /// Set value of a transient storage key. pub fn set_transient_storage(&mut self, key: U256, value: U256) -> Result<(), ActorError> { let current_lifespan = self.get_current_transient_data_lifespan(); @@ -450,15 +450,15 @@ impl<'r, RT: Runtime> System<'r, RT> { if self.transient_data_lifespan == current_lifespan { // Lifespan matches, proceed to set value let changed = if value.is_zero() { - self.transient_slots - .delete(&key) - .map(|v| v.is_some()) - .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to clear transient storage slot")? + self.transient_slots.delete(&key).map(|v| v.is_some()).context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to clear transient storage slot", + )? } else { - self.transient_slots - .set(key, value) - .map(|v| v != Some(value)) - .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to update transient storage slot")? + self.transient_slots.set(key, value).map(|v| v != Some(value)).context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to update transient storage slot", + )? }; if changed { @@ -473,17 +473,20 @@ impl<'r, RT: Runtime> System<'r, RT> { // Reset transient storage and update lifespan self.reset_transient_storage(current_lifespan)?; - self.transient_slots - .set(key, value) - .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to set transient storage after reset")?; - + self.transient_slots.set(key, value).context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to set transient storage after reset", + )?; } Ok(()) } /// Reset transient storage and update lifespan. - pub fn reset_transient_storage(&mut self, new_lifespan: Option) -> Result<(), ActorError> { + pub fn reset_transient_storage( + &mut self, + new_lifespan: Option, + ) -> Result<(), ActorError> { // Update lifespan self.transient_data_lifespan = new_lifespan; diff --git a/actors/evm/src/state.rs b/actors/evm/src/state.rs index 98dce5ffb..aa77aecdc 100644 --- a/actors/evm/src/state.rs +++ b/actors/evm/src/state.rs @@ -24,7 +24,7 @@ pub struct TransientData { /// Transient Data State is a map of U256 -> U256 values. /// KAMT pub transient_data_state: Option, - /// The data representing the transient data lifespan + /// The data representing the transient data lifespan pub transient_data_lifespan: Option, } @@ -127,7 +127,7 @@ pub struct State { pub contract_state: Cid, /// The data that containers tranisent state. The struct includes the CID of the KAMT that - /// contains the state data and the tuple of nonce and actor id that represents + /// contains the state data and the tuple of nonce and actor id that represents /// the lifespan of the transient storage data pub transient_data: Option, From 56d2458d02b07aab42cd08a222b686e271d889b2 Mon Sep 17 00:00:00 2001 From: Mikers Date: Mon, 2 Dec 2024 16:42:21 -0700 Subject: [PATCH 07/46] update comments on tests --- .../evm/src/interpreter/instructions/storage.rs | 4 +--- actors/evm/tests/basic.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/actors/evm/src/interpreter/instructions/storage.rs b/actors/evm/src/interpreter/instructions/storage.rs index 5ecefdc1e..fedfb5c83 100644 --- a/actors/evm/src/interpreter/instructions/storage.rs +++ b/actors/evm/src/interpreter/instructions/storage.rs @@ -107,8 +107,6 @@ mod tests { }; } - // TODO test transient storage lifecycle - #[test] fn test_tload() { // happy path @@ -127,7 +125,7 @@ mod tests { #[test] fn test_tload_oob() { - // oob access -- it is a zero + // oob access -- unitialized is zero evm_unit_test! { (m) { TLOAD; diff --git a/actors/evm/tests/basic.rs b/actors/evm/tests/basic.rs index d59518049..fa1fccc1a 100644 --- a/actors/evm/tests/basic.rs +++ b/actors/evm/tests/basic.rs @@ -229,3 +229,20 @@ fn mcopy_test(bytecode: Vec) { let result = util::invoke_contract(&rt, &solidity_params); assert_eq!(&*result, &*encoded_testdata); } + +#[test] +fn transient_storage() { + //TODO XXX + /* + 1. **Basic Functionality:** + - Verify `TLOAD` retrieves the correct value. + - Verify `TSTORE` writes data to the transient storage correctly. + - Verify `TLOAD` from an unitialized location returns the zero value. + + 2. **Lifecycle Validation:** + - Verify that transient storage is automatically cleared and becomes inaccessible after the transaction ends. + - Verify that transient storage is properly cleared at the end of each transaction and any out-of-lifecycle data does not interfere with subsequent transaction operations. + - Verify that nested contracts have independent transient storage spaces can read and write independently. + - Verify that memory remains accessible and stable after contract reentry. + */ +} From 312299fac99a7735f91c25568b640b85be953e85 Mon Sep 17 00:00:00 2001 From: Mikers Date: Tue, 3 Dec 2024 08:58:42 -1000 Subject: [PATCH 08/46] add tstorage test contract files --- actors/evm/tests/contracts/NestedContract.abi | 1 + actors/evm/tests/contracts/NestedContract.bin | 1 + .../tests/contracts/NestedContract.signatures | 3 + .../contracts/NestedContract_storage.json | 1 + .../evm/tests/contracts/ReentrantContract.abi | 1 + .../evm/tests/contracts/ReentrantContract.bin | 1 + .../contracts/ReentrantContract.signatures | 5 + .../contracts/ReentrantContract_storage.json | 1 + .../tests/contracts/TransientStorageTest.abi | 1 + .../tests/contracts/TransientStorageTest.bin | 1 + .../tests/contracts/TransientStorageTest.hex | 1 + .../contracts/TransientStorageTest.signatures | 9 + .../tests/contracts/TransientStorageTest.sol | 157 ++++++++++++++++++ .../TransientStorageTest_storage.json | 1 + 14 files changed, 184 insertions(+) create mode 100644 actors/evm/tests/contracts/NestedContract.abi create mode 100644 actors/evm/tests/contracts/NestedContract.bin create mode 100644 actors/evm/tests/contracts/NestedContract.signatures create mode 100644 actors/evm/tests/contracts/NestedContract_storage.json create mode 100644 actors/evm/tests/contracts/ReentrantContract.abi create mode 100644 actors/evm/tests/contracts/ReentrantContract.bin create mode 100644 actors/evm/tests/contracts/ReentrantContract.signatures create mode 100644 actors/evm/tests/contracts/ReentrantContract_storage.json create mode 100644 actors/evm/tests/contracts/TransientStorageTest.abi create mode 100644 actors/evm/tests/contracts/TransientStorageTest.bin create mode 100644 actors/evm/tests/contracts/TransientStorageTest.hex create mode 100644 actors/evm/tests/contracts/TransientStorageTest.signatures create mode 100644 actors/evm/tests/contracts/TransientStorageTest.sol create mode 100644 actors/evm/tests/contracts/TransientStorageTest_storage.json diff --git a/actors/evm/tests/contracts/NestedContract.abi b/actors/evm/tests/contracts/NestedContract.abi new file mode 100644 index 000000000..7fc3a8a06 --- /dev/null +++ b/actors/evm/tests/contracts/NestedContract.abi @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"readTransientData","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"writeTransientData","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/actors/evm/tests/contracts/NestedContract.bin b/actors/evm/tests/contracts/NestedContract.bin new file mode 100644 index 000000000..86db45a26 --- /dev/null +++ b/actors/evm/tests/contracts/NestedContract.bin @@ -0,0 +1 @@ +6080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea2646970667358221220d79b2f20cfa6deba47093f370319ffaaebfdde191340829ef9aa39d035867cd564736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/NestedContract.signatures b/actors/evm/tests/contracts/NestedContract.signatures new file mode 100644 index 000000000..e263c6b39 --- /dev/null +++ b/actors/evm/tests/contracts/NestedContract.signatures @@ -0,0 +1,3 @@ +Function signatures: +02a5e064: readTransientData(uint256) +b279888b: writeTransientData(uint256,uint256) diff --git a/actors/evm/tests/contracts/NestedContract_storage.json b/actors/evm/tests/contracts/NestedContract_storage.json new file mode 100644 index 000000000..325d0043f --- /dev/null +++ b/actors/evm/tests/contracts/NestedContract_storage.json @@ -0,0 +1 @@ +{"storage":[]} \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.abi b/actors/evm/tests/contracts/ReentrantContract.abi new file mode 100644 index 000000000..6f552a64a --- /dev/null +++ b/actors/evm/tests/contracts/ReentrantContract.abi @@ -0,0 +1 @@ +[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"success","type":"bool"}],"name":"ReentrySuccess","type":"event"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"},{"internalType":"uint256","name":"expectedValue","type":"uint256"}],"name":"callReentry","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.bin b/actors/evm/tests/contracts/ReentrantContract.bin new file mode 100644 index 000000000..bc85bdbda --- /dev/null +++ b/actors/evm/tests/contracts/ReentrantContract.bin @@ -0,0 +1 @@ +6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea2646970667358221220078f0ae5fbc49d21178ec96c418740767565267325827d420bc7823b6a1bbeeb64736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.signatures b/actors/evm/tests/contracts/ReentrantContract.signatures new file mode 100644 index 000000000..87741e20c --- /dev/null +++ b/actors/evm/tests/contracts/ReentrantContract.signatures @@ -0,0 +1,5 @@ +Function signatures: +d52aa447: callReentry(uint256,uint256) + +Event signatures: +df046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a: ReentrySuccess(bool) diff --git a/actors/evm/tests/contracts/ReentrantContract_storage.json b/actors/evm/tests/contracts/ReentrantContract_storage.json new file mode 100644 index 000000000..325d0043f --- /dev/null +++ b/actors/evm/tests/contracts/ReentrantContract_storage.json @@ -0,0 +1 @@ +{"storage":[]} \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.abi b/actors/evm/tests/contracts/TransientStorageTest.abi new file mode 100644 index 000000000..83fa63f5b --- /dev/null +++ b/actors/evm/tests/contracts/TransientStorageTest.abi @@ -0,0 +1 @@ +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"TestResult","type":"event"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testNestedContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testReentry","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.bin b/actors/evm/tests/contracts/TransientStorageTest.bin new file mode 100644 index 000000000..1ac837d46 --- /dev/null +++ b/actors/evm/tests/contracts/TransientStorageTest.bin @@ -0,0 +1 @@ +608060405234801561000f575f5ffd5b5061001e61002360201b60201c565b610cc8565b61003161005d60201b60201c565b61003f61013c60201b60201c565b61004d61022060201b60201c565b61005b61040560201b60201c565b565b5f600190505f602a905080825d5f825c90508181146100b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100a8906105e2565b60405180910390fd5b5f600290505f815c90505f81146100fd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100f490610670565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f600160405161012d91906106f2565b60405180910390a15050505050565b5f600390505f6063905080825d5f825c9050818114610190576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101879061078e565b60405180910390fd5b5f6101a08461053760201b60201c565b9050806101e2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d99061081c565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516102129190610884565b60405180910390a150505050565b5f60405161022d90610548565b604051809103905ff080158015610246573d5f5f3e3d5ffd5b5090505f600490505f6058905080825d8273ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b8152600401610293929190610934565b5f604051808303815f87803b1580156102aa575f5ffd5b505af11580156102bc573d5f5f3e3d5ffd5b505050505f825c9050818114610307576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102fe906109cb565b60405180910390fd5b5f8473ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b815260040161034291906109e9565b602060405180830381865afa15801561035d573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103819190610a30565b9050607b81146103c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103bd90610aa5565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516103f69190610b33565b60405180910390a15050505050565b5f600590505f604d905080825d5f60405161041f90610555565b604051809103905ff080158015610438573d5f5f3e3d5ffd5b5090505f8173ffffffffffffffffffffffffffffffffffffffff1663d52aa44785856040518363ffffffff1660e01b8152600401610477929190610b6e565b6020604051808303815f875af1158015610493573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104b79190610bbf565b9050806104f9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104f090610c34565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516105299190610c9c565b60405180910390a150505050565b5f5f825c90505f8114915050919050565b6101b480611e8783390190565b61025a8061203b83390190565b5f82825260208201905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6105cc602883610562565b91506105d782610572565b604082019050919050565b5f6020820190508181035f8301526105f9816105c0565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f61065a602783610562565b915061066582610600565b604082019050919050565b5f6020820190508181035f8301526106878161064e565b9050919050565b5f8115159050919050565b6106a28161068e565b82525050565b7f42617369632066756e6374696f6e616c697479207061737365640000000000005f82015250565b5f6106dc601a83610562565b91506106e7826106a8565b602082019050919050565b5f6040820190506107055f830184610699565b8181036020830152610716816106d0565b905092915050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610778603683610562565b91506107838261071e565b604082019050919050565b5f6020820190508181035f8301526107a58161076c565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f610806603383610562565b9150610811826107ac565b604082019050919050565b5f6020820190508181035f830152610833816107fa565b9050919050565b7f4c6966656379636c652076616c69646174696f6e2070617373656400000000005f82015250565b5f61086e601b83610562565b91506108798261083a565b602082019050919050565b5f6040820190506108975f830184610699565b81810360208301526108a881610862565b905092915050565b5f819050919050565b5f819050919050565b5f819050919050565b5f6108e56108e06108db846108b0565b6108c2565b6108b9565b9050919050565b6108f5816108cb565b82525050565b5f819050919050565b5f61091e610919610914846108fb565b6108c2565b6108b9565b9050919050565b61092e81610904565b82525050565b5f6040820190506109475f8301856108ec565b6109546020830184610925565b9392505050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f6109b5603783610562565b91506109c08261095b565b604082019050919050565b5f6020820190508181035f8301526109e2816109a9565b9050919050565b5f6020820190506109fc5f8301846108ec565b92915050565b5f5ffd5b610a0f816108b9565b8114610a19575f5ffd5b50565b5f81519050610a2a81610a06565b92915050565b5f60208284031215610a4557610a44610a02565b5b5f610a5284828501610a1c565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f610a8f601e83610562565b9150610a9a82610a5b565b602082019050919050565b5f6020820190508181035f830152610abc81610a83565b9050919050565b7f4e657374656420636f6e7472616374732076616c69646174696f6e20706173735f8201527f6564000000000000000000000000000000000000000000000000000000000000602082015250565b5f610b1d602283610562565b9150610b2882610ac3565b604082019050919050565b5f604082019050610b465f830184610699565b8181036020830152610b5781610b11565b905092915050565b610b68816108b9565b82525050565b5f604082019050610b815f830185610b5f565b610b8e6020830184610b5f565b9392505050565b610b9e8161068e565b8114610ba8575f5ffd5b50565b5f81519050610bb981610b95565b92915050565b5f60208284031215610bd457610bd3610a02565b5b5f610be184828501610bab565b91505092915050565b7f5265656e747279206661696c65640000000000000000000000000000000000005f82015250565b5f610c1e600e83610562565b9150610c2982610bea565b602082019050919050565b5f6020820190508181035f830152610c4b81610c12565b9050919050565b7f5265656e7472792076616c69646174696f6e20706173736564000000000000005f82015250565b5f610c86601983610562565b9150610c9182610c52565b602082019050919050565b5f604082019050610caf5f830184610699565b8181036020830152610cc081610c7a565b905092915050565b6111b280610cd55f395ff3fe608060405234801561000f575f5ffd5b5060043610610055575f3560e01c806317d68eb11461005957806318e1813f146100635780635fcbdd3a14610093578063cf83c71c1461009d578063e90bf998146100a7575b5f5ffd5b6100616100b1565b005b61007d600480360381019061007891906105e7565b6101e3565b60405161008a919061062c565b60405180910390f35b61009b6101f4565b005b6100a56103d9565b005b6100af6104b8565b005b5f600590505f604d905080825d5f6040516100cb90610596565b604051809103905ff0801580156100e4573d5f5f3e3d5ffd5b5090505f8173ffffffffffffffffffffffffffffffffffffffff1663d52aa44785856040518363ffffffff1660e01b8152600401610123929190610654565b6020604051808303815f875af115801561013f573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061016391906106a5565b9050806101a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161019c9061072a565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516101d59190610792565b60405180910390a150505050565b5f5f825c90505f8114915050919050565b5f604051610201906105a3565b604051809103905ff08015801561021a573d5f5f3e3d5ffd5b5090505f600490505f6058905080825d8273ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b8152600401610267929190610839565b5f604051808303815f87803b15801561027e575f5ffd5b505af1158015610290573d5f5f3e3d5ffd5b505050505f825c90508181146102db576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102d2906108d0565b60405180910390fd5b5f8473ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b815260040161031691906108ee565b602060405180830381865afa158015610331573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610355919061091b565b9050607b811461039a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161039190610990565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516103ca9190610a1e565b60405180910390a15050505050565b5f600190505f602a905080825d5f825c905081811461042d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161042490610aba565b60405180910390fd5b5f600290505f815c90505f8114610479576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047090610b48565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516104a99190610bb0565b60405180910390a15050505050565b5f600390505f6063905080825d5f825c905081811461050c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161050390610c4c565b60405180910390fd5b5f610516846101e3565b905080610558576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161054f90610cda565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516105889190610d42565b60405180910390a150505050565b61025a80610d6f83390190565b6101b480610fc983390190565b5f5ffd5b5f819050919050565b6105c6816105b4565b81146105d0575f5ffd5b50565b5f813590506105e1816105bd565b92915050565b5f602082840312156105fc576105fb6105b0565b5b5f610609848285016105d3565b91505092915050565b5f8115159050919050565b61062681610612565b82525050565b5f60208201905061063f5f83018461061d565b92915050565b61064e816105b4565b82525050565b5f6040820190506106675f830185610645565b6106746020830184610645565b9392505050565b61068481610612565b811461068e575f5ffd5b50565b5f8151905061069f8161067b565b92915050565b5f602082840312156106ba576106b96105b0565b5b5f6106c784828501610691565b91505092915050565b5f82825260208201905092915050565b7f5265656e747279206661696c65640000000000000000000000000000000000005f82015250565b5f610714600e836106d0565b915061071f826106e0565b602082019050919050565b5f6020820190508181035f83015261074181610708565b9050919050565b7f5265656e7472792076616c69646174696f6e20706173736564000000000000005f82015250565b5f61077c6019836106d0565b915061078782610748565b602082019050919050565b5f6040820190506107a55f83018461061d565b81810360208301526107b681610770565b905092915050565b5f819050919050565b5f819050919050565b5f6107ea6107e56107e0846107be565b6107c7565b6105b4565b9050919050565b6107fa816107d0565b82525050565b5f819050919050565b5f61082361081e61081984610800565b6107c7565b6105b4565b9050919050565b61083381610809565b82525050565b5f60408201905061084c5f8301856107f1565b610859602083018461082a565b9392505050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f6108ba6037836106d0565b91506108c582610860565b604082019050919050565b5f6020820190508181035f8301526108e7816108ae565b9050919050565b5f6020820190506109015f8301846107f1565b92915050565b5f81519050610915816105bd565b92915050565b5f602082840312156109305761092f6105b0565b5b5f61093d84828501610907565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f61097a601e836106d0565b915061098582610946565b602082019050919050565b5f6020820190508181035f8301526109a78161096e565b9050919050565b7f4e657374656420636f6e7472616374732076616c69646174696f6e20706173735f8201527f6564000000000000000000000000000000000000000000000000000000000000602082015250565b5f610a086022836106d0565b9150610a13826109ae565b604082019050919050565b5f604082019050610a315f83018461061d565b8181036020830152610a42816109fc565b905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f610aa46028836106d0565b9150610aaf82610a4a565b604082019050919050565b5f6020820190508181035f830152610ad181610a98565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610b326027836106d0565b9150610b3d82610ad8565b604082019050919050565b5f6020820190508181035f830152610b5f81610b26565b9050919050565b7f42617369632066756e6374696f6e616c697479207061737365640000000000005f82015250565b5f610b9a601a836106d0565b9150610ba582610b66565b602082019050919050565b5f604082019050610bc35f83018461061d565b8181036020830152610bd481610b8e565b905092915050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610c366036836106d0565b9150610c4182610bdc565b604082019050919050565b5f6020820190508181035f830152610c6381610c2a565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f610cc46033836106d0565b9150610ccf82610c6a565b604082019050919050565b5f6020820190508181035f830152610cf181610cb8565b9050919050565b7f4c6966656379636c652076616c69646174696f6e2070617373656400000000005f82015250565b5f610d2c601b836106d0565b9150610d3782610cf8565b602082019050919050565b5f604082019050610d555f83018461061d565b8181036020830152610d6681610d20565b90509291505056fe6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea2646970667358221220078f0ae5fbc49d21178ec96c418740767565267325827d420bc7823b6a1bbeeb64736f6c634300081c00336080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea2646970667358221220d79b2f20cfa6deba47093f370319ffaaebfdde191340829ef9aa39d035867cd564736f6c634300081c0033a2646970667358221220465a9d6dd1d0a596a9464f269106920068481b311769c7b126fe879fda67dbd664736f6c634300081c00336080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea2646970667358221220d79b2f20cfa6deba47093f370319ffaaebfdde191340829ef9aa39d035867cd564736f6c634300081c00336080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea2646970667358221220078f0ae5fbc49d21178ec96c418740767565267325827d420bc7823b6a1bbeeb64736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.hex b/actors/evm/tests/contracts/TransientStorageTest.hex new file mode 100644 index 000000000..86db45a26 --- /dev/null +++ b/actors/evm/tests/contracts/TransientStorageTest.hex @@ -0,0 +1 @@ +6080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea2646970667358221220d79b2f20cfa6deba47093f370319ffaaebfdde191340829ef9aa39d035867cd564736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.signatures b/actors/evm/tests/contracts/TransientStorageTest.signatures new file mode 100644 index 000000000..5dce6119b --- /dev/null +++ b/actors/evm/tests/contracts/TransientStorageTest.signatures @@ -0,0 +1,9 @@ +Function signatures: +18e1813f: isStorageCleared(uint256) +cf83c71c: testBasicFunctionality() +e90bf998: testLifecycleValidation() +5fcbdd3a: testNestedContracts() +17d68eb1: testReentry() + +Event signatures: +08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f: TestResult(bool,string) diff --git a/actors/evm/tests/contracts/TransientStorageTest.sol b/actors/evm/tests/contracts/TransientStorageTest.sol new file mode 100644 index 000000000..5a7dcd522 --- /dev/null +++ b/actors/evm/tests/contracts/TransientStorageTest.sol @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +contract TransientStorageTest { + event TestResult(bool success, string message); + + constructor() { + // Automatically run tests on deployment + _runTests(); + } + + function _runTests() internal { + testBasicFunctionality(); + testLifecycleValidation(); + testNestedContracts(); + testReentry(); + } + + // Test 1: Basic Functionality + function testBasicFunctionality() public { + uint256 slot = 1; + uint256 value = 42; + + // Store value using TSTORE + assembly { + tstore(slot, value) + } + + // Retrieve value using TLOAD + uint256 retrievedValue; + assembly { + retrievedValue := tload(slot) + } + + require(retrievedValue == value, "TLOAD did not retrieve the correct value"); + + // Verify TLOAD from uninitialized location + uint256 uninitializedSlot = 2; + uint256 uninitializedValue; + assembly { + uninitializedValue := tload(uninitializedSlot) + } + + require(uninitializedValue == 0, "Uninitialized TLOAD did not return zero"); + + emit TestResult(true, "Basic functionality passed"); + } + + // Test 2.1: Verify transient storage clears after transaction + function testLifecycleValidation() public { + uint256 slot = 3; + uint256 value = 99; + + // Store value using TSTORE + assembly { + tstore(slot, value) + } + + // Verify it exists within the same transaction + uint256 retrievedValue; + assembly { + retrievedValue := tload(slot) + } + require(retrievedValue == value, "TLOAD did not retrieve stored value within transaction"); + + // Test clearing by re-calling a new transaction + bool cleared = isStorageCleared(slot); + require(cleared, "Transient storage was not cleared after transaction"); + + emit TestResult(true, "Lifecycle validation passed"); + } + + function isStorageCleared(uint256 slot) public view returns (bool) { + uint256 retrievedValue; + assembly { + retrievedValue := tload(slot) + } + return retrievedValue == 0; // True if cleared + } + + // Test 2.2: Verify nested contract independence + function testNestedContracts() public { + NestedContract nested = new NestedContract(); + uint256 slot = 4; + uint256 value = 88; + + // Store in this contract's transient storage + assembly { + tstore(slot, value) + } + + // Call nested contract to write its own transient storage + nested.writeTransientData(4, 123); + + // Verify this contract's data is unchanged + uint256 retrievedValue; + assembly { + retrievedValue := tload(slot) + } + require(retrievedValue == value, "Nested contract interfered with this contract's storage"); + + // Verify nested contract's data independently + uint256 nestedValue = nested.readTransientData(4); + require(nestedValue == 123, "Nested contract data incorrect"); + + emit TestResult(true, "Nested contracts validation passed"); + } + + // Test 2.3: Verify transient storage during reentry + function testReentry() public { + uint256 slot = 5; + uint256 value = 77; + + // Store value in transient storage + assembly { + tstore(slot, value) + } + + // Call reentrant contract + ReentrantContract reentrant = new ReentrantContract(); + bool success = reentrant.callReentry(slot, value); + + require(success, "Reentry failed"); + emit TestResult(true, "Reentry validation passed"); + } +} + +contract NestedContract { + function writeTransientData(uint256 slot, uint256 value) external { + assembly { + tstore(slot, value) + } + } + + function readTransientData(uint256 slot) external view returns (uint256) { + uint256 value; + assembly { + value := tload(slot) + } + return value; + } +} + +contract ReentrantContract { + event ReentrySuccess(bool success); + + function callReentry(uint256 slot, uint256 expectedValue) external returns (bool) { + uint256 storedValue; + assembly { + storedValue := tload(slot) + } + require(storedValue == expectedValue, "Reentrant value mismatch"); + + emit ReentrySuccess(true); + return true; + } +} diff --git a/actors/evm/tests/contracts/TransientStorageTest_storage.json b/actors/evm/tests/contracts/TransientStorageTest_storage.json new file mode 100644 index 000000000..325d0043f --- /dev/null +++ b/actors/evm/tests/contracts/TransientStorageTest_storage.json @@ -0,0 +1 @@ +{"storage":[]} \ No newline at end of file From 757131f32432ef868d34401b285a50ce5e102a14 Mon Sep 17 00:00:00 2001 From: Mikers Date: Tue, 3 Dec 2024 11:34:13 -1000 Subject: [PATCH 09/46] use a non optimized delete method to clear transient storage. TODO update kamt lirbary to support a clear method --- actors/evm/src/interpreter/system.rs | 36 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 3663a9ef5..6a4a0968b 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -490,10 +490,8 @@ impl<'r, RT: Runtime> System<'r, RT> { // Update lifespan self.transient_data_lifespan = new_lifespan; - // Reinitialize the transient_slots with a fresh KAMT - //let transient_store = self.rt.store().clone(); - //self.transient_slots = StateKamt::new_with_config(transient_store, KAMT_CONFIG.clone()); - // TODO XXX reinitialize does not currently work due to blockstore reference issues + // Delete all keys from transient storage + self.clear_transient_slots()?; // Mark state as dirty self.saved_state_root = None; @@ -501,6 +499,36 @@ impl<'r, RT: Runtime> System<'r, RT> { Ok(()) } + /// Clears all entries in `transient_slots`. + /// This is not ideal because it is iterating over each key + /// TODO create a PR for the KAMT library to support a "clear" method + /// and upgrade to the new KAMT library version once its updated + fn clear_transient_slots(&mut self) -> Result<(), ActorError> { + let mut keys_to_delete = Vec::new(); + + // Use `for_each` to collect all keys + self.transient_slots + .for_each(|key, _| { + keys_to_delete.push(key.clone()); + Ok(()) + }) + .map_err( + |err| actor_error!(illegal_state; "iterating over transient_slots failed: {}", err), + )?; + + for key in keys_to_delete { + self.transient_slots.delete(&key).map_err(|err| { + actor_error!( + illegal_state; + "deleting key {key:?} from transient_slots failed: {}", + err + ) + })?; + } + + Ok(()) + } + /// Resolve the address to the ethereum equivalent, if possible. /// /// - Eth f4 maps directly to an Eth address. From eb894ae56ba9ea06d16644fd7b3504ca95eafb71 Mon Sep 17 00:00:00 2001 From: Mikers Date: Tue, 3 Dec 2024 11:34:41 -1000 Subject: [PATCH 10/46] failing tests that need to be investigated --- actors/evm/tests/basic.rs | 36 +++++++++-------- actors/evm/tests/contracts/NestedContract.bin | 2 +- actors/evm/tests/contracts/NestedContract.hex | 1 + actors/evm/tests/contracts/NestedContract.sol | 18 +++++++++ .../evm/tests/contracts/ReentrantContract.bin | 2 +- .../evm/tests/contracts/ReentrantContract.hex | 1 + .../evm/tests/contracts/ReentrantContract.sol | 17 ++++++++ .../tests/contracts/TransientStorageTest.abi | 2 +- .../tests/contracts/TransientStorageTest.bin | 2 +- .../tests/contracts/TransientStorageTest.hex | 2 +- .../contracts/TransientStorageTest.signatures | 1 + .../tests/contracts/TransientStorageTest.sol | 40 ++++--------------- 12 files changed, 71 insertions(+), 53 deletions(-) create mode 100644 actors/evm/tests/contracts/NestedContract.hex create mode 100644 actors/evm/tests/contracts/NestedContract.sol create mode 100644 actors/evm/tests/contracts/ReentrantContract.hex create mode 100644 actors/evm/tests/contracts/ReentrantContract.sol diff --git a/actors/evm/tests/basic.rs b/actors/evm/tests/basic.rs index fa1fccc1a..2461dbd54 100644 --- a/actors/evm/tests/basic.rs +++ b/actors/evm/tests/basic.rs @@ -203,6 +203,26 @@ fn test_push_last_byte() { util::invoke_contract(&rt, &[]); } +#[test] +fn transient_storage() { + let bytecode = hex::decode(include_str!("contracts/TransientStorageTest.bin")).unwrap(); + transient_storage_test(bytecode); +} + +fn transient_storage_test(bytecode: Vec) { + let contract = Address::new_id(100); + + let rt = util::init_construct_and_verify(bytecode, |rt| { + rt.actor_code_cids.borrow_mut().insert(contract, *EVM_ACTOR_CODE_ID); + rt.set_origin(contract); + }); + + let mut solidity_params = vec![]; + + solidity_params.extend_from_slice(&hex::decode("23d74628").unwrap()); // function selector, "runTests()" + let _result = util::invoke_contract(&rt, &solidity_params); +} + #[test] fn mcopy() { let bytecode = hex::decode(include_str!("contracts/MCOPYTest.hex")).unwrap(); @@ -230,19 +250,3 @@ fn mcopy_test(bytecode: Vec) { assert_eq!(&*result, &*encoded_testdata); } -#[test] -fn transient_storage() { - //TODO XXX - /* - 1. **Basic Functionality:** - - Verify `TLOAD` retrieves the correct value. - - Verify `TSTORE` writes data to the transient storage correctly. - - Verify `TLOAD` from an unitialized location returns the zero value. - - 2. **Lifecycle Validation:** - - Verify that transient storage is automatically cleared and becomes inaccessible after the transaction ends. - - Verify that transient storage is properly cleared at the end of each transaction and any out-of-lifecycle data does not interfere with subsequent transaction operations. - - Verify that nested contracts have independent transient storage spaces can read and write independently. - - Verify that memory remains accessible and stable after contract reentry. - */ -} diff --git a/actors/evm/tests/contracts/NestedContract.bin b/actors/evm/tests/contracts/NestedContract.bin index 86db45a26..ef302979c 100644 --- a/actors/evm/tests/contracts/NestedContract.bin +++ b/actors/evm/tests/contracts/NestedContract.bin @@ -1 +1 @@ -6080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea2646970667358221220d79b2f20cfa6deba47093f370319ffaaebfdde191340829ef9aa39d035867cd564736f6c634300081c0033 \ No newline at end of file +6080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea264697066735822122022a3efe83f7aff51061bf54c745bd6c6faa7241f45c690093b50304bf5ae7f8564736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/NestedContract.hex b/actors/evm/tests/contracts/NestedContract.hex new file mode 100644 index 000000000..ef302979c --- /dev/null +++ b/actors/evm/tests/contracts/NestedContract.hex @@ -0,0 +1 @@ +6080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea264697066735822122022a3efe83f7aff51061bf54c745bd6c6faa7241f45c690093b50304bf5ae7f8564736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/NestedContract.sol b/actors/evm/tests/contracts/NestedContract.sol new file mode 100644 index 000000000..3ab066d4d --- /dev/null +++ b/actors/evm/tests/contracts/NestedContract.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +contract NestedContract { + function writeTransientData(uint256 slot, uint256 value) external { + assembly { + tstore(slot, value) + } + } + + function readTransientData(uint256 slot) external view returns (uint256) { + uint256 value; + assembly { + value := tload(slot) + } + return value; + } +} diff --git a/actors/evm/tests/contracts/ReentrantContract.bin b/actors/evm/tests/contracts/ReentrantContract.bin index bc85bdbda..f36b7e1a8 100644 --- a/actors/evm/tests/contracts/ReentrantContract.bin +++ b/actors/evm/tests/contracts/ReentrantContract.bin @@ -1 +1 @@ -6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea2646970667358221220078f0ae5fbc49d21178ec96c418740767565267325827d420bc7823b6a1bbeeb64736f6c634300081c0033 \ No newline at end of file +6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea26469706673582212201f962b4b81dfea667fc231f5535eb3b661a369a8f5de4c2a277869f134de9dfa64736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.hex b/actors/evm/tests/contracts/ReentrantContract.hex new file mode 100644 index 000000000..f36b7e1a8 --- /dev/null +++ b/actors/evm/tests/contracts/ReentrantContract.hex @@ -0,0 +1 @@ +6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea26469706673582212201f962b4b81dfea667fc231f5535eb3b661a369a8f5de4c2a277869f134de9dfa64736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.sol b/actors/evm/tests/contracts/ReentrantContract.sol new file mode 100644 index 000000000..3fa0c4a5c --- /dev/null +++ b/actors/evm/tests/contracts/ReentrantContract.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +contract ReentrantContract { + event ReentrySuccess(bool success); + + function callReentry(uint256 slot, uint256 expectedValue) external returns (bool) { + uint256 storedValue; + assembly { + storedValue := tload(slot) + } + require(storedValue == expectedValue, "Reentrant value mismatch"); + + emit ReentrySuccess(true); + return true; + } +} diff --git a/actors/evm/tests/contracts/TransientStorageTest.abi b/actors/evm/tests/contracts/TransientStorageTest.abi index 83fa63f5b..d93e9fb57 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.abi +++ b/actors/evm/tests/contracts/TransientStorageTest.abi @@ -1 +1 @@ -[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"TestResult","type":"event"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testNestedContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testReentry","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"TestResult","type":"event"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"runTests","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testNestedContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testReentry","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.bin b/actors/evm/tests/contracts/TransientStorageTest.bin index 1ac837d46..94a699d95 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.bin +++ b/actors/evm/tests/contracts/TransientStorageTest.bin @@ -1 +1 @@ -608060405234801561000f575f5ffd5b5061001e61002360201b60201c565b610cc8565b61003161005d60201b60201c565b61003f61013c60201b60201c565b61004d61022060201b60201c565b61005b61040560201b60201c565b565b5f600190505f602a905080825d5f825c90508181146100b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100a8906105e2565b60405180910390fd5b5f600290505f815c90505f81146100fd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100f490610670565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f600160405161012d91906106f2565b60405180910390a15050505050565b5f600390505f6063905080825d5f825c9050818114610190576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101879061078e565b60405180910390fd5b5f6101a08461053760201b60201c565b9050806101e2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101d99061081c565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516102129190610884565b60405180910390a150505050565b5f60405161022d90610548565b604051809103905ff080158015610246573d5f5f3e3d5ffd5b5090505f600490505f6058905080825d8273ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b8152600401610293929190610934565b5f604051808303815f87803b1580156102aa575f5ffd5b505af11580156102bc573d5f5f3e3d5ffd5b505050505f825c9050818114610307576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102fe906109cb565b60405180910390fd5b5f8473ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b815260040161034291906109e9565b602060405180830381865afa15801561035d573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103819190610a30565b9050607b81146103c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103bd90610aa5565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516103f69190610b33565b60405180910390a15050505050565b5f600590505f604d905080825d5f60405161041f90610555565b604051809103905ff080158015610438573d5f5f3e3d5ffd5b5090505f8173ffffffffffffffffffffffffffffffffffffffff1663d52aa44785856040518363ffffffff1660e01b8152600401610477929190610b6e565b6020604051808303815f875af1158015610493573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104b79190610bbf565b9050806104f9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104f090610c34565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516105299190610c9c565b60405180910390a150505050565b5f5f825c90505f8114915050919050565b6101b480611e8783390190565b61025a8061203b83390190565b5f82825260208201905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6105cc602883610562565b91506105d782610572565b604082019050919050565b5f6020820190508181035f8301526105f9816105c0565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f61065a602783610562565b915061066582610600565b604082019050919050565b5f6020820190508181035f8301526106878161064e565b9050919050565b5f8115159050919050565b6106a28161068e565b82525050565b7f42617369632066756e6374696f6e616c697479207061737365640000000000005f82015250565b5f6106dc601a83610562565b91506106e7826106a8565b602082019050919050565b5f6040820190506107055f830184610699565b8181036020830152610716816106d0565b905092915050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610778603683610562565b91506107838261071e565b604082019050919050565b5f6020820190508181035f8301526107a58161076c565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f610806603383610562565b9150610811826107ac565b604082019050919050565b5f6020820190508181035f830152610833816107fa565b9050919050565b7f4c6966656379636c652076616c69646174696f6e2070617373656400000000005f82015250565b5f61086e601b83610562565b91506108798261083a565b602082019050919050565b5f6040820190506108975f830184610699565b81810360208301526108a881610862565b905092915050565b5f819050919050565b5f819050919050565b5f819050919050565b5f6108e56108e06108db846108b0565b6108c2565b6108b9565b9050919050565b6108f5816108cb565b82525050565b5f819050919050565b5f61091e610919610914846108fb565b6108c2565b6108b9565b9050919050565b61092e81610904565b82525050565b5f6040820190506109475f8301856108ec565b6109546020830184610925565b9392505050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f6109b5603783610562565b91506109c08261095b565b604082019050919050565b5f6020820190508181035f8301526109e2816109a9565b9050919050565b5f6020820190506109fc5f8301846108ec565b92915050565b5f5ffd5b610a0f816108b9565b8114610a19575f5ffd5b50565b5f81519050610a2a81610a06565b92915050565b5f60208284031215610a4557610a44610a02565b5b5f610a5284828501610a1c565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f610a8f601e83610562565b9150610a9a82610a5b565b602082019050919050565b5f6020820190508181035f830152610abc81610a83565b9050919050565b7f4e657374656420636f6e7472616374732076616c69646174696f6e20706173735f8201527f6564000000000000000000000000000000000000000000000000000000000000602082015250565b5f610b1d602283610562565b9150610b2882610ac3565b604082019050919050565b5f604082019050610b465f830184610699565b8181036020830152610b5781610b11565b905092915050565b610b68816108b9565b82525050565b5f604082019050610b815f830185610b5f565b610b8e6020830184610b5f565b9392505050565b610b9e8161068e565b8114610ba8575f5ffd5b50565b5f81519050610bb981610b95565b92915050565b5f60208284031215610bd457610bd3610a02565b5b5f610be184828501610bab565b91505092915050565b7f5265656e747279206661696c65640000000000000000000000000000000000005f82015250565b5f610c1e600e83610562565b9150610c2982610bea565b602082019050919050565b5f6020820190508181035f830152610c4b81610c12565b9050919050565b7f5265656e7472792076616c69646174696f6e20706173736564000000000000005f82015250565b5f610c86601983610562565b9150610c9182610c52565b602082019050919050565b5f604082019050610caf5f830184610699565b8181036020830152610cc081610c7a565b905092915050565b6111b280610cd55f395ff3fe608060405234801561000f575f5ffd5b5060043610610055575f3560e01c806317d68eb11461005957806318e1813f146100635780635fcbdd3a14610093578063cf83c71c1461009d578063e90bf998146100a7575b5f5ffd5b6100616100b1565b005b61007d600480360381019061007891906105e7565b6101e3565b60405161008a919061062c565b60405180910390f35b61009b6101f4565b005b6100a56103d9565b005b6100af6104b8565b005b5f600590505f604d905080825d5f6040516100cb90610596565b604051809103905ff0801580156100e4573d5f5f3e3d5ffd5b5090505f8173ffffffffffffffffffffffffffffffffffffffff1663d52aa44785856040518363ffffffff1660e01b8152600401610123929190610654565b6020604051808303815f875af115801561013f573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061016391906106a5565b9050806101a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161019c9061072a565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516101d59190610792565b60405180910390a150505050565b5f5f825c90505f8114915050919050565b5f604051610201906105a3565b604051809103905ff08015801561021a573d5f5f3e3d5ffd5b5090505f600490505f6058905080825d8273ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b8152600401610267929190610839565b5f604051808303815f87803b15801561027e575f5ffd5b505af1158015610290573d5f5f3e3d5ffd5b505050505f825c90508181146102db576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102d2906108d0565b60405180910390fd5b5f8473ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b815260040161031691906108ee565b602060405180830381865afa158015610331573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610355919061091b565b9050607b811461039a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161039190610990565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516103ca9190610a1e565b60405180910390a15050505050565b5f600190505f602a905080825d5f825c905081811461042d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161042490610aba565b60405180910390fd5b5f600290505f815c90505f8114610479576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047090610b48565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516104a99190610bb0565b60405180910390a15050505050565b5f600390505f6063905080825d5f825c905081811461050c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161050390610c4c565b60405180910390fd5b5f610516846101e3565b905080610558576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161054f90610cda565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516105889190610d42565b60405180910390a150505050565b61025a80610d6f83390190565b6101b480610fc983390190565b5f5ffd5b5f819050919050565b6105c6816105b4565b81146105d0575f5ffd5b50565b5f813590506105e1816105bd565b92915050565b5f602082840312156105fc576105fb6105b0565b5b5f610609848285016105d3565b91505092915050565b5f8115159050919050565b61062681610612565b82525050565b5f60208201905061063f5f83018461061d565b92915050565b61064e816105b4565b82525050565b5f6040820190506106675f830185610645565b6106746020830184610645565b9392505050565b61068481610612565b811461068e575f5ffd5b50565b5f8151905061069f8161067b565b92915050565b5f602082840312156106ba576106b96105b0565b5b5f6106c784828501610691565b91505092915050565b5f82825260208201905092915050565b7f5265656e747279206661696c65640000000000000000000000000000000000005f82015250565b5f610714600e836106d0565b915061071f826106e0565b602082019050919050565b5f6020820190508181035f83015261074181610708565b9050919050565b7f5265656e7472792076616c69646174696f6e20706173736564000000000000005f82015250565b5f61077c6019836106d0565b915061078782610748565b602082019050919050565b5f6040820190506107a55f83018461061d565b81810360208301526107b681610770565b905092915050565b5f819050919050565b5f819050919050565b5f6107ea6107e56107e0846107be565b6107c7565b6105b4565b9050919050565b6107fa816107d0565b82525050565b5f819050919050565b5f61082361081e61081984610800565b6107c7565b6105b4565b9050919050565b61083381610809565b82525050565b5f60408201905061084c5f8301856107f1565b610859602083018461082a565b9392505050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f6108ba6037836106d0565b91506108c582610860565b604082019050919050565b5f6020820190508181035f8301526108e7816108ae565b9050919050565b5f6020820190506109015f8301846107f1565b92915050565b5f81519050610915816105bd565b92915050565b5f602082840312156109305761092f6105b0565b5b5f61093d84828501610907565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f61097a601e836106d0565b915061098582610946565b602082019050919050565b5f6020820190508181035f8301526109a78161096e565b9050919050565b7f4e657374656420636f6e7472616374732076616c69646174696f6e20706173735f8201527f6564000000000000000000000000000000000000000000000000000000000000602082015250565b5f610a086022836106d0565b9150610a13826109ae565b604082019050919050565b5f604082019050610a315f83018461061d565b8181036020830152610a42816109fc565b905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f610aa46028836106d0565b9150610aaf82610a4a565b604082019050919050565b5f6020820190508181035f830152610ad181610a98565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610b326027836106d0565b9150610b3d82610ad8565b604082019050919050565b5f6020820190508181035f830152610b5f81610b26565b9050919050565b7f42617369632066756e6374696f6e616c697479207061737365640000000000005f82015250565b5f610b9a601a836106d0565b9150610ba582610b66565b602082019050919050565b5f604082019050610bc35f83018461061d565b8181036020830152610bd481610b8e565b905092915050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610c366036836106d0565b9150610c4182610bdc565b604082019050919050565b5f6020820190508181035f830152610c6381610c2a565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f610cc46033836106d0565b9150610ccf82610c6a565b604082019050919050565b5f6020820190508181035f830152610cf181610cb8565b9050919050565b7f4c6966656379636c652076616c69646174696f6e2070617373656400000000005f82015250565b5f610d2c601b836106d0565b9150610d3782610cf8565b602082019050919050565b5f604082019050610d555f83018461061d565b8181036020830152610d6681610d20565b90509291505056fe6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea2646970667358221220078f0ae5fbc49d21178ec96c418740767565267325827d420bc7823b6a1bbeeb64736f6c634300081c00336080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea2646970667358221220d79b2f20cfa6deba47093f370319ffaaebfdde191340829ef9aa39d035867cd564736f6c634300081c0033a2646970667358221220465a9d6dd1d0a596a9464f269106920068481b311769c7b126fe879fda67dbd664736f6c634300081c00336080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea2646970667358221220d79b2f20cfa6deba47093f370319ffaaebfdde191340829ef9aa39d035867cd564736f6c634300081c00336080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea2646970667358221220078f0ae5fbc49d21178ec96c418740767565267325827d420bc7823b6a1bbeeb64736f6c634300081c0033 \ No newline at end of file +6080604052348015600e575f5ffd5b506112098061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610060575f3560e01c806317d68eb11461006457806318e1813f1461006e57806323d746281461009e5780635fcbdd3a146100bc578063cf83c71c146100c6578063e90bf998146100d0575b5f5ffd5b61006c6100da565b005b6100886004803603810190610083919061063e565b61020c565b6040516100959190610683565b60405180910390f35b6100a661021d565b6040516100b39190610683565b60405180910390f35b6100c4610229565b005b6100ce61040e565b005b6100d86104ed565b005b5f600590505f604d905080825d5f6040516100f4906105ed565b604051809103905ff08015801561010d573d5f5f3e3d5ffd5b5090505f8173ffffffffffffffffffffffffffffffffffffffff1663d52aa44785856040518363ffffffff1660e01b815260040161014c9291906106ab565b6020604051808303815f875af1158015610168573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061018c91906106fc565b9050806101ce576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101c590610781565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516101fe91906107e9565b60405180910390a150505050565b5f5f825c90505f8114915050919050565b5f6102266105cb565b90565b5f604051610236906105fa565b604051809103905ff08015801561024f573d5f5f3e3d5ffd5b5090505f600490505f6058905080825d8273ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b815260040161029c929190610890565b5f604051808303815f87803b1580156102b3575f5ffd5b505af11580156102c5573d5f5f3e3d5ffd5b505050505f825c9050818114610310576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161030790610927565b60405180910390fd5b5f8473ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b815260040161034b9190610945565b602060405180830381865afa158015610366573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061038a9190610972565b9050607b81146103cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103c6906109e7565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516103ff9190610a75565b60405180910390a15050505050565b5f600190505f602a905080825d5f825c9050818114610462576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161045990610b11565b60405180910390fd5b5f600290505f815c90505f81146104ae576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104a590610b9f565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516104de9190610c07565b60405180910390a15050505050565b5f600390505f6063905080825d5f825c9050818114610541576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161053890610ca3565b60405180910390fd5b5f61054b8461020c565b90508061058d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161058490610d31565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516105bd9190610d99565b60405180910390a150505050565b6105d361040e565b6105db6104ed565b6105e3610229565b6105eb6100da565b565b61025a80610dc683390190565b6101b48061102083390190565b5f5ffd5b5f819050919050565b61061d8161060b565b8114610627575f5ffd5b50565b5f8135905061063881610614565b92915050565b5f6020828403121561065357610652610607565b5b5f6106608482850161062a565b91505092915050565b5f8115159050919050565b61067d81610669565b82525050565b5f6020820190506106965f830184610674565b92915050565b6106a58161060b565b82525050565b5f6040820190506106be5f83018561069c565b6106cb602083018461069c565b9392505050565b6106db81610669565b81146106e5575f5ffd5b50565b5f815190506106f6816106d2565b92915050565b5f6020828403121561071157610710610607565b5b5f61071e848285016106e8565b91505092915050565b5f82825260208201905092915050565b7f5265656e747279206661696c65640000000000000000000000000000000000005f82015250565b5f61076b600e83610727565b915061077682610737565b602082019050919050565b5f6020820190508181035f8301526107988161075f565b9050919050565b7f5265656e7472792076616c69646174696f6e20706173736564000000000000005f82015250565b5f6107d3601983610727565b91506107de8261079f565b602082019050919050565b5f6040820190506107fc5f830184610674565b818103602083015261080d816107c7565b905092915050565b5f819050919050565b5f819050919050565b5f61084161083c61083784610815565b61081e565b61060b565b9050919050565b61085181610827565b82525050565b5f819050919050565b5f61087a61087561087084610857565b61081e565b61060b565b9050919050565b61088a81610860565b82525050565b5f6040820190506108a35f830185610848565b6108b06020830184610881565b9392505050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f610911603783610727565b915061091c826108b7565b604082019050919050565b5f6020820190508181035f83015261093e81610905565b9050919050565b5f6020820190506109585f830184610848565b92915050565b5f8151905061096c81610614565b92915050565b5f6020828403121561098757610986610607565b5b5f6109948482850161095e565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f6109d1601e83610727565b91506109dc8261099d565b602082019050919050565b5f6020820190508181035f8301526109fe816109c5565b9050919050565b7f4e657374656420636f6e7472616374732076616c69646174696f6e20706173735f8201527f6564000000000000000000000000000000000000000000000000000000000000602082015250565b5f610a5f602283610727565b9150610a6a82610a05565b604082019050919050565b5f604082019050610a885f830184610674565b8181036020830152610a9981610a53565b905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f610afb602883610727565b9150610b0682610aa1565b604082019050919050565b5f6020820190508181035f830152610b2881610aef565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610b89602783610727565b9150610b9482610b2f565b604082019050919050565b5f6020820190508181035f830152610bb681610b7d565b9050919050565b7f42617369632066756e6374696f6e616c697479207061737365640000000000005f82015250565b5f610bf1601a83610727565b9150610bfc82610bbd565b602082019050919050565b5f604082019050610c1a5f830184610674565b8181036020830152610c2b81610be5565b905092915050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610c8d603683610727565b9150610c9882610c33565b604082019050919050565b5f6020820190508181035f830152610cba81610c81565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f610d1b603383610727565b9150610d2682610cc1565b604082019050919050565b5f6020820190508181035f830152610d4881610d0f565b9050919050565b7f4c6966656379636c652076616c69646174696f6e2070617373656400000000005f82015250565b5f610d83601b83610727565b9150610d8e82610d4f565b602082019050919050565b5f604082019050610dac5f830184610674565b8181036020830152610dbd81610d77565b90509291505056fe6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea26469706673582212201f962b4b81dfea667fc231f5535eb3b661a369a8f5de4c2a277869f134de9dfa64736f6c634300081c00336080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea264697066735822122022a3efe83f7aff51061bf54c745bd6c6faa7241f45c690093b50304bf5ae7f8564736f6c634300081c0033a26469706673582212208a4da7da84099773dadd4fdd424c43d5904e6e8aaa149414723b4171c54b24d864736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.hex b/actors/evm/tests/contracts/TransientStorageTest.hex index 86db45a26..ef302979c 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.hex +++ b/actors/evm/tests/contracts/TransientStorageTest.hex @@ -1 +1 @@ -6080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea2646970667358221220d79b2f20cfa6deba47093f370319ffaaebfdde191340829ef9aa39d035867cd564736f6c634300081c0033 \ No newline at end of file +6080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea264697066735822122022a3efe83f7aff51061bf54c745bd6c6faa7241f45c690093b50304bf5ae7f8564736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.signatures b/actors/evm/tests/contracts/TransientStorageTest.signatures index 5dce6119b..93dcc25f6 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.signatures +++ b/actors/evm/tests/contracts/TransientStorageTest.signatures @@ -1,5 +1,6 @@ Function signatures: 18e1813f: isStorageCleared(uint256) +23d74628: runTests() cf83c71c: testBasicFunctionality() e90bf998: testLifecycleValidation() 5fcbdd3a: testNestedContracts() diff --git a/actors/evm/tests/contracts/TransientStorageTest.sol b/actors/evm/tests/contracts/TransientStorageTest.sol index 5a7dcd522..f19ee4c89 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.sol +++ b/actors/evm/tests/contracts/TransientStorageTest.sol @@ -1,12 +1,19 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; +import "./NestedContract.sol"; +import "./ReentrantContract.sol"; + contract TransientStorageTest { event TestResult(bool success, string message); constructor() { // Automatically run tests on deployment - _runTests(); + //_runTests(); + } + + function runTests() public returns (bool) { + _runTests(); } function _runTests() internal { @@ -124,34 +131,3 @@ contract TransientStorageTest { emit TestResult(true, "Reentry validation passed"); } } - -contract NestedContract { - function writeTransientData(uint256 slot, uint256 value) external { - assembly { - tstore(slot, value) - } - } - - function readTransientData(uint256 slot) external view returns (uint256) { - uint256 value; - assembly { - value := tload(slot) - } - return value; - } -} - -contract ReentrantContract { - event ReentrySuccess(bool success); - - function callReentry(uint256 slot, uint256 expectedValue) external returns (bool) { - uint256 storedValue; - assembly { - storedValue := tload(slot) - } - require(storedValue == expectedValue, "Reentrant value mismatch"); - - emit ReentrySuccess(true); - return true; - } -} From 3dfe37723e0d597563d1923ce6d56ab26565c194 Mon Sep 17 00:00:00 2001 From: Mikers Date: Tue, 3 Dec 2024 15:20:21 -1000 Subject: [PATCH 11/46] add test confirming transient storage is cleared --- .../src/interpreter/instructions/storage.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/actors/evm/src/interpreter/instructions/storage.rs b/actors/evm/src/interpreter/instructions/storage.rs index fedfb5c83..790558d92 100644 --- a/actors/evm/src/interpreter/instructions/storage.rs +++ b/actors/evm/src/interpreter/instructions/storage.rs @@ -153,4 +153,27 @@ mod tests { assert_eq!(m.system.get_transient_storage(U256::from(0)).unwrap(), U256::from(0x42)); }; } + + #[test] + fn test_tstore_clear() { + evm_unit_test! { + (m) { + TSTORE; + } + + m.state.stack.push(U256::from(0x42)).unwrap(); + m.state.stack.push(U256::from(0)).unwrap(); + let result = m.step(); + assert!(result.is_ok(), "execution step failed"); + assert_eq!(m.state.stack.len(), 0); + assert_eq!(m.system.get_transient_storage(U256::from(0)).unwrap(), U256::from(0x42)); + + //clear transient storage + let result = m.system.reset_transient_storage(None); + assert!(result.is_ok(), "Expected Ok, got Err: {:?}", result.err()); + + //confirm getting value at slot 0 returns 0 + assert_eq!(m.system.get_transient_storage(U256::from(0)).unwrap(), U256::from(0)); + }; + } } From ab808a244c4a7fc0a91ed6b972221290dbc2ed53 Mon Sep 17 00:00:00 2001 From: Mikers Date: Tue, 3 Dec 2024 20:12:09 -1000 Subject: [PATCH 12/46] more test debugging --- actors/evm/tests/basic.rs | 61 ++++++++++++++++--- .../evm/tests/contracts/ReentrantContract.bin | 2 +- .../evm/tests/contracts/ReentrantContract.hex | 2 +- .../evm/tests/contracts/ReentrantContract.sol | 2 +- .../tests/contracts/TransientStorageTest.abi | 2 +- .../tests/contracts/TransientStorageTest.bin | 2 +- .../contracts/TransientStorageTest.signatures | 1 + .../tests/contracts/TransientStorageTest.sol | 33 +++++++--- .../TransientStorageTest_storage.json | 2 +- actors/evm/tests/util.rs | 30 +++++++++ 10 files changed, 114 insertions(+), 23 deletions(-) diff --git a/actors/evm/tests/basic.rs b/actors/evm/tests/basic.rs index 2461dbd54..053078807 100644 --- a/actors/evm/tests/basic.rs +++ b/actors/evm/tests/basic.rs @@ -205,22 +205,70 @@ fn test_push_last_byte() { #[test] fn transient_storage() { - let bytecode = hex::decode(include_str!("contracts/TransientStorageTest.bin")).unwrap(); - transient_storage_test(bytecode); + let transient_storage_bytecode = + hex::decode(include_str!("contracts/TransientStorageTest.bin")).unwrap(); + let nested_storage_bytecode = + hex::decode(include_str!("contracts/NestedContract.bin")).unwrap(); + let reentrant_storage_bytecode = + hex::decode(include_str!("contracts/ReentrantContract.bin")).unwrap(); + transient_storage_test( + transient_storage_bytecode, + nested_storage_bytecode, + reentrant_storage_bytecode, + ); } -fn transient_storage_test(bytecode: Vec) { - let contract = Address::new_id(100); +fn transient_storage_test( + mut transient_storage_bytecode: Vec, + nested_contract_bytecode: Vec, + reentrant_contract_bytecode: Vec, +) { + let nested_contract = Address::new_id(100); + let _rt_nested_contract = util::init_construct_and_verify(nested_contract_bytecode, |rt| { + rt.actor_code_cids.borrow_mut().insert(nested_contract, *EVM_ACTOR_CODE_ID); + rt.set_origin(nested_contract); + }); - let rt = util::init_construct_and_verify(bytecode, |rt| { + let reentrant_contract = Address::new_id(101); + let _rt_reentrant_contract = + util::init_construct_and_verify(reentrant_contract_bytecode, |rt| { + rt.actor_code_cids.borrow_mut().insert(reentrant_contract, *EVM_ACTOR_CODE_ID); + rt.set_origin(reentrant_contract); + }); + + let mut arg_nested_address = vec![0u8; 32]; + arg_nested_address[12] = 0xff; // it's an ID address, so we enable the flag + arg_nested_address[31] = 100; // the owner address + transient_storage_bytecode.append(&mut arg_nested_address); + + let mut arg_reentrant_address = vec![0u8; 32]; + arg_reentrant_address[12] = 0xff; // it's an ID address, so we enable the flag + arg_reentrant_address[31] = 101; // the owner address + transient_storage_bytecode.append(&mut arg_reentrant_address); + + let contract = Address::new_id(102); + let rt = util::init_construct_and_verify(transient_storage_bytecode, |rt| { rt.actor_code_cids.borrow_mut().insert(contract, *EVM_ACTOR_CODE_ID); rt.set_origin(contract); }); let mut solidity_params = vec![]; - solidity_params.extend_from_slice(&hex::decode("23d74628").unwrap()); // function selector, "runTests()" let _result = util::invoke_contract(&rt, &solidity_params); + + // Setup for testing that the transient storage data clears when a new transaction occurs + let mut solidity_params_test_cleared = vec![]; + solidity_params_test_cleared.extend_from_slice(&hex::decode("54e84d1b").unwrap()); // function selector, "testLifecycleValidationSubsequentTransaction()" + // + // We expect this to fail because no changes are made + util::invoke_contract_expect_fail(&rt, &solidity_params_test_cleared); + + //use a new address for our calling context + //This will cause the transient storage data to reset because the transient storage lifecycle value has changed + let new_context = Address::new_id(200); + rt.set_origin(new_context); + + util::invoke_contract(&rt, &solidity_params_test_cleared); } #[test] @@ -249,4 +297,3 @@ fn mcopy_test(bytecode: Vec) { let result = util::invoke_contract(&rt, &solidity_params); assert_eq!(&*result, &*encoded_testdata); } - diff --git a/actors/evm/tests/contracts/ReentrantContract.bin b/actors/evm/tests/contracts/ReentrantContract.bin index f36b7e1a8..6bc298e8f 100644 --- a/actors/evm/tests/contracts/ReentrantContract.bin +++ b/actors/evm/tests/contracts/ReentrantContract.bin @@ -1 +1 @@ -6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea26469706673582212201f962b4b81dfea667fc231f5535eb3b661a369a8f5de4c2a277869f134de9dfa64736f6c634300081c0033 \ No newline at end of file +6080604052348015600e575f5ffd5b506102068061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b610047600480360381019061004291906100e7565b61005d565b604051610054919061013f565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101b2565b60405180910390fd5b600191505092915050565b5f5ffd5b5f819050919050565b6100c6816100b4565b81146100d0575f5ffd5b50565b5f813590506100e1816100bd565b92915050565b5f5f604083850312156100fd576100fc6100b0565b5b5f61010a858286016100d3565b925050602061011b858286016100d3565b9150509250929050565b5f8115159050919050565b61013981610125565b82525050565b5f6020820190506101525f830184610130565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f61019c601883610158565b91506101a782610168565b602082019050919050565b5f6020820190508181035f8301526101c981610190565b905091905056fea2646970667358221220446704e7e7001b2a2045094ee4fcdd0f73ab5fbba3c39686bd80ee3099c2e46c64736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.hex b/actors/evm/tests/contracts/ReentrantContract.hex index f36b7e1a8..6bc298e8f 100644 --- a/actors/evm/tests/contracts/ReentrantContract.hex +++ b/actors/evm/tests/contracts/ReentrantContract.hex @@ -1 +1 @@ -6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea26469706673582212201f962b4b81dfea667fc231f5535eb3b661a369a8f5de4c2a277869f134de9dfa64736f6c634300081c0033 \ No newline at end of file +6080604052348015600e575f5ffd5b506102068061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b610047600480360381019061004291906100e7565b61005d565b604051610054919061013f565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101b2565b60405180910390fd5b600191505092915050565b5f5ffd5b5f819050919050565b6100c6816100b4565b81146100d0575f5ffd5b50565b5f813590506100e1816100bd565b92915050565b5f5f604083850312156100fd576100fc6100b0565b5b5f61010a858286016100d3565b925050602061011b858286016100d3565b9150509250929050565b5f8115159050919050565b61013981610125565b82525050565b5f6020820190506101525f830184610130565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f61019c601883610158565b91506101a782610168565b602082019050919050565b5f6020820190508181035f8301526101c981610190565b905091905056fea2646970667358221220446704e7e7001b2a2045094ee4fcdd0f73ab5fbba3c39686bd80ee3099c2e46c64736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.sol b/actors/evm/tests/contracts/ReentrantContract.sol index 3fa0c4a5c..78ac2750d 100644 --- a/actors/evm/tests/contracts/ReentrantContract.sol +++ b/actors/evm/tests/contracts/ReentrantContract.sol @@ -11,7 +11,7 @@ contract ReentrantContract { } require(storedValue == expectedValue, "Reentrant value mismatch"); - emit ReentrySuccess(true); + //emit ReentrySuccess(true); return true; } } diff --git a/actors/evm/tests/contracts/TransientStorageTest.abi b/actors/evm/tests/contracts/TransientStorageTest.abi index d93e9fb57..6ef3b4402 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.abi +++ b/actors/evm/tests/contracts/TransientStorageTest.abi @@ -1 +1 @@ -[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"TestResult","type":"event"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"runTests","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testNestedContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testReentry","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file +[{"inputs":[{"internalType":"address","name":"nestedAddress","type":"address"},{"internalType":"address","name":"reentrantAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"TestResult","type":"event"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"runTests","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidationSubsequentTransaction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testNestedContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testReentry","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.bin b/actors/evm/tests/contracts/TransientStorageTest.bin index 94a699d95..3e6042bf4 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.bin +++ b/actors/evm/tests/contracts/TransientStorageTest.bin @@ -1 +1 @@ -6080604052348015600e575f5ffd5b506112098061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610060575f3560e01c806317d68eb11461006457806318e1813f1461006e57806323d746281461009e5780635fcbdd3a146100bc578063cf83c71c146100c6578063e90bf998146100d0575b5f5ffd5b61006c6100da565b005b6100886004803603810190610083919061063e565b61020c565b6040516100959190610683565b60405180910390f35b6100a661021d565b6040516100b39190610683565b60405180910390f35b6100c4610229565b005b6100ce61040e565b005b6100d86104ed565b005b5f600590505f604d905080825d5f6040516100f4906105ed565b604051809103905ff08015801561010d573d5f5f3e3d5ffd5b5090505f8173ffffffffffffffffffffffffffffffffffffffff1663d52aa44785856040518363ffffffff1660e01b815260040161014c9291906106ab565b6020604051808303815f875af1158015610168573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061018c91906106fc565b9050806101ce576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101c590610781565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516101fe91906107e9565b60405180910390a150505050565b5f5f825c90505f8114915050919050565b5f6102266105cb565b90565b5f604051610236906105fa565b604051809103905ff08015801561024f573d5f5f3e3d5ffd5b5090505f600490505f6058905080825d8273ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b815260040161029c929190610890565b5f604051808303815f87803b1580156102b3575f5ffd5b505af11580156102c5573d5f5f3e3d5ffd5b505050505f825c9050818114610310576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161030790610927565b60405180910390fd5b5f8473ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b815260040161034b9190610945565b602060405180830381865afa158015610366573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061038a9190610972565b9050607b81146103cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103c6906109e7565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516103ff9190610a75565b60405180910390a15050505050565b5f600190505f602a905080825d5f825c9050818114610462576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161045990610b11565b60405180910390fd5b5f600290505f815c90505f81146104ae576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104a590610b9f565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516104de9190610c07565b60405180910390a15050505050565b5f600390505f6063905080825d5f825c9050818114610541576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161053890610ca3565b60405180910390fd5b5f61054b8461020c565b90508061058d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161058490610d31565b60405180910390fd5b7f08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f60016040516105bd9190610d99565b60405180910390a150505050565b6105d361040e565b6105db6104ed565b6105e3610229565b6105eb6100da565b565b61025a80610dc683390190565b6101b48061102083390190565b5f5ffd5b5f819050919050565b61061d8161060b565b8114610627575f5ffd5b50565b5f8135905061063881610614565b92915050565b5f6020828403121561065357610652610607565b5b5f6106608482850161062a565b91505092915050565b5f8115159050919050565b61067d81610669565b82525050565b5f6020820190506106965f830184610674565b92915050565b6106a58161060b565b82525050565b5f6040820190506106be5f83018561069c565b6106cb602083018461069c565b9392505050565b6106db81610669565b81146106e5575f5ffd5b50565b5f815190506106f6816106d2565b92915050565b5f6020828403121561071157610710610607565b5b5f61071e848285016106e8565b91505092915050565b5f82825260208201905092915050565b7f5265656e747279206661696c65640000000000000000000000000000000000005f82015250565b5f61076b600e83610727565b915061077682610737565b602082019050919050565b5f6020820190508181035f8301526107988161075f565b9050919050565b7f5265656e7472792076616c69646174696f6e20706173736564000000000000005f82015250565b5f6107d3601983610727565b91506107de8261079f565b602082019050919050565b5f6040820190506107fc5f830184610674565b818103602083015261080d816107c7565b905092915050565b5f819050919050565b5f819050919050565b5f61084161083c61083784610815565b61081e565b61060b565b9050919050565b61085181610827565b82525050565b5f819050919050565b5f61087a61087561087084610857565b61081e565b61060b565b9050919050565b61088a81610860565b82525050565b5f6040820190506108a35f830185610848565b6108b06020830184610881565b9392505050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f610911603783610727565b915061091c826108b7565b604082019050919050565b5f6020820190508181035f83015261093e81610905565b9050919050565b5f6020820190506109585f830184610848565b92915050565b5f8151905061096c81610614565b92915050565b5f6020828403121561098757610986610607565b5b5f6109948482850161095e565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f6109d1601e83610727565b91506109dc8261099d565b602082019050919050565b5f6020820190508181035f8301526109fe816109c5565b9050919050565b7f4e657374656420636f6e7472616374732076616c69646174696f6e20706173735f8201527f6564000000000000000000000000000000000000000000000000000000000000602082015250565b5f610a5f602283610727565b9150610a6a82610a05565b604082019050919050565b5f604082019050610a885f830184610674565b8181036020830152610a9981610a53565b905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f610afb602883610727565b9150610b0682610aa1565b604082019050919050565b5f6020820190508181035f830152610b2881610aef565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610b89602783610727565b9150610b9482610b2f565b604082019050919050565b5f6020820190508181035f830152610bb681610b7d565b9050919050565b7f42617369632066756e6374696f6e616c697479207061737365640000000000005f82015250565b5f610bf1601a83610727565b9150610bfc82610bbd565b602082019050919050565b5f604082019050610c1a5f830184610674565b8181036020830152610c2b81610be5565b905092915050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610c8d603683610727565b9150610c9882610c33565b604082019050919050565b5f6020820190508181035f830152610cba81610c81565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f610d1b603383610727565b9150610d2682610cc1565b604082019050919050565b5f6020820190508181035f830152610d4881610d0f565b9050919050565b7f4c6966656379636c652076616c69646174696f6e2070617373656400000000005f82015250565b5f610d83601b83610727565b9150610d8e82610d4f565b602082019050919050565b5f604082019050610dac5f830184610674565b8181036020830152610dbd81610d77565b90509291505056fe6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea26469706673582212201f962b4b81dfea667fc231f5535eb3b661a369a8f5de4c2a277869f134de9dfa64736f6c634300081c00336080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea264697066735822122022a3efe83f7aff51061bf54c745bd6c6faa7241f45c690093b50304bf5ae7f8564736f6c634300081c0033a26469706673582212208a4da7da84099773dadd4fdd424c43d5904e6e8aaa149414723b4171c54b24d864736f6c634300081c0033 \ No newline at end of file +608060405234801561000f575f5ffd5b50604051610c8d380380610c8d83398181016040528101906100319190610115565b815f5f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050610153565b5f5ffd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100e4826100bb565b9050919050565b6100f4816100da565b81146100fe575f5ffd5b50565b5f8151905061010f816100eb565b92915050565b5f5f6040838503121561012b5761012a6100b7565b5b5f61013885828601610101565b925050602061014985828601610101565b9150509250929050565b610b2d806101605f395ff3fe608060405234801561000f575f5ffd5b506004361061007b575f3560e01c806354e84d1b1161005957806354e84d1b146100d75780635fcbdd3a146100e1578063cf83c71c146100eb578063e90bf998146100f55761007b565b806317d68eb11461007f57806318e1813f1461008957806323d74628146100b9575b5f5ffd5b6100876100ff565b005b6100a3600480360381019061009e919061056e565b6101f0565b6040516100b091906105b3565b60405180910390f35b6100c1610201565b6040516100ce91906105b3565b60405180910390f35b6100df61020d565b005b6100e9610262565b005b6100f3610425565b005b6100fd6104cc565b005b5f600590505f604d905080825d5f60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d52aa44784846040518363ffffffff1660e01b81526004016101699291906105db565b6020604051808303815f875af1158015610185573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101a9919061062c565b9050806101eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101e2906106b1565b60405180910390fd5b505050565b5f5f825c90505f8114915050919050565b5f61020a610525565b90565b5f600390505f61021c826101f0565b90508061025e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102559061073f565b60405180910390fd5b5050565b5f600490505f6058905080825d5f5f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b81526004016102cc9291906107d8565b5f604051808303815f87803b1580156102e3575f5ffd5b505af11580156102f5573d5f5f3e3d5ffd5b505050505f825c9050818114610340576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103379061086f565b60405180910390fd5b5f5f5f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b815260040161039b919061088d565b602060405180830381865afa1580156103b6573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103da91906108ba565b9050607b811461041f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104169061092f565b60405180910390fd5b50505050565b5f600190505f602a905080825d5f825c9050818114610479576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610470906109bd565b60405180910390fd5b5f600290505f815c90505f81146104c5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104bc90610a4b565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c9050818114610520576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161051790610ad9565b60405180910390fd5b505050565b61052d610425565b6105356104cc565b565b5f5ffd5b5f819050919050565b61054d8161053b565b8114610557575f5ffd5b50565b5f8135905061056881610544565b92915050565b5f6020828403121561058357610582610537565b5b5f6105908482850161055a565b91505092915050565b5f8115159050919050565b6105ad81610599565b82525050565b5f6020820190506105c65f8301846105a4565b92915050565b6105d58161053b565b82525050565b5f6040820190506105ee5f8301856105cc565b6105fb60208301846105cc565b9392505050565b61060b81610599565b8114610615575f5ffd5b50565b5f8151905061062681610602565b92915050565b5f6020828403121561064157610640610537565b5b5f61064e84828501610618565b91505092915050565b5f82825260208201905092915050565b7f5265656e747279206661696c65640000000000000000000000000000000000005f82015250565b5f61069b600e83610657565b91506106a682610667565b602082019050919050565b5f6020820190508181035f8301526106c88161068f565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f610729603383610657565b9150610734826106cf565b604082019050919050565b5f6020820190508181035f8301526107568161071d565b9050919050565b5f819050919050565b5f819050919050565b5f61078961078461077f8461075d565b610766565b61053b565b9050919050565b6107998161076f565b82525050565b5f819050919050565b5f6107c26107bd6107b88461079f565b610766565b61053b565b9050919050565b6107d2816107a8565b82525050565b5f6040820190506107eb5f830185610790565b6107f860208301846107c9565b9392505050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f610859603783610657565b9150610864826107ff565b604082019050919050565b5f6020820190508181035f8301526108868161084d565b9050919050565b5f6020820190506108a05f830184610790565b92915050565b5f815190506108b481610544565b92915050565b5f602082840312156108cf576108ce610537565b5b5f6108dc848285016108a6565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f610919601e83610657565b9150610924826108e5565b602082019050919050565b5f6020820190508181035f8301526109468161090d565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6109a7602883610657565b91506109b28261094d565b604082019050919050565b5f6020820190508181035f8301526109d48161099b565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610a35602783610657565b9150610a40826109db565b604082019050919050565b5f6020820190508181035f830152610a6281610a29565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610ac3603683610657565b9150610ace82610a69565b604082019050919050565b5f6020820190508181035f830152610af081610ab7565b905091905056fea26469706673582212206a1bd88ba2340456a02cbc0613039a57760acf0bf432df4d19c32c527d141b3864736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.signatures b/actors/evm/tests/contracts/TransientStorageTest.signatures index 93dcc25f6..4de108df1 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.signatures +++ b/actors/evm/tests/contracts/TransientStorageTest.signatures @@ -3,6 +3,7 @@ Function signatures: 23d74628: runTests() cf83c71c: testBasicFunctionality() e90bf998: testLifecycleValidation() +54e84d1b: testLifecycleValidationSubsequentTransaction() 5fcbdd3a: testNestedContracts() 17d68eb1: testReentry() diff --git a/actors/evm/tests/contracts/TransientStorageTest.sol b/actors/evm/tests/contracts/TransientStorageTest.sol index f19ee4c89..bbd9fa87c 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.sol +++ b/actors/evm/tests/contracts/TransientStorageTest.sol @@ -7,9 +7,12 @@ import "./ReentrantContract.sol"; contract TransientStorageTest { event TestResult(bool success, string message); - constructor() { - // Automatically run tests on deployment - //_runTests(); + NestedContract nested; + ReentrantContract reentrant; + + constructor(address nestedAddress, address reentrantAddress) { + nested = NestedContract(nestedAddress); + reentrant = ReentrantContract(reentrantAddress); } function runTests() public returns (bool) { @@ -19,6 +22,15 @@ contract TransientStorageTest { function _runTests() internal { testBasicFunctionality(); testLifecycleValidation(); + + return; + + // XXX Currently calling any external methods in the basic evm test framework causes a revert + // This is unrelated to the transient data code being tested but a factor of the MockRuntime framework + // It also means that we can't currently properly test nested contracts or reentrancy + + // It may be that the next two tests are not compatible with the MockRuntime framework and will need to run in Lotus + testNestedContracts(); testReentry(); } @@ -50,7 +62,7 @@ contract TransientStorageTest { require(uninitializedValue == 0, "Uninitialized TLOAD did not return zero"); - emit TestResult(true, "Basic functionality passed"); + //emit TestResult(true, "Basic functionality passed"); } // Test 2.1: Verify transient storage clears after transaction @@ -69,12 +81,15 @@ contract TransientStorageTest { retrievedValue := tload(slot) } require(retrievedValue == value, "TLOAD did not retrieve stored value within transaction"); + } - // Test clearing by re-calling a new transaction + function testLifecycleValidationSubsequentTransaction() public { + // Test clearing by re-calling as a new transaction + uint256 slot = 3; bool cleared = isStorageCleared(slot); require(cleared, "Transient storage was not cleared after transaction"); - emit TestResult(true, "Lifecycle validation passed"); + //emit TestResult(true, "Lifecycle validation passed"); } function isStorageCleared(uint256 slot) public view returns (bool) { @@ -87,7 +102,6 @@ contract TransientStorageTest { // Test 2.2: Verify nested contract independence function testNestedContracts() public { - NestedContract nested = new NestedContract(); uint256 slot = 4; uint256 value = 88; @@ -110,7 +124,7 @@ contract TransientStorageTest { uint256 nestedValue = nested.readTransientData(4); require(nestedValue == 123, "Nested contract data incorrect"); - emit TestResult(true, "Nested contracts validation passed"); + //emit TestResult(true, "Nested contracts validation passed"); } // Test 2.3: Verify transient storage during reentry @@ -124,10 +138,9 @@ contract TransientStorageTest { } // Call reentrant contract - ReentrantContract reentrant = new ReentrantContract(); bool success = reentrant.callReentry(slot, value); require(success, "Reentry failed"); - emit TestResult(true, "Reentry validation passed"); + //emit TestResult(true, "Reentry validation passed"); } } diff --git a/actors/evm/tests/contracts/TransientStorageTest_storage.json b/actors/evm/tests/contracts/TransientStorageTest_storage.json index 325d0043f..cdae40d25 100644 --- a/actors/evm/tests/contracts/TransientStorageTest_storage.json +++ b/actors/evm/tests/contracts/TransientStorageTest_storage.json @@ -1 +1 @@ -{"storage":[]} \ No newline at end of file +{"storage":[{"astId":12,"contract":"tests/contracts/TransientStorageTest.sol:TransientStorageTest","label":"nested","offset":0,"slot":"0","type":"t_contract(NestedContract)257"},{"astId":15,"contract":"tests/contracts/TransientStorageTest.sol:TransientStorageTest","label":"reentrant","offset":0,"slot":"1","type":"t_contract(ReentrantContract)287"}],"types":{"t_contract(NestedContract)257":{"encoding":"inplace","label":"contract NestedContract","numberOfBytes":"20"},"t_contract(ReentrantContract)287":{"encoding":"inplace","label":"contract ReentrantContract","numberOfBytes":"20"}}} \ No newline at end of file diff --git a/actors/evm/tests/util.rs b/actors/evm/tests/util.rs index b91ddc9f3..3f620d8ae 100644 --- a/actors/evm/tests/util.rs +++ b/actors/evm/tests/util.rs @@ -80,6 +80,36 @@ pub fn invoke_contract(rt: &MockRuntime, input_data: &[u8]) -> Vec { res } +#[allow(dead_code)] +pub fn invoke_contract_expect_fail(rt: &MockRuntime, input_data: &[u8]) { + rt.expect_validate_caller_any(); + + // Call the contract and check if it results in an error + let result = rt.call::( + evm::Method::InvokeContract as u64, + IpldBlock::serialize_cbor(&BytesSer(input_data)).unwrap(), + ); + + // Ensure the call fails as expected + match result { + Ok(_) => panic!("Expected contract invocation to fail, but it succeeded"), + Err(err) => { + // Use accessor methods for `exit_code` and `msg` + assert_eq!(err.exit_code().value(), 33, "Unexpected exit code"); + + // Directly use `err.msg()` as it returns `&str` + let msg = err.msg(); + assert!( + msg.contains("contract reverted"), + "Unexpected error message: {}", + msg + ); + } + } +} + + + #[allow(dead_code)] // silly to have the full word for a single byte but... pub fn dispatch_num_word(method_num: u8) -> [u8; 32] { From 20aefb509dfd7beff80dfd78676fe31fe5b50e29 Mon Sep 17 00:00:00 2001 From: Mikers Date: Tue, 3 Dec 2024 20:48:53 -1000 Subject: [PATCH 13/46] cargo fmt --- actors/evm/tests/basic.rs | 2 +- actors/evm/tests/util.rs | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/actors/evm/tests/basic.rs b/actors/evm/tests/basic.rs index 053078807..d0a56a221 100644 --- a/actors/evm/tests/basic.rs +++ b/actors/evm/tests/basic.rs @@ -260,7 +260,7 @@ fn transient_storage_test( let mut solidity_params_test_cleared = vec![]; solidity_params_test_cleared.extend_from_slice(&hex::decode("54e84d1b").unwrap()); // function selector, "testLifecycleValidationSubsequentTransaction()" // - // We expect this to fail because no changes are made + // We expect this to fail because no changes are made util::invoke_contract_expect_fail(&rt, &solidity_params_test_cleared); //use a new address for our calling context diff --git a/actors/evm/tests/util.rs b/actors/evm/tests/util.rs index 3f620d8ae..df83179cd 100644 --- a/actors/evm/tests/util.rs +++ b/actors/evm/tests/util.rs @@ -99,17 +99,11 @@ pub fn invoke_contract_expect_fail(rt: &MockRuntime, input_data: &[u8]) { // Directly use `err.msg()` as it returns `&str` let msg = err.msg(); - assert!( - msg.contains("contract reverted"), - "Unexpected error message: {}", - msg - ); + assert!(msg.contains("contract reverted"), "Unexpected error message: {}", msg); } } } - - #[allow(dead_code)] // silly to have the full word for a single byte but... pub fn dispatch_num_word(method_num: u8) -> [u8; 32] { From 99c1e6be5c1f3ec61858f7ae8b8e48b81f1f0cfd Mon Sep 17 00:00:00 2001 From: Mikers Date: Tue, 3 Dec 2024 20:54:22 -1000 Subject: [PATCH 14/46] fix cargo check nit --- actors/evm/src/interpreter/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 6a4a0968b..f95206ed9 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -509,7 +509,7 @@ impl<'r, RT: Runtime> System<'r, RT> { // Use `for_each` to collect all keys self.transient_slots .for_each(|key, _| { - keys_to_delete.push(key.clone()); + keys_to_delete.push(*key); Ok(()) }) .map_err( From 2b811de1984d3eabe3fe9f4c2cc43e9b7bb5d95f Mon Sep 17 00:00:00 2001 From: Mikers Date: Fri, 6 Dec 2024 16:13:49 -1000 Subject: [PATCH 15/46] simplify transient test --- actors/evm/tests/basic.rs | 41 +---------- .../evm/tests/contracts/ReentrantContract.bin | 2 +- .../evm/tests/contracts/ReentrantContract.hex | 2 +- .../evm/tests/contracts/ReentrantContract.sol | 7 +- .../tests/contracts/TransientStorageTest.abi | 2 +- .../tests/contracts/TransientStorageTest.bin | 2 +- .../tests/contracts/TransientStorageTest.hex | 2 +- .../contracts/TransientStorageTest.signatures | 5 -- .../tests/contracts/TransientStorageTest.sol | 71 +------------------ .../TransientStorageTest_storage.json | 2 +- 10 files changed, 15 insertions(+), 121 deletions(-) diff --git a/actors/evm/tests/basic.rs b/actors/evm/tests/basic.rs index d0a56a221..7f527d68a 100644 --- a/actors/evm/tests/basic.rs +++ b/actors/evm/tests/basic.rs @@ -207,46 +207,11 @@ fn test_push_last_byte() { fn transient_storage() { let transient_storage_bytecode = hex::decode(include_str!("contracts/TransientStorageTest.bin")).unwrap(); - let nested_storage_bytecode = - hex::decode(include_str!("contracts/NestedContract.bin")).unwrap(); - let reentrant_storage_bytecode = - hex::decode(include_str!("contracts/ReentrantContract.bin")).unwrap(); - transient_storage_test( - transient_storage_bytecode, - nested_storage_bytecode, - reentrant_storage_bytecode, - ); + transient_storage_test(transient_storage_bytecode); } -fn transient_storage_test( - mut transient_storage_bytecode: Vec, - nested_contract_bytecode: Vec, - reentrant_contract_bytecode: Vec, -) { - let nested_contract = Address::new_id(100); - let _rt_nested_contract = util::init_construct_and_verify(nested_contract_bytecode, |rt| { - rt.actor_code_cids.borrow_mut().insert(nested_contract, *EVM_ACTOR_CODE_ID); - rt.set_origin(nested_contract); - }); - - let reentrant_contract = Address::new_id(101); - let _rt_reentrant_contract = - util::init_construct_and_verify(reentrant_contract_bytecode, |rt| { - rt.actor_code_cids.borrow_mut().insert(reentrant_contract, *EVM_ACTOR_CODE_ID); - rt.set_origin(reentrant_contract); - }); - - let mut arg_nested_address = vec![0u8; 32]; - arg_nested_address[12] = 0xff; // it's an ID address, so we enable the flag - arg_nested_address[31] = 100; // the owner address - transient_storage_bytecode.append(&mut arg_nested_address); - - let mut arg_reentrant_address = vec![0u8; 32]; - arg_reentrant_address[12] = 0xff; // it's an ID address, so we enable the flag - arg_reentrant_address[31] = 101; // the owner address - transient_storage_bytecode.append(&mut arg_reentrant_address); - - let contract = Address::new_id(102); +fn transient_storage_test(transient_storage_bytecode: Vec) { + let contract = Address::new_id(100); let rt = util::init_construct_and_verify(transient_storage_bytecode, |rt| { rt.actor_code_cids.borrow_mut().insert(contract, *EVM_ACTOR_CODE_ID); rt.set_origin(contract); diff --git a/actors/evm/tests/contracts/ReentrantContract.bin b/actors/evm/tests/contracts/ReentrantContract.bin index 6bc298e8f..dc074cae3 100644 --- a/actors/evm/tests/contracts/ReentrantContract.bin +++ b/actors/evm/tests/contracts/ReentrantContract.bin @@ -1 +1 @@ -6080604052348015600e575f5ffd5b506102068061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b610047600480360381019061004291906100e7565b61005d565b604051610054919061013f565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101b2565b60405180910390fd5b600191505092915050565b5f5ffd5b5f819050919050565b6100c6816100b4565b81146100d0575f5ffd5b50565b5f813590506100e1816100bd565b92915050565b5f5f604083850312156100fd576100fc6100b0565b5b5f61010a858286016100d3565b925050602061011b858286016100d3565b9150509250929050565b5f8115159050919050565b61013981610125565b82525050565b5f6020820190506101525f830184610130565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f61019c601883610158565b91506101a782610168565b602082019050919050565b5f6020820190508181035f8301526101c981610190565b905091905056fea2646970667358221220446704e7e7001b2a2045094ee4fcdd0f73ab5fbba3c39686bd80ee3099c2e46c64736f6c634300081c0033 \ No newline at end of file +6080604052348015600e575f5ffd5b506102068061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b610047600480360381019061004291906100e7565b61005d565b604051610054919061013f565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101b2565b60405180910390fd5b600191505092915050565b5f5ffd5b5f819050919050565b6100c6816100b4565b81146100d0575f5ffd5b50565b5f813590506100e1816100bd565b92915050565b5f5f604083850312156100fd576100fc6100b0565b5b5f61010a858286016100d3565b925050602061011b858286016100d3565b9150509250929050565b5f8115159050919050565b61013981610125565b82525050565b5f6020820190506101525f830184610130565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f61019c601883610158565b91506101a782610168565b602082019050919050565b5f6020820190508181035f8301526101c981610190565b905091905056fea2646970667358221220fdf471a84a6318ce450d9a366e4db4df8fd229bc05a0474ed51db62d3713620064736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.hex b/actors/evm/tests/contracts/ReentrantContract.hex index 6bc298e8f..dc074cae3 100644 --- a/actors/evm/tests/contracts/ReentrantContract.hex +++ b/actors/evm/tests/contracts/ReentrantContract.hex @@ -1 +1 @@ -6080604052348015600e575f5ffd5b506102068061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b610047600480360381019061004291906100e7565b61005d565b604051610054919061013f565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101b2565b60405180910390fd5b600191505092915050565b5f5ffd5b5f819050919050565b6100c6816100b4565b81146100d0575f5ffd5b50565b5f813590506100e1816100bd565b92915050565b5f5f604083850312156100fd576100fc6100b0565b5b5f61010a858286016100d3565b925050602061011b858286016100d3565b9150509250929050565b5f8115159050919050565b61013981610125565b82525050565b5f6020820190506101525f830184610130565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f61019c601883610158565b91506101a782610168565b602082019050919050565b5f6020820190508181035f8301526101c981610190565b905091905056fea2646970667358221220446704e7e7001b2a2045094ee4fcdd0f73ab5fbba3c39686bd80ee3099c2e46c64736f6c634300081c0033 \ No newline at end of file +6080604052348015600e575f5ffd5b506102068061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b610047600480360381019061004291906100e7565b61005d565b604051610054919061013f565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101b2565b60405180910390fd5b600191505092915050565b5f5ffd5b5f819050919050565b6100c6816100b4565b81146100d0575f5ffd5b50565b5f813590506100e1816100bd565b92915050565b5f5f604083850312156100fd576100fc6100b0565b5b5f61010a858286016100d3565b925050602061011b858286016100d3565b9150509250929050565b5f8115159050919050565b61013981610125565b82525050565b5f6020820190506101525f830184610130565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f61019c601883610158565b91506101a782610168565b602082019050919050565b5f6020820190508181035f8301526101c981610190565b905091905056fea2646970667358221220fdf471a84a6318ce450d9a366e4db4df8fd229bc05a0474ed51db62d3713620064736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.sol b/actors/evm/tests/contracts/ReentrantContract.sol index 78ac2750d..3e2adcb56 100644 --- a/actors/evm/tests/contracts/ReentrantContract.sol +++ b/actors/evm/tests/contracts/ReentrantContract.sol @@ -5,13 +5,16 @@ contract ReentrantContract { event ReentrySuccess(bool success); function callReentry(uint256 slot, uint256 expectedValue) external returns (bool) { + /* + * TODO + * Actually test for reentry + * */ + uint256 storedValue; assembly { storedValue := tload(slot) } require(storedValue == expectedValue, "Reentrant value mismatch"); - - //emit ReentrySuccess(true); return true; } } diff --git a/actors/evm/tests/contracts/TransientStorageTest.abi b/actors/evm/tests/contracts/TransientStorageTest.abi index 6ef3b4402..628597ccd 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.abi +++ b/actors/evm/tests/contracts/TransientStorageTest.abi @@ -1 +1 @@ -[{"inputs":[{"internalType":"address","name":"nestedAddress","type":"address"},{"internalType":"address","name":"reentrantAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"TestResult","type":"event"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"runTests","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidationSubsequentTransaction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testNestedContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testReentry","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file +[{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"runTests","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidationSubsequentTransaction","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.bin b/actors/evm/tests/contracts/TransientStorageTest.bin index 3e6042bf4..47b789418 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.bin +++ b/actors/evm/tests/contracts/TransientStorageTest.bin @@ -1 +1 @@ -608060405234801561000f575f5ffd5b50604051610c8d380380610c8d83398181016040528101906100319190610115565b815f5f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050610153565b5f5ffd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100e4826100bb565b9050919050565b6100f4816100da565b81146100fe575f5ffd5b50565b5f8151905061010f816100eb565b92915050565b5f5f6040838503121561012b5761012a6100b7565b5b5f61013885828601610101565b925050602061014985828601610101565b9150509250929050565b610b2d806101605f395ff3fe608060405234801561000f575f5ffd5b506004361061007b575f3560e01c806354e84d1b1161005957806354e84d1b146100d75780635fcbdd3a146100e1578063cf83c71c146100eb578063e90bf998146100f55761007b565b806317d68eb11461007f57806318e1813f1461008957806323d74628146100b9575b5f5ffd5b6100876100ff565b005b6100a3600480360381019061009e919061056e565b6101f0565b6040516100b091906105b3565b60405180910390f35b6100c1610201565b6040516100ce91906105b3565b60405180910390f35b6100df61020d565b005b6100e9610262565b005b6100f3610425565b005b6100fd6104cc565b005b5f600590505f604d905080825d5f60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d52aa44784846040518363ffffffff1660e01b81526004016101699291906105db565b6020604051808303815f875af1158015610185573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101a9919061062c565b9050806101eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101e2906106b1565b60405180910390fd5b505050565b5f5f825c90505f8114915050919050565b5f61020a610525565b90565b5f600390505f61021c826101f0565b90508061025e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102559061073f565b60405180910390fd5b5050565b5f600490505f6058905080825d5f5f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b81526004016102cc9291906107d8565b5f604051808303815f87803b1580156102e3575f5ffd5b505af11580156102f5573d5f5f3e3d5ffd5b505050505f825c9050818114610340576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103379061086f565b60405180910390fd5b5f5f5f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b815260040161039b919061088d565b602060405180830381865afa1580156103b6573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103da91906108ba565b9050607b811461041f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104169061092f565b60405180910390fd5b50505050565b5f600190505f602a905080825d5f825c9050818114610479576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610470906109bd565b60405180910390fd5b5f600290505f815c90505f81146104c5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104bc90610a4b565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c9050818114610520576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161051790610ad9565b60405180910390fd5b505050565b61052d610425565b6105356104cc565b565b5f5ffd5b5f819050919050565b61054d8161053b565b8114610557575f5ffd5b50565b5f8135905061056881610544565b92915050565b5f6020828403121561058357610582610537565b5b5f6105908482850161055a565b91505092915050565b5f8115159050919050565b6105ad81610599565b82525050565b5f6020820190506105c65f8301846105a4565b92915050565b6105d58161053b565b82525050565b5f6040820190506105ee5f8301856105cc565b6105fb60208301846105cc565b9392505050565b61060b81610599565b8114610615575f5ffd5b50565b5f8151905061062681610602565b92915050565b5f6020828403121561064157610640610537565b5b5f61064e84828501610618565b91505092915050565b5f82825260208201905092915050565b7f5265656e747279206661696c65640000000000000000000000000000000000005f82015250565b5f61069b600e83610657565b91506106a682610667565b602082019050919050565b5f6020820190508181035f8301526106c88161068f565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f610729603383610657565b9150610734826106cf565b604082019050919050565b5f6020820190508181035f8301526107568161071d565b9050919050565b5f819050919050565b5f819050919050565b5f61078961078461077f8461075d565b610766565b61053b565b9050919050565b6107998161076f565b82525050565b5f819050919050565b5f6107c26107bd6107b88461079f565b610766565b61053b565b9050919050565b6107d2816107a8565b82525050565b5f6040820190506107eb5f830185610790565b6107f860208301846107c9565b9392505050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f610859603783610657565b9150610864826107ff565b604082019050919050565b5f6020820190508181035f8301526108868161084d565b9050919050565b5f6020820190506108a05f830184610790565b92915050565b5f815190506108b481610544565b92915050565b5f602082840312156108cf576108ce610537565b5b5f6108dc848285016108a6565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f610919601e83610657565b9150610924826108e5565b602082019050919050565b5f6020820190508181035f8301526109468161090d565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6109a7602883610657565b91506109b28261094d565b604082019050919050565b5f6020820190508181035f8301526109d48161099b565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610a35602783610657565b9150610a40826109db565b604082019050919050565b5f6020820190508181035f830152610a6281610a29565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610ac3603683610657565b9150610ace82610a69565b604082019050919050565b5f6020820190508181035f830152610af081610ab7565b905091905056fea26469706673582212206a1bd88ba2340456a02cbc0613039a57760acf0bf432df4d19c32c527d141b3864736f6c634300081c0033 \ No newline at end of file +6080604052348015600e575f5ffd5b5061055c8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610055575f3560e01c806318e1813f1461005957806323d746281461008957806354e84d1b146100a7578063cf83c71c146100b1578063e90bf998146100bb575b5f5ffd5b610073600480360381019061006e9190610280565b6100c5565b60405161008091906102c5565b60405180910390f35b6100916100d6565b60405161009e91906102c5565b60405180910390f35b6100af6100e2565b005b6100b9610137565b005b6100c36101de565b005b5f5f825c90505f8114915050919050565b5f6100df610237565b90565b5f600390505f6100f1826100c5565b905080610133576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012a9061035e565b60405180910390fd5b5050565b5f600190505f602a905080825d5f825c905081811461018b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610182906103ec565b60405180910390fd5b5f600290505f815c90505f81146101d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101ce9061047a565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c9050818114610232576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161022990610508565b60405180910390fd5b505050565b61023f610137565b6102476101de565b565b5f5ffd5b5f819050919050565b61025f8161024d565b8114610269575f5ffd5b50565b5f8135905061027a81610256565b92915050565b5f6020828403121561029557610294610249565b5b5f6102a28482850161026c565b91505092915050565b5f8115159050919050565b6102bf816102ab565b82525050565b5f6020820190506102d85f8301846102b6565b92915050565b5f82825260208201905092915050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f6103486033836102de565b9150610353826102ee565b604082019050919050565b5f6020820190508181035f8301526103758161033c565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6103d66028836102de565b91506103e18261037c565b604082019050919050565b5f6020820190508181035f830152610403816103ca565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f6104646027836102de565b915061046f8261040a565b604082019050919050565b5f6020820190508181035f83015261049181610458565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f6104f26036836102de565b91506104fd82610498565b604082019050919050565b5f6020820190508181035f83015261051f816104e6565b905091905056fea264697066735822122052e3d4e0bfd7d10a14d0926c78bc8f14b137d5262eb40d47e6825bffd82faca964736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.hex b/actors/evm/tests/contracts/TransientStorageTest.hex index ef302979c..47b789418 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.hex +++ b/actors/evm/tests/contracts/TransientStorageTest.hex @@ -1 +1 @@ -6080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea264697066735822122022a3efe83f7aff51061bf54c745bd6c6faa7241f45c690093b50304bf5ae7f8564736f6c634300081c0033 \ No newline at end of file +6080604052348015600e575f5ffd5b5061055c8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610055575f3560e01c806318e1813f1461005957806323d746281461008957806354e84d1b146100a7578063cf83c71c146100b1578063e90bf998146100bb575b5f5ffd5b610073600480360381019061006e9190610280565b6100c5565b60405161008091906102c5565b60405180910390f35b6100916100d6565b60405161009e91906102c5565b60405180910390f35b6100af6100e2565b005b6100b9610137565b005b6100c36101de565b005b5f5f825c90505f8114915050919050565b5f6100df610237565b90565b5f600390505f6100f1826100c5565b905080610133576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012a9061035e565b60405180910390fd5b5050565b5f600190505f602a905080825d5f825c905081811461018b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610182906103ec565b60405180910390fd5b5f600290505f815c90505f81146101d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101ce9061047a565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c9050818114610232576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161022990610508565b60405180910390fd5b505050565b61023f610137565b6102476101de565b565b5f5ffd5b5f819050919050565b61025f8161024d565b8114610269575f5ffd5b50565b5f8135905061027a81610256565b92915050565b5f6020828403121561029557610294610249565b5b5f6102a28482850161026c565b91505092915050565b5f8115159050919050565b6102bf816102ab565b82525050565b5f6020820190506102d85f8301846102b6565b92915050565b5f82825260208201905092915050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f6103486033836102de565b9150610353826102ee565b604082019050919050565b5f6020820190508181035f8301526103758161033c565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6103d66028836102de565b91506103e18261037c565b604082019050919050565b5f6020820190508181035f830152610403816103ca565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f6104646027836102de565b915061046f8261040a565b604082019050919050565b5f6020820190508181035f83015261049181610458565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f6104f26036836102de565b91506104fd82610498565b604082019050919050565b5f6020820190508181035f83015261051f816104e6565b905091905056fea264697066735822122052e3d4e0bfd7d10a14d0926c78bc8f14b137d5262eb40d47e6825bffd82faca964736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.signatures b/actors/evm/tests/contracts/TransientStorageTest.signatures index 4de108df1..cf07a9d29 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.signatures +++ b/actors/evm/tests/contracts/TransientStorageTest.signatures @@ -4,8 +4,3 @@ Function signatures: cf83c71c: testBasicFunctionality() e90bf998: testLifecycleValidation() 54e84d1b: testLifecycleValidationSubsequentTransaction() -5fcbdd3a: testNestedContracts() -17d68eb1: testReentry() - -Event signatures: -08ac145f3e770071f0c37bc3ff2567bb378849e8681fd23c65de36a8e6a4955f: TestResult(bool,string) diff --git a/actors/evm/tests/contracts/TransientStorageTest.sol b/actors/evm/tests/contracts/TransientStorageTest.sol index bbd9fa87c..0ab1133b5 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.sol +++ b/actors/evm/tests/contracts/TransientStorageTest.sol @@ -1,38 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -import "./NestedContract.sol"; -import "./ReentrantContract.sol"; - contract TransientStorageTest { - event TestResult(bool success, string message); - - NestedContract nested; - ReentrantContract reentrant; - - constructor(address nestedAddress, address reentrantAddress) { - nested = NestedContract(nestedAddress); - reentrant = ReentrantContract(reentrantAddress); - } function runTests() public returns (bool) { _runTests(); + } function _runTests() internal { testBasicFunctionality(); testLifecycleValidation(); - - return; - - // XXX Currently calling any external methods in the basic evm test framework causes a revert - // This is unrelated to the transient data code being tested but a factor of the MockRuntime framework - // It also means that we can't currently properly test nested contracts or reentrancy - - // It may be that the next two tests are not compatible with the MockRuntime framework and will need to run in Lotus - - testNestedContracts(); - testReentry(); } // Test 1: Basic Functionality @@ -61,8 +39,6 @@ contract TransientStorageTest { } require(uninitializedValue == 0, "Uninitialized TLOAD did not return zero"); - - //emit TestResult(true, "Basic functionality passed"); } // Test 2.1: Verify transient storage clears after transaction @@ -88,8 +64,6 @@ contract TransientStorageTest { uint256 slot = 3; bool cleared = isStorageCleared(slot); require(cleared, "Transient storage was not cleared after transaction"); - - //emit TestResult(true, "Lifecycle validation passed"); } function isStorageCleared(uint256 slot) public view returns (bool) { @@ -100,47 +74,4 @@ contract TransientStorageTest { return retrievedValue == 0; // True if cleared } - // Test 2.2: Verify nested contract independence - function testNestedContracts() public { - uint256 slot = 4; - uint256 value = 88; - - // Store in this contract's transient storage - assembly { - tstore(slot, value) - } - - // Call nested contract to write its own transient storage - nested.writeTransientData(4, 123); - - // Verify this contract's data is unchanged - uint256 retrievedValue; - assembly { - retrievedValue := tload(slot) - } - require(retrievedValue == value, "Nested contract interfered with this contract's storage"); - - // Verify nested contract's data independently - uint256 nestedValue = nested.readTransientData(4); - require(nestedValue == 123, "Nested contract data incorrect"); - - //emit TestResult(true, "Nested contracts validation passed"); - } - - // Test 2.3: Verify transient storage during reentry - function testReentry() public { - uint256 slot = 5; - uint256 value = 77; - - // Store value in transient storage - assembly { - tstore(slot, value) - } - - // Call reentrant contract - bool success = reentrant.callReentry(slot, value); - - require(success, "Reentry failed"); - //emit TestResult(true, "Reentry validation passed"); - } } diff --git a/actors/evm/tests/contracts/TransientStorageTest_storage.json b/actors/evm/tests/contracts/TransientStorageTest_storage.json index cdae40d25..325d0043f 100644 --- a/actors/evm/tests/contracts/TransientStorageTest_storage.json +++ b/actors/evm/tests/contracts/TransientStorageTest_storage.json @@ -1 +1 @@ -{"storage":[{"astId":12,"contract":"tests/contracts/TransientStorageTest.sol:TransientStorageTest","label":"nested","offset":0,"slot":"0","type":"t_contract(NestedContract)257"},{"astId":15,"contract":"tests/contracts/TransientStorageTest.sol:TransientStorageTest","label":"reentrant","offset":0,"slot":"1","type":"t_contract(ReentrantContract)287"}],"types":{"t_contract(NestedContract)257":{"encoding":"inplace","label":"contract NestedContract","numberOfBytes":"20"},"t_contract(ReentrantContract)287":{"encoding":"inplace","label":"contract ReentrantContract","numberOfBytes":"20"}}} \ No newline at end of file +{"storage":[]} \ No newline at end of file From 89311f9d01d631a626e35fe26c30779531665594 Mon Sep 17 00:00:00 2001 From: Mikers Date: Fri, 6 Dec 2024 17:40:52 -1000 Subject: [PATCH 16/46] support nested and reentry in transient storage in integration tests --- .../tests/contracts/TransientStorageTest.abi | 2 +- .../tests/contracts/TransientStorageTest.bin | 2 +- .../tests/contracts/TransientStorageTest.hex | 2 +- .../contracts/TransientStorageTest.signatures | 5 + .../tests/contracts/TransientStorageTest.sol | 89 +++++++++- integration_tests/src/tests/evm_test.rs | 160 ++++++++++++++++++ test_vm/tests/suite/evm_test.rs | 16 +- 7 files changed, 271 insertions(+), 5 deletions(-) diff --git a/actors/evm/tests/contracts/TransientStorageTest.abi b/actors/evm/tests/contracts/TransientStorageTest.abi index 628597ccd..8cbb6387c 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.abi +++ b/actors/evm/tests/contracts/TransientStorageTest.abi @@ -1 +1 @@ -[{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"runTests","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidationSubsequentTransaction","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"readTransientData","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"reentryCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"runTests","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidationSubsequentTransaction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"other","type":"address"}],"name":"testNestedContracts","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"otherContract","type":"address"}],"name":"testReentry","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"writeTransientData","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.bin b/actors/evm/tests/contracts/TransientStorageTest.bin index 47b789418..f90c7d359 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.bin +++ b/actors/evm/tests/contracts/TransientStorageTest.bin @@ -1 +1 @@ -6080604052348015600e575f5ffd5b5061055c8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610055575f3560e01c806318e1813f1461005957806323d746281461008957806354e84d1b146100a7578063cf83c71c146100b1578063e90bf998146100bb575b5f5ffd5b610073600480360381019061006e9190610280565b6100c5565b60405161008091906102c5565b60405180910390f35b6100916100d6565b60405161009e91906102c5565b60405180910390f35b6100af6100e2565b005b6100b9610137565b005b6100c36101de565b005b5f5f825c90505f8114915050919050565b5f6100df610237565b90565b5f600390505f6100f1826100c5565b905080610133576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012a9061035e565b60405180910390fd5b5050565b5f600190505f602a905080825d5f825c905081811461018b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610182906103ec565b60405180910390fd5b5f600290505f815c90505f81146101d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101ce9061047a565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c9050818114610232576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161022990610508565b60405180910390fd5b505050565b61023f610137565b6102476101de565b565b5f5ffd5b5f819050919050565b61025f8161024d565b8114610269575f5ffd5b50565b5f8135905061027a81610256565b92915050565b5f6020828403121561029557610294610249565b5b5f6102a28482850161026c565b91505092915050565b5f8115159050919050565b6102bf816102ab565b82525050565b5f6020820190506102d85f8301846102b6565b92915050565b5f82825260208201905092915050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f6103486033836102de565b9150610353826102ee565b604082019050919050565b5f6020820190508181035f8301526103758161033c565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6103d66028836102de565b91506103e18261037c565b604082019050919050565b5f6020820190508181035f830152610403816103ca565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f6104646027836102de565b915061046f8261040a565b604082019050919050565b5f6020820190508181035f83015261049181610458565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f6104f26036836102de565b91506104fd82610498565b604082019050919050565b5f6020820190508181035f83015261051f816104e6565b905091905056fea264697066735822122052e3d4e0bfd7d10a14d0926c78bc8f14b137d5262eb40d47e6825bffd82faca964736f6c634300081c0033 \ No newline at end of file +608060405234801561000f575f5ffd5b5061001e61002360201b60201c565b6102fb565b61003161004160201b60201c565b61003f6100e860201b60201c565b565b5f600190505f602a905080825d5f825c9050818114610095576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161008c906101c1565b60405180910390fd5b5f600290505f815c90505f81146100e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100d89061024f565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c905081811461013c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610133906102dd565b60405180910390fd5b505050565b5f82825260208201905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6101ab602883610141565b91506101b682610151565b604082019050919050565b5f6020820190508181035f8301526101d88161019f565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610239602783610141565b9150610244826101df565b604082019050919050565b5f6020820190508181035f8301526102668161022d565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f6102c7603683610141565b91506102d28261026d565b604082019050919050565b5f6020820190508181035f8301526102f4816102bb565b9050919050565b610d0c806103085f395ff3fe608060405234801561000f575f5ffd5b506004361061009c575f3560e01c8063ad5963ca11610064578063ad5963ca14610158578063b279888b14610188578063cf83c71c146101a4578063dec9f688146101ae578063e90bf998146101b85761009c565b806302a5e064146100a057806306c0f8b9146100d057806318e1813f1461010057806323d746281461013057806354e84d1b1461014e575b5f5ffd5b6100ba60048036038101906100b59190610639565b6101c2565b6040516100c79190610673565b60405180910390f35b6100ea60048036038101906100e591906106e6565b6101d1565b6040516100f7919061072b565b60405180910390f35b61011a60048036038101906101159190610639565b610361565b604051610127919061072b565b60405180910390f35b610138610372565b604051610145919061072b565b60405180910390f35b61015661037e565b005b610172600480360381019061016d91906106e6565b6103d3565b60405161017f919061072b565b60405180910390f35b6101a2600480360381019061019d9190610744565b61048f565b005b6101ac610496565b005b6101b661053d565b005b6101c0610597565b005b5f5f825c905080915050919050565b5f5f600490505f605890505f84905081835d8073ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b81526004016102209291906107fd565b5f604051808303815f87803b158015610237575f5ffd5b505af1158015610249573d5f5f3e3d5ffd5b505050505f835c9050828114610294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028b906108a4565b60405180910390fd5b5f8273ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b81526004016102cf91906108c2565b602060405180830381865afa1580156102ea573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030e91906108ef565b9050607b8114610353576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034a90610964565b60405180910390fd5b600195505050505050919050565b5f5f825c90505f8114915050919050565b5f61037b6105f0565b90565b5f600390505f61038d82610361565b9050806103cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103c6906109f2565b60405180910390fd5b5050565b5f5f600590505f607b905080825d8373ffffffffffffffffffffffffffffffffffffffff1663dec9f6886040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610426575f5ffd5b505af1158015610438573d5f5f3e3d5ffd5b505050505f825c9050818114610483576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047a90610a80565b60405180910390fd5b60019350505050919050565b80825d5050565b5f600190505f602a905080825d5f825c90508181146104ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104e190610b0e565b60405180910390fd5b5f600290505f815c90505f8114610536576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052d90610b9c565b60405180910390fd5b5050505050565b5f600690505f6101c8905080825d5f825c9050818114610592576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161058990610c2a565b60405180910390fd5b505050565b5f600390505f6063905080825d5f825c90508181146105eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105e290610cb8565b60405180910390fd5b505050565b6105f8610496565b610600610597565b565b5f5ffd5b5f819050919050565b61061881610606565b8114610622575f5ffd5b50565b5f813590506106338161060f565b92915050565b5f6020828403121561064e5761064d610602565b5b5f61065b84828501610625565b91505092915050565b61066d81610606565b82525050565b5f6020820190506106865f830184610664565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6106b58261068c565b9050919050565b6106c5816106ab565b81146106cf575f5ffd5b50565b5f813590506106e0816106bc565b92915050565b5f602082840312156106fb576106fa610602565b5b5f610708848285016106d2565b91505092915050565b5f8115159050919050565b61072581610711565b82525050565b5f60208201905061073e5f83018461071c565b92915050565b5f5f6040838503121561075a57610759610602565b5b5f61076785828601610625565b925050602061077885828601610625565b9150509250929050565b5f819050919050565b5f819050919050565b5f6107ae6107a96107a484610782565b61078b565b610606565b9050919050565b6107be81610794565b82525050565b5f819050919050565b5f6107e76107e26107dd846107c4565b61078b565b610606565b9050919050565b6107f7816107cd565b82525050565b5f6040820190506108105f8301856107b5565b61081d60208301846107ee565b9392505050565b5f82825260208201905092915050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f61088e603783610824565b915061089982610834565b604082019050919050565b5f6020820190508181035f8301526108bb81610882565b9050919050565b5f6020820190506108d55f8301846107b5565b92915050565b5f815190506108e98161060f565b92915050565b5f6020828403121561090457610903610602565b5b5f610911848285016108db565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f61094e601e83610824565b91506109598261091a565b602082019050919050565b5f6020820190508181035f83015261097b81610942565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f6109dc603383610824565b91506109e782610982565b604082019050919050565b5f6020820190508181035f830152610a09816109d0565b9050919050565b7f5265656e74727920616c7465726564207472616e7369656e742073746f7261675f8201527f6500000000000000000000000000000000000000000000000000000000000000602082015250565b5f610a6a602183610824565b9150610a7582610a10565b604082019050919050565b5f6020820190508181035f830152610a9781610a5e565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f610af8602883610824565b9150610b0382610a9e565b604082019050919050565b5f6020820190508181035f830152610b2581610aec565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610b86602783610824565b9150610b9182610b2c565b604082019050919050565b5f6020820190508181035f830152610bb381610b7a565b9050919050565b7f5265656e7472792063616c6c6261636b206661696c656420746f2073746f72655f8201527f20636f72726563742076616c7565000000000000000000000000000000000000602082015250565b5f610c14602e83610824565b9150610c1f82610bba565b604082019050919050565b5f6020820190508181035f830152610c4181610c08565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610ca2603683610824565b9150610cad82610c48565b604082019050919050565b5f6020820190508181035f830152610ccf81610c96565b905091905056fea264697066735822122095c906ec88537a93b3cb227216e53383f0de67b1ebc5dce9dd036fd303ac8b6e64736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.hex b/actors/evm/tests/contracts/TransientStorageTest.hex index 47b789418..f90c7d359 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.hex +++ b/actors/evm/tests/contracts/TransientStorageTest.hex @@ -1 +1 @@ -6080604052348015600e575f5ffd5b5061055c8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610055575f3560e01c806318e1813f1461005957806323d746281461008957806354e84d1b146100a7578063cf83c71c146100b1578063e90bf998146100bb575b5f5ffd5b610073600480360381019061006e9190610280565b6100c5565b60405161008091906102c5565b60405180910390f35b6100916100d6565b60405161009e91906102c5565b60405180910390f35b6100af6100e2565b005b6100b9610137565b005b6100c36101de565b005b5f5f825c90505f8114915050919050565b5f6100df610237565b90565b5f600390505f6100f1826100c5565b905080610133576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012a9061035e565b60405180910390fd5b5050565b5f600190505f602a905080825d5f825c905081811461018b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610182906103ec565b60405180910390fd5b5f600290505f815c90505f81146101d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101ce9061047a565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c9050818114610232576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161022990610508565b60405180910390fd5b505050565b61023f610137565b6102476101de565b565b5f5ffd5b5f819050919050565b61025f8161024d565b8114610269575f5ffd5b50565b5f8135905061027a81610256565b92915050565b5f6020828403121561029557610294610249565b5b5f6102a28482850161026c565b91505092915050565b5f8115159050919050565b6102bf816102ab565b82525050565b5f6020820190506102d85f8301846102b6565b92915050565b5f82825260208201905092915050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f6103486033836102de565b9150610353826102ee565b604082019050919050565b5f6020820190508181035f8301526103758161033c565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6103d66028836102de565b91506103e18261037c565b604082019050919050565b5f6020820190508181035f830152610403816103ca565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f6104646027836102de565b915061046f8261040a565b604082019050919050565b5f6020820190508181035f83015261049181610458565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f6104f26036836102de565b91506104fd82610498565b604082019050919050565b5f6020820190508181035f83015261051f816104e6565b905091905056fea264697066735822122052e3d4e0bfd7d10a14d0926c78bc8f14b137d5262eb40d47e6825bffd82faca964736f6c634300081c0033 \ No newline at end of file +608060405234801561000f575f5ffd5b5061001e61002360201b60201c565b6102fb565b61003161004160201b60201c565b61003f6100e860201b60201c565b565b5f600190505f602a905080825d5f825c9050818114610095576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161008c906101c1565b60405180910390fd5b5f600290505f815c90505f81146100e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100d89061024f565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c905081811461013c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610133906102dd565b60405180910390fd5b505050565b5f82825260208201905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6101ab602883610141565b91506101b682610151565b604082019050919050565b5f6020820190508181035f8301526101d88161019f565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610239602783610141565b9150610244826101df565b604082019050919050565b5f6020820190508181035f8301526102668161022d565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f6102c7603683610141565b91506102d28261026d565b604082019050919050565b5f6020820190508181035f8301526102f4816102bb565b9050919050565b610d0c806103085f395ff3fe608060405234801561000f575f5ffd5b506004361061009c575f3560e01c8063ad5963ca11610064578063ad5963ca14610158578063b279888b14610188578063cf83c71c146101a4578063dec9f688146101ae578063e90bf998146101b85761009c565b806302a5e064146100a057806306c0f8b9146100d057806318e1813f1461010057806323d746281461013057806354e84d1b1461014e575b5f5ffd5b6100ba60048036038101906100b59190610639565b6101c2565b6040516100c79190610673565b60405180910390f35b6100ea60048036038101906100e591906106e6565b6101d1565b6040516100f7919061072b565b60405180910390f35b61011a60048036038101906101159190610639565b610361565b604051610127919061072b565b60405180910390f35b610138610372565b604051610145919061072b565b60405180910390f35b61015661037e565b005b610172600480360381019061016d91906106e6565b6103d3565b60405161017f919061072b565b60405180910390f35b6101a2600480360381019061019d9190610744565b61048f565b005b6101ac610496565b005b6101b661053d565b005b6101c0610597565b005b5f5f825c905080915050919050565b5f5f600490505f605890505f84905081835d8073ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b81526004016102209291906107fd565b5f604051808303815f87803b158015610237575f5ffd5b505af1158015610249573d5f5f3e3d5ffd5b505050505f835c9050828114610294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028b906108a4565b60405180910390fd5b5f8273ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b81526004016102cf91906108c2565b602060405180830381865afa1580156102ea573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030e91906108ef565b9050607b8114610353576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034a90610964565b60405180910390fd5b600195505050505050919050565b5f5f825c90505f8114915050919050565b5f61037b6105f0565b90565b5f600390505f61038d82610361565b9050806103cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103c6906109f2565b60405180910390fd5b5050565b5f5f600590505f607b905080825d8373ffffffffffffffffffffffffffffffffffffffff1663dec9f6886040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610426575f5ffd5b505af1158015610438573d5f5f3e3d5ffd5b505050505f825c9050818114610483576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047a90610a80565b60405180910390fd5b60019350505050919050565b80825d5050565b5f600190505f602a905080825d5f825c90508181146104ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104e190610b0e565b60405180910390fd5b5f600290505f815c90505f8114610536576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052d90610b9c565b60405180910390fd5b5050505050565b5f600690505f6101c8905080825d5f825c9050818114610592576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161058990610c2a565b60405180910390fd5b505050565b5f600390505f6063905080825d5f825c90508181146105eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105e290610cb8565b60405180910390fd5b505050565b6105f8610496565b610600610597565b565b5f5ffd5b5f819050919050565b61061881610606565b8114610622575f5ffd5b50565b5f813590506106338161060f565b92915050565b5f6020828403121561064e5761064d610602565b5b5f61065b84828501610625565b91505092915050565b61066d81610606565b82525050565b5f6020820190506106865f830184610664565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6106b58261068c565b9050919050565b6106c5816106ab565b81146106cf575f5ffd5b50565b5f813590506106e0816106bc565b92915050565b5f602082840312156106fb576106fa610602565b5b5f610708848285016106d2565b91505092915050565b5f8115159050919050565b61072581610711565b82525050565b5f60208201905061073e5f83018461071c565b92915050565b5f5f6040838503121561075a57610759610602565b5b5f61076785828601610625565b925050602061077885828601610625565b9150509250929050565b5f819050919050565b5f819050919050565b5f6107ae6107a96107a484610782565b61078b565b610606565b9050919050565b6107be81610794565b82525050565b5f819050919050565b5f6107e76107e26107dd846107c4565b61078b565b610606565b9050919050565b6107f7816107cd565b82525050565b5f6040820190506108105f8301856107b5565b61081d60208301846107ee565b9392505050565b5f82825260208201905092915050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f61088e603783610824565b915061089982610834565b604082019050919050565b5f6020820190508181035f8301526108bb81610882565b9050919050565b5f6020820190506108d55f8301846107b5565b92915050565b5f815190506108e98161060f565b92915050565b5f6020828403121561090457610903610602565b5b5f610911848285016108db565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f61094e601e83610824565b91506109598261091a565b602082019050919050565b5f6020820190508181035f83015261097b81610942565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f6109dc603383610824565b91506109e782610982565b604082019050919050565b5f6020820190508181035f830152610a09816109d0565b9050919050565b7f5265656e74727920616c7465726564207472616e7369656e742073746f7261675f8201527f6500000000000000000000000000000000000000000000000000000000000000602082015250565b5f610a6a602183610824565b9150610a7582610a10565b604082019050919050565b5f6020820190508181035f830152610a9781610a5e565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f610af8602883610824565b9150610b0382610a9e565b604082019050919050565b5f6020820190508181035f830152610b2581610aec565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610b86602783610824565b9150610b9182610b2c565b604082019050919050565b5f6020820190508181035f830152610bb381610b7a565b9050919050565b7f5265656e7472792063616c6c6261636b206661696c656420746f2073746f72655f8201527f20636f72726563742076616c7565000000000000000000000000000000000000602082015250565b5f610c14602e83610824565b9150610c1f82610bba565b604082019050919050565b5f6020820190508181035f830152610c4181610c08565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610ca2603683610824565b9150610cad82610c48565b604082019050919050565b5f6020820190508181035f830152610ccf81610c96565b905091905056fea264697066735822122095c906ec88537a93b3cb227216e53383f0de67b1ebc5dce9dd036fd303ac8b6e64736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.signatures b/actors/evm/tests/contracts/TransientStorageTest.signatures index cf07a9d29..d6d85e8e4 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.signatures +++ b/actors/evm/tests/contracts/TransientStorageTest.signatures @@ -1,6 +1,11 @@ Function signatures: 18e1813f: isStorageCleared(uint256) +02a5e064: readTransientData(uint256) +dec9f688: reentryCallback() 23d74628: runTests() cf83c71c: testBasicFunctionality() e90bf998: testLifecycleValidation() 54e84d1b: testLifecycleValidationSubsequentTransaction() +06c0f8b9: testNestedContracts(address) +ad5963ca: testReentry(address) +b279888b: writeTransientData(uint256,uint256) diff --git a/actors/evm/tests/contracts/TransientStorageTest.sol b/actors/evm/tests/contracts/TransientStorageTest.sol index 0ab1133b5..c5f985974 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.sol +++ b/actors/evm/tests/contracts/TransientStorageTest.sol @@ -3,9 +3,12 @@ pragma solidity ^0.8.24; contract TransientStorageTest { - function runTests() public returns (bool) { + constructor(){ _runTests(); + } + function runTests() public returns (bool) { + _runTests(); } function _runTests() internal { @@ -74,4 +77,88 @@ contract TransientStorageTest { return retrievedValue == 0; // True if cleared } + // Test 2.2: Verify nested contract independence + function testNestedContracts(address other) public returns (bool) { + + uint256 slot = 4; + uint256 value = 88; + + TransientStorageTest nested = TransientStorageTest(other); + + // Store in this contract's transient storage + assembly { + tstore(slot, value) + } + + // Call nested contract to write its own transient storage + nested.writeTransientData(4, 123); + + // Verify this contract's data is unchanged + uint256 retrievedValue; + assembly { + retrievedValue := tload(slot) + } + require(retrievedValue == value, "Nested contract interfered with this contract's storage"); + + // Verify nested contract's data independently + uint256 nestedValue = nested.readTransientData(4); + require(nestedValue == 123, "Nested contract data incorrect"); + return true; + } + + // New function to test reentry scenario + function testReentry(address otherContract) public returns (bool){ + uint256 slot = 5; + uint256 value = 123; + + // Store a value in transient storage + assembly { + tstore(slot, value) + } + + // Call the other contract to trigger a callback to this contract + TransientStorageTest(otherContract).reentryCallback(); + + // After reentry, check that the transient storage still has the correct value + uint256 retrievedValue; + assembly { + retrievedValue := tload(slot) + } + + require(retrievedValue == value, "Reentry altered transient storage"); + return true; + } + + function reentryCallback() public { + uint256 slot = 6; + uint256 value = 456; + + // Store a different value in a different slot + assembly { + tstore(slot, value) + } + + // Verify the value was stored correctly + uint256 retrievedValue; + assembly { + retrievedValue := tload(slot) + } + + require(retrievedValue == value, "Reentry callback failed to store correct value"); + } + + function writeTransientData(uint256 slot, uint256 value) external { + assembly { + tstore(slot, value) + } + } + + function readTransientData(uint256 slot) external view returns (uint256) { + uint256 value; + assembly { + value := tload(slot) + } + return value; + } + } diff --git a/integration_tests/src/tests/evm_test.rs b/integration_tests/src/tests/evm_test.rs index 2005d231b..d1181390e 100644 --- a/integration_tests/src/tests/evm_test.rs +++ b/integration_tests/src/tests/evm_test.rs @@ -29,6 +29,7 @@ use crate::TEST_FAUCET_ADDR; abigen!(Recursive, "../actors/evm/tests/contracts/Recursive.abi"); abigen!(Factory, "../actors/evm/tests/contracts/Factory.abi"); abigen!(FactoryChild, "../actors/evm/tests/contracts/FactoryChild.abi"); +abigen!(TransientStorageTest, "../actors/evm/tests/contracts/TransientStorageTest.abi"); pub fn id_to_eth(id: ActorID) -> EthAddress { let mut addr = [0u8; 20]; @@ -753,3 +754,162 @@ pub fn evm_init_revert_data_test(v: &dyn VM) { expected[31] = 0x42; assert_eq!(revert_data, expected); } + +#[allow(non_snake_case)] +#[vm_test] +pub fn evm_transient_nested_test(v: &dyn VM) { + // Step 1: Create an EthAccount with an initial balance. + let account = create_accounts(v, 1, &TokenAmount::from_whole(10_000))[0]; + let address = id_to_eth(account.id().unwrap()); + + // Step 2: Deploy the `TransientStorageTest` contract twice. + let bytecode = + hex::decode(include_str!("../../../actors/evm/tests/contracts/TransientStorageTest.hex")) + .unwrap(); + + let create_contract = |account: &Address| { + let create_result = v + .execute_message( + account, + &EAM_ACTOR_ADDR, + &TokenAmount::zero(), + fil_actor_eam::Method::CreateExternal as u64, + Some(serialize_ok(&fil_actor_eam::CreateExternalParams(bytecode.clone()))), + ) + .unwrap(); + + assert!( + create_result.code.is_success(), + "failed to create the contract {}", + create_result.message + ); + + let create_return: fil_actor_eam::CreateExternalReturn = + create_result.ret.unwrap().deserialize().expect("failed to decode results"); + + create_return.robust_address.unwrap() + }; + + // Deploy two instances of the contract. + let contract_1_addr = create_contract(&account); + let contract_2_addr = create_contract(&account); + + // Step 3: Call `testNestedContracts` on the first contract, passing the address of the second. + let (client, _mock) = Provider::mocked(); + let client = Arc::new(client); + let contract = TransientStorageTest::new(id_to_eth(account.id().unwrap()), client.clone()); + + let nested_contract_id = v.resolve_id_address(&contract_2_addr).unwrap().id().unwrap(); + let nested_contract_address = id_to_eth(nested_contract_id); + + let call_params = contract + .test_nested_contracts(nested_contract_address) + .calldata() + .expect("failed to serialize calldata"); + + let call_result = v + .execute_message( + &account, + &contract_1_addr, + &TokenAmount::zero(), + fil_actor_evm::Method::InvokeContract as u64, + Some(serialize_ok(&ContractParams(call_params.to_vec()))), + ) + .unwrap(); + + // Step 4: Check if the call was successful. + assert!( + call_result.code.is_success(), + "testNestedContracts call failed: {}", + call_result.message + ); + + // Step 5: Deserialize and verify the event emitted by the contract. + let BytesDe(return_value) = + call_result.ret.unwrap().deserialize().expect("failed to deserialize results"); + + let event_emitted: bool = contract + .decode_output( + &contract.test_nested_contracts(nested_contract_address).function.name, + return_value, + ) + .expect("failed to decode return"); + + assert!(event_emitted, "testNestedContracts did not succeed as expected"); +} + +#[allow(non_snake_case)] +#[vm_test] +pub fn evm_transient_reentry_test(v: &dyn VM) { + // Step 1: Create an EthAccount with an initial balance. + let account = create_accounts(v, 1, &TokenAmount::from_whole(10_000))[0]; + let address = id_to_eth(account.id().unwrap()); + + // Step 2: Deploy the `TransientStorageTest` contract twice. + let bytecode = + hex::decode(include_str!("../../../actors/evm/tests/contracts/TransientStorageTest.hex")) + .unwrap(); + + let create_contract = |account: &Address| { + let create_result = v + .execute_message( + account, + &EAM_ACTOR_ADDR, + &TokenAmount::zero(), + fil_actor_eam::Method::CreateExternal as u64, + Some(serialize_ok(&fil_actor_eam::CreateExternalParams(bytecode.clone()))), + ) + .unwrap(); + + assert!( + create_result.code.is_success(), + "failed to create the contract {}", + create_result.message + ); + + let create_return: fil_actor_eam::CreateExternalReturn = + create_result.ret.unwrap().deserialize().expect("failed to decode results"); + + create_return.robust_address.unwrap() + }; + + // Deploy two instances of the contract. + let contract_1_addr = create_contract(&account); + let contract_2_addr = create_contract(&account); + + // Step 3: Call `testReentry` on the first contract, passing the address of the second contract. + let (client, _mock) = Provider::mocked(); + let client = Arc::new(client); + let contract = TransientStorageTest::new(id_to_eth(account.id().unwrap()), client.clone()); + + let nested_contract_id = v.resolve_id_address(&contract_2_addr).unwrap().id().unwrap(); + let nested_contract_address = id_to_eth(nested_contract_id); + + let call_params = contract + .test_reentry(nested_contract_address) + .calldata() + .expect("failed to serialize calldata"); + + let call_result = v + .execute_message( + &account, + &contract_1_addr, + &TokenAmount::zero(), + fil_actor_evm::Method::InvokeContract as u64, + Some(serialize_ok(&ContractParams(call_params.to_vec()))), + ) + .unwrap(); + + // Step 4: Check if the call was successful. + assert!(call_result.code.is_success(), "testReentry call failed: {}", call_result.message); + + // Step 5: Deserialize and verify the return value. + let BytesDe(return_value) = + call_result.ret.unwrap().deserialize().expect("failed to deserialize results"); + + let event_emitted: bool = contract + .decode_output(&contract.test_reentry(nested_contract_address).function.name, return_value) + .expect("failed to decode return"); + + assert!(event_emitted, "testReentry did not succeed as expected"); +} diff --git a/test_vm/tests/suite/evm_test.rs b/test_vm/tests/suite/evm_test.rs index b1094fcd2..6d39e12d9 100644 --- a/test_vm/tests/suite/evm_test.rs +++ b/test_vm/tests/suite/evm_test.rs @@ -1,7 +1,7 @@ use fil_actors_integration_tests::tests::{ evm_call_test, evm_create_test, evm_delegatecall_test, evm_empty_initcode_test, evm_eth_create_external_test, evm_init_revert_data_test, evm_staticcall_delegatecall_test, - evm_staticcall_test, + evm_staticcall_test, evm_transient_nested_test, evm_transient_reentry_test, }; use fil_actors_runtime::test_blockstores::MemoryBlockstore; use test_vm::TestVM; @@ -60,3 +60,17 @@ fn evm_init_revert_data() { let v = TestVM::new_with_singletons(store); evm_init_revert_data_test(&v); } + +#[test] +fn evm_transient_nested() { + let store = MemoryBlockstore::new(); + let v = TestVM::new_with_singletons(store); + evm_transient_nested_test(&v); +} + +#[test] +fn evm_transient_reentry() { + let store = MemoryBlockstore::new(); + let v = TestVM::new_with_singletons(store); + evm_transient_reentry_test(&v); +} From af6bb9925155784a3c04fb745039bc8e49335920 Mon Sep 17 00:00:00 2001 From: Mikers Date: Fri, 6 Dec 2024 18:46:41 -1000 Subject: [PATCH 17/46] progress on fixing removing tranisent storage lifespan from system, but still issues with reload --- .../src/interpreter/instructions/storage.rs | 23 --- actors/evm/src/interpreter/system.rs | 183 +++++++----------- 2 files changed, 67 insertions(+), 139 deletions(-) diff --git a/actors/evm/src/interpreter/instructions/storage.rs b/actors/evm/src/interpreter/instructions/storage.rs index 790558d92..fedfb5c83 100644 --- a/actors/evm/src/interpreter/instructions/storage.rs +++ b/actors/evm/src/interpreter/instructions/storage.rs @@ -153,27 +153,4 @@ mod tests { assert_eq!(m.system.get_transient_storage(U256::from(0)).unwrap(), U256::from(0x42)); }; } - - #[test] - fn test_tstore_clear() { - evm_unit_test! { - (m) { - TSTORE; - } - - m.state.stack.push(U256::from(0x42)).unwrap(); - m.state.stack.push(U256::from(0)).unwrap(); - let result = m.step(); - assert!(result.is_ok(), "execution step failed"); - assert_eq!(m.state.stack.len(), 0); - assert_eq!(m.system.get_transient_storage(U256::from(0)).unwrap(), U256::from(0x42)); - - //clear transient storage - let result = m.system.reset_transient_storage(None); - assert!(result.is_ok(), "Expected Ok, got Err: {:?}", result.err()); - - //confirm getting value at slot 0 returns 0 - assert_eq!(m.system.get_transient_storage(U256::from(0)).unwrap(), U256::from(0)); - }; - } } diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index f95206ed9..ea8dce71d 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -94,7 +94,6 @@ pub struct System<'r, RT: Runtime> { /// The contract's EVM transient storage slots. transient_slots: StateKamt, - transient_data_lifespan: Option, /// The contracts "nonce" (incremented when creating new actors). pub(crate) nonce: u64, @@ -121,7 +120,6 @@ impl<'r, RT: Runtime> System<'r, RT> { rt, slots: StateKamt::new_with_config(store, KAMT_CONFIG.clone()), transient_slots: StateKamt::new_with_config(transient_store, KAMT_CONFIG.clone()), - transient_data_lifespan: None, nonce: 1, saved_state_root: None, bytecode: None, @@ -186,18 +184,30 @@ impl<'r, RT: Runtime> System<'r, RT> { } let read_only = rt.read_only(); + let current_lifespan = Self::get_current_transient_data_lifespan(rt); + + // Handle transient storage based on the presence and lifespan of `transient_data` + let transient_slots = match state.transient_data { + Some(transient_data) if current_lifespan == transient_data.transient_data_lifespan => { + // Lifespans match, load the transient storage + StateKamt::load_with_config( + &transient_data.transient_data_state.unwrap(), + transient_store, + KAMT_CONFIG.clone(), + ) + .context_code(ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore")? + } + _ => { + // Lifespan mismatch or `transient_data` is `None`, initialize an empty transient storage KAMT + StateKamt::new_with_config(transient_store, KAMT_CONFIG.clone()) + } + }; Ok(Self { rt, slots: StateKamt::load_with_config(&state.contract_state, store, KAMT_CONFIG.clone()) .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?, - transient_slots: StateKamt::load_with_config( - &state.transient_data.unwrap().transient_data_state.unwrap(), - transient_store, - KAMT_CONFIG.clone(), - ) - .context_code(ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore")?, - transient_data_lifespan: state.transient_data.unwrap().transient_data_lifespan, + transient_slots, nonce: state.nonce, saved_state_root: Some(state_root), bytecode: Some(EvmBytecode::new(state.bytecode, state.bytecode_hash)), @@ -286,6 +296,18 @@ impl<'r, RT: Runtime> System<'r, RT> { // set empty bytecode hashes None => self.set_bytecode(&[])?, }; + + let transient_data = match self.transient_slots.is_empty() { + true => None, + false => Some(TransientData { + transient_data_state: Some(self.transient_slots.flush().context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to flush transient storage state", + )?), + transient_data_lifespan: Self::get_current_transient_data_lifespan(self.rt), + }), + }; + let new_root = self .rt .store() @@ -297,15 +319,7 @@ impl<'r, RT: Runtime> System<'r, RT> { ExitCode::USR_ILLEGAL_STATE, "failed to flush contract state", )?, - transient_data: { - Some(TransientData { - transient_data_state: Some(self.transient_slots.flush().context_code( - ExitCode::USR_ILLEGAL_STATE, - "failed to flush contract state", - )?), - transient_data_lifespan: self.transient_data_lifespan, - }) - }, + transient_data, nonce: self.nonce, tombstone: self.tombstone, }, @@ -335,14 +349,23 @@ impl<'r, RT: Runtime> System<'r, RT> { .get_cbor(&root) .context_code(ExitCode::USR_SERIALIZATION, "failed to decode state")? .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?; + // + let transient_data_lifespan = state.transient_data.unwrap().transient_data_lifespan; + /* + * TODO compare transient_data_state with current lifespan + */ + let current_lifespan = Self::get_current_transient_data_lifespan(self.rt); + + if current_lifespan == transient_data_lifespan { + self.transient_slots + .set_root(&state.transient_data.unwrap().transient_data_state.unwrap()) + .context_code(ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore")?; + } else { + } self.slots .set_root(&state.contract_state) .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?; - self.transient_slots - .set_root(&state.transient_data.unwrap().transient_data_state.unwrap()) - .context_code(ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore")?; - self.transient_data_lifespan = state.transient_data.unwrap().transient_data_lifespan; self.nonce = state.nonce; self.saved_state_root = Some(root); self.bytecode = Some(EvmBytecode::new(state.bytecode, state.bytecode_hash)); @@ -415,10 +438,10 @@ impl<'r, RT: Runtime> System<'r, RT> { } /// Returns the current transient data lifespan based on the execution environment. - pub fn get_current_transient_data_lifespan(&self) -> Option { - match self.rt.message().origin().id() { + pub fn get_current_transient_data_lifespan(rt: &RT) -> Option { + match rt.message().origin().id() { Ok(origin_id) => { - Some(TransientDataLifespan { origin: origin_id, nonce: self.rt.message().nonce() }) + Some(TransientDataLifespan { origin: origin_id, nonce: rt.message().nonce() }) } Err(_) => None, // Handle the error case by returning None } @@ -426,104 +449,32 @@ impl<'r, RT: Runtime> System<'r, RT> { /// Get value of a transient storage key. pub fn get_transient_storage(&mut self, key: U256) -> Result { - if self.transient_data_lifespan == self.get_current_transient_data_lifespan() { - // Lifespan matches, retrieve value - Ok(self - .transient_slots - .get(&key) - .context_code( - ExitCode::USR_ILLEGAL_STATE, - "failed to access transient storage slot", - )? - .cloned() - .unwrap_or_default()) - } else { - // Lifespan mismatch, return default value - Ok(U256::zero()) - } + // Lifespan matches, retrieve value + Ok(self + .transient_slots + .get(&key) + .context_code(ExitCode::USR_ILLEGAL_STATE, "failed to access transient storage slot")? + .cloned() + .unwrap_or_default()) } /// Set value of a transient storage key. pub fn set_transient_storage(&mut self, key: U256, value: U256) -> Result<(), ActorError> { - let current_lifespan = self.get_current_transient_data_lifespan(); - - if self.transient_data_lifespan == current_lifespan { - // Lifespan matches, proceed to set value - let changed = if value.is_zero() { - self.transient_slots.delete(&key).map(|v| v.is_some()).context_code( - ExitCode::USR_ILLEGAL_STATE, - "failed to clear transient storage slot", - )? - } else { - self.transient_slots.set(key, value).map(|v| v != Some(value)).context_code( - ExitCode::USR_ILLEGAL_STATE, - "failed to update transient storage slot", - )? - }; - - if changed { - self.saved_state_root = None; // Mark state as dirty - } + // Lifespan matches, proceed to set value + let changed = if value.is_zero() { + self.transient_slots.delete(&key).map(|v| v.is_some()).context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to clear transient storage slot", + )? } else { - // Lifespan mismatch - if value.is_zero() { - // If setting to default value, skip storage reset - return Ok(()); - } - - // Reset transient storage and update lifespan - self.reset_transient_storage(current_lifespan)?; - self.transient_slots.set(key, value).context_code( + self.transient_slots.set(key, value).map(|v| v != Some(value)).context_code( ExitCode::USR_ILLEGAL_STATE, - "failed to set transient storage after reset", - )?; - } - - Ok(()) - } - - /// Reset transient storage and update lifespan. - pub fn reset_transient_storage( - &mut self, - new_lifespan: Option, - ) -> Result<(), ActorError> { - // Update lifespan - self.transient_data_lifespan = new_lifespan; - - // Delete all keys from transient storage - self.clear_transient_slots()?; - - // Mark state as dirty - self.saved_state_root = None; - - Ok(()) - } + "failed to update transient storage slot", + )? + }; - /// Clears all entries in `transient_slots`. - /// This is not ideal because it is iterating over each key - /// TODO create a PR for the KAMT library to support a "clear" method - /// and upgrade to the new KAMT library version once its updated - fn clear_transient_slots(&mut self) -> Result<(), ActorError> { - let mut keys_to_delete = Vec::new(); - - // Use `for_each` to collect all keys - self.transient_slots - .for_each(|key, _| { - keys_to_delete.push(*key); - Ok(()) - }) - .map_err( - |err| actor_error!(illegal_state; "iterating over transient_slots failed: {}", err), - )?; - - for key in keys_to_delete { - self.transient_slots.delete(&key).map_err(|err| { - actor_error!( - illegal_state; - "deleting key {key:?} from transient_slots failed: {}", - err - ) - })?; + if changed { + self.saved_state_root = None; // Mark state as dirty } Ok(()) From d93167bd309b3b0e9688af3b3c719a0065a60789 Mon Sep 17 00:00:00 2001 From: Mikers Date: Fri, 6 Dec 2024 19:13:03 -1000 Subject: [PATCH 18/46] use clear instead of loop and delete --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- actors/evm/src/interpreter/system.rs | 23 +---------------------- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index adc049bc9..3edc5ef53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2271,9 +2271,9 @@ dependencies = [ [[package]] name = "fvm_ipld_kamt" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02250be2140aa2e805e18b9427dc93fa1ad9753c8169d0807389f31739683450" +checksum = "270444092b6cb62319b5a8f1ca6ae21265d31e0c818019e9ebd63cf8b2d51cb5" dependencies = [ "anyhow", "byteorder", diff --git a/Cargo.toml b/Cargo.toml index 14a4f6768..91a4f32d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -137,7 +137,7 @@ fvm_shared = "4.5.1" fvm_ipld_encoding = "0.5.0" fvm_ipld_blockstore = "0.3.0" fvm_ipld_hamt = "0.10.2" -fvm_ipld_kamt = "0.4.2" +fvm_ipld_kamt = "0.4.3" fvm_ipld_amt = { version = "0.7.3" } fvm_ipld_bitfield = "0.7.0" diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index fd57c338f..fd1d9c453 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -504,28 +504,7 @@ impl<'r, RT: Runtime> System<'r, RT> { /// TODO create a PR for the KAMT library to support a "clear" method /// and upgrade to the new KAMT library version once its updated fn clear_transient_slots(&mut self) -> Result<(), ActorError> { - let mut keys_to_delete = Vec::new(); - - // Use `for_each` to collect all keys - self.transient_slots - .for_each(|key, _| { - keys_to_delete.push(*key); - Ok(()) - }) - .map_err( - |err| actor_error!(illegal_state; "iterating over transient_slots failed: {}", err), - )?; - - for key in keys_to_delete { - self.transient_slots.delete(&key).map_err(|err| { - actor_error!( - illegal_state; - "deleting key {key:?} from transient_slots failed: {}", - err - ) - })?; - } - + self.transient_slots.clear(); Ok(()) } From 250d133e0948d18e388283b9fed34ee60ad692c7 Mon Sep 17 00:00:00 2001 From: Mikers Date: Fri, 6 Dec 2024 23:26:12 -1000 Subject: [PATCH 19/46] use kamt clear in reload --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- actors/evm/src/interpreter/system.rs | 7 ++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index adc049bc9..3edc5ef53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2271,9 +2271,9 @@ dependencies = [ [[package]] name = "fvm_ipld_kamt" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02250be2140aa2e805e18b9427dc93fa1ad9753c8169d0807389f31739683450" +checksum = "270444092b6cb62319b5a8f1ca6ae21265d31e0c818019e9ebd63cf8b2d51cb5" dependencies = [ "anyhow", "byteorder", diff --git a/Cargo.toml b/Cargo.toml index 14a4f6768..91a4f32d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -137,7 +137,7 @@ fvm_shared = "4.5.1" fvm_ipld_encoding = "0.5.0" fvm_ipld_blockstore = "0.3.0" fvm_ipld_hamt = "0.10.2" -fvm_ipld_kamt = "0.4.2" +fvm_ipld_kamt = "0.4.3" fvm_ipld_amt = { version = "0.7.3" } fvm_ipld_bitfield = "0.7.0" diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 4c6e67417..13f03dd52 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -349,18 +349,15 @@ impl<'r, RT: Runtime> System<'r, RT> { .get_cbor(&root) .context_code(ExitCode::USR_SERIALIZATION, "failed to decode state")? .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?; - // + let transient_data_lifespan = state.transient_data.unwrap().transient_data_lifespan; - /* - * TODO compare transient_data_state with current lifespan - */ let current_lifespan = Self::get_current_transient_data_lifespan(self.rt); - if current_lifespan == transient_data_lifespan { self.transient_slots .set_root(&state.transient_data.unwrap().transient_data_state.unwrap()) .context_code(ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore")?; } else { + self.transient_slots.clear(); } self.slots From e614a36e6c722e69b19fd47ae30885a680ad1fce Mon Sep 17 00:00:00 2001 From: Mikers Date: Sat, 7 Dec 2024 00:15:31 -1000 Subject: [PATCH 20/46] unused var --- integration_tests/src/tests/evm_test.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration_tests/src/tests/evm_test.rs b/integration_tests/src/tests/evm_test.rs index d1181390e..b3b61a7b5 100644 --- a/integration_tests/src/tests/evm_test.rs +++ b/integration_tests/src/tests/evm_test.rs @@ -760,7 +760,6 @@ pub fn evm_init_revert_data_test(v: &dyn VM) { pub fn evm_transient_nested_test(v: &dyn VM) { // Step 1: Create an EthAccount with an initial balance. let account = create_accounts(v, 1, &TokenAmount::from_whole(10_000))[0]; - let address = id_to_eth(account.id().unwrap()); // Step 2: Deploy the `TransientStorageTest` contract twice. let bytecode = @@ -843,7 +842,6 @@ pub fn evm_transient_nested_test(v: &dyn VM) { pub fn evm_transient_reentry_test(v: &dyn VM) { // Step 1: Create an EthAccount with an initial balance. let account = create_accounts(v, 1, &TokenAmount::from_whole(10_000))[0]; - let address = id_to_eth(account.id().unwrap()); // Step 2: Deploy the `TransientStorageTest` contract twice. let bytecode = From 978b49d1e0f1e50fbecf020cadcfb1b5b8c4275a Mon Sep 17 00:00:00 2001 From: Mikers Date: Mon, 9 Dec 2024 14:30:15 -1000 Subject: [PATCH 21/46] remove Options from transient data in state and handle None better to avoid panics --- actors/evm/src/interpreter/system.rs | 43 +++++++++++++++++----------- actors/evm/src/state.rs | 4 +-- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 13f03dd52..cc3e27f80 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -187,11 +187,13 @@ impl<'r, RT: Runtime> System<'r, RT> { let current_lifespan = Self::get_current_transient_data_lifespan(rt); // Handle transient storage based on the presence and lifespan of `transient_data` - let transient_slots = match state.transient_data { - Some(transient_data) if current_lifespan == transient_data.transient_data_lifespan => { + let transient_slots = match (current_lifespan, state.transient_data) { + (Some(current_lifespan), Some(transient_data)) + if current_lifespan == transient_data.transient_data_lifespan => + { // Lifespans match, load the transient storage StateKamt::load_with_config( - &transient_data.transient_data_state.unwrap(), + &transient_data.transient_data_state, transient_store, KAMT_CONFIG.clone(), ) @@ -299,13 +301,16 @@ impl<'r, RT: Runtime> System<'r, RT> { let transient_data = match self.transient_slots.is_empty() { true => None, - false => Some(TransientData { - transient_data_state: Some(self.transient_slots.flush().context_code( - ExitCode::USR_ILLEGAL_STATE, - "failed to flush transient storage state", - )?), - transient_data_lifespan: Self::get_current_transient_data_lifespan(self.rt), - }), + false => match Self::get_current_transient_data_lifespan(self.rt) { + Some(lifespan_value) => Some(TransientData { + transient_data_state: self.transient_slots.flush().context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to flush transient storage state", + )?, + transient_data_lifespan: lifespan_value, + }), + None => None, + }, }; let new_root = self @@ -350,12 +355,18 @@ impl<'r, RT: Runtime> System<'r, RT> { .context_code(ExitCode::USR_SERIALIZATION, "failed to decode state")? .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?; - let transient_data_lifespan = state.transient_data.unwrap().transient_data_lifespan; - let current_lifespan = Self::get_current_transient_data_lifespan(self.rt); - if current_lifespan == transient_data_lifespan { - self.transient_slots - .set_root(&state.transient_data.unwrap().transient_data_state.unwrap()) - .context_code(ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore")?; + if let Some(transient_data) = state.transient_data { + let transient_data_lifespan = transient_data.transient_data_lifespan; + let current_lifespan = Self::get_current_transient_data_lifespan(self.rt); + + if current_lifespan == Some(transient_data_lifespan) { + self.transient_slots.set_root(&transient_data.transient_data_state).context_code( + ExitCode::USR_ILLEGAL_STATE, + "transient_state not in blockstore", + )?; + } else { + self.transient_slots.clear(); + } } else { self.transient_slots.clear(); } diff --git a/actors/evm/src/state.rs b/actors/evm/src/state.rs index aa77aecdc..52d0bfb1e 100644 --- a/actors/evm/src/state.rs +++ b/actors/evm/src/state.rs @@ -23,9 +23,9 @@ pub struct TransientData { /// The contract transient data state dictionary. /// Transient Data State is a map of U256 -> U256 values. /// KAMT - pub transient_data_state: Option, + pub transient_data_state: Cid, /// The data representing the transient data lifespan - pub transient_data_lifespan: Option, + pub transient_data_lifespan: TransientDataLifespan, } /// A structure representing the transient data lifespan. From a47c21e36338f087a92762a8bb3cc48acc2b8e99 Mon Sep 17 00:00:00 2001 From: Mikers Date: Mon, 9 Dec 2024 14:53:02 -1000 Subject: [PATCH 22/46] add current_transient_data_lifespan to state and refactor get_current_transient_data_lifespan to be a free function --- actors/evm/src/interpreter/system.rs | 36 +++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index cc3e27f80..65c56ec73 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -94,6 +94,7 @@ pub struct System<'r, RT: Runtime> { /// The contract's EVM transient storage slots. transient_slots: StateKamt, + current_transient_data_lifespan: Option, /// The contracts "nonce" (incremented when creating new actors). pub(crate) nonce: u64, @@ -116,10 +117,12 @@ impl<'r, RT: Runtime> System<'r, RT> { { let store = rt.store().clone(); let transient_store = rt.store().clone(); + let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); Self { rt, slots: StateKamt::new_with_config(store, KAMT_CONFIG.clone()), transient_slots: StateKamt::new_with_config(transient_store, KAMT_CONFIG.clone()), + current_transient_data_lifespan, nonce: 1, saved_state_root: None, bytecode: None, @@ -184,10 +187,10 @@ impl<'r, RT: Runtime> System<'r, RT> { } let read_only = rt.read_only(); - let current_lifespan = Self::get_current_transient_data_lifespan(rt); + let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); // Handle transient storage based on the presence and lifespan of `transient_data` - let transient_slots = match (current_lifespan, state.transient_data) { + let transient_slots = match (current_transient_data_lifespan, state.transient_data) { (Some(current_lifespan), Some(transient_data)) if current_lifespan == transient_data.transient_data_lifespan => { @@ -210,6 +213,7 @@ impl<'r, RT: Runtime> System<'r, RT> { slots: StateKamt::load_with_config(&state.contract_state, store, KAMT_CONFIG.clone()) .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?, transient_slots, + current_transient_data_lifespan: current_transient_data_lifespan, nonce: state.nonce, saved_state_root: Some(state_root), bytecode: Some(EvmBytecode::new(state.bytecode, state.bytecode_hash)), @@ -301,7 +305,7 @@ impl<'r, RT: Runtime> System<'r, RT> { let transient_data = match self.transient_slots.is_empty() { true => None, - false => match Self::get_current_transient_data_lifespan(self.rt) { + false => match self.current_transient_data_lifespan { Some(lifespan_value) => Some(TransientData { transient_data_state: self.transient_slots.flush().context_code( ExitCode::USR_ILLEGAL_STATE, @@ -356,10 +360,10 @@ impl<'r, RT: Runtime> System<'r, RT> { .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?; if let Some(transient_data) = state.transient_data { - let transient_data_lifespan = transient_data.transient_data_lifespan; - let current_lifespan = Self::get_current_transient_data_lifespan(self.rt); + let state_transient_data_lifespan = transient_data.transient_data_lifespan; + let current_transient_data_lifespan = get_current_transient_data_lifespan(self.rt); - if current_lifespan == Some(transient_data_lifespan) { + if current_transient_data_lifespan == Some(state_transient_data_lifespan) { self.transient_slots.set_root(&transient_data.transient_data_state).context_code( ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore", @@ -445,16 +449,6 @@ impl<'r, RT: Runtime> System<'r, RT> { Ok(()) } - /// Returns the current transient data lifespan based on the execution environment. - pub fn get_current_transient_data_lifespan(rt: &RT) -> Option { - match rt.message().origin().id() { - Ok(origin_id) => { - Some(TransientDataLifespan { origin: origin_id, nonce: rt.message().nonce() }) - } - Err(_) => None, // Handle the error case by returning None - } - } - /// Get value of a transient storage key. pub fn get_transient_storage(&mut self, key: U256) -> Result { // Lifespan matches, retrieve value @@ -549,3 +543,13 @@ impl<'r, RT: Runtime> System<'r, RT> { self.tombstone = Some(crate::current_tombstone(self.rt)); } } + +/// Returns the current transient data lifespan based on the execution environment. +pub fn get_current_transient_data_lifespan(rt: &RT) -> Option { + match rt.message().origin().id() { + Ok(origin_id) => { + Some(TransientDataLifespan { origin: origin_id, nonce: rt.message().nonce() }) + } + Err(_) => None, + } +} From e26e5198eb21d96f008186d69e114180bf5bc795 Mon Sep 17 00:00:00 2001 From: Mikers Date: Mon, 9 Dec 2024 15:00:47 -1000 Subject: [PATCH 23/46] fmt --- actors/evm/src/interpreter/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 65c56ec73..a58e49936 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -213,7 +213,7 @@ impl<'r, RT: Runtime> System<'r, RT> { slots: StateKamt::load_with_config(&state.contract_state, store, KAMT_CONFIG.clone()) .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?, transient_slots, - current_transient_data_lifespan: current_transient_data_lifespan, + current_transient_data_lifespan, nonce: state.nonce, saved_state_root: Some(state_root), bytecode: Some(EvmBytecode::new(state.bytecode, state.bytecode_hash)), From 4feec0fba90337dc6cffaa24837a801fe5032efc Mon Sep 17 00:00:00 2001 From: Mikers Date: Mon, 9 Dec 2024 17:11:00 -1000 Subject: [PATCH 24/46] set in call to true because transient data calls message() which has that assertion --- actors/evm/src/interpreter/precompiles/evm.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/actors/evm/src/interpreter/precompiles/evm.rs b/actors/evm/src/interpreter/precompiles/evm.rs index c38d9f1e3..717eb88c8 100644 --- a/actors/evm/src/interpreter/precompiles/evm.rs +++ b/actors/evm/src/interpreter/precompiles/evm.rs @@ -314,6 +314,8 @@ mod tests { #[test] fn bn_recover() { let rt = MockRuntime::default(); + rt.in_call.replace(true); + let mut system = System::create(&rt).unwrap(); let input = &hex!( @@ -357,6 +359,8 @@ mod tests { let input = "foo bar baz boxy".as_bytes(); let rt = MockRuntime::default(); + rt.in_call.replace(true); + let mut system = System::create(&rt).unwrap(); let expected = hex!("ace8597929092c14bd028ede7b07727875788c7e130278b5afed41940d965aba"); @@ -370,6 +374,8 @@ mod tests { let input = "foo bar baz boxy".as_bytes(); let rt = MockRuntime::default(); + rt.in_call.replace(true); + let mut system = System::create(&rt).unwrap(); let expected = hex!("0000000000000000000000004cd7a0452bd3d682e4cbd5fa90f446d7285b156a"); @@ -389,6 +395,8 @@ mod tests { ); let rt = MockRuntime::default(); + rt.in_call.replace(true); + let mut system = System::create(&rt).unwrap(); let expected = hex!("08"); @@ -450,6 +458,8 @@ mod tests { #[test] fn bn_add() { let rt = MockRuntime::default(); + rt.in_call.replace(true); + let mut system = System::create(&rt).unwrap(); let input = hex::decode( @@ -519,6 +529,8 @@ mod tests { ]; let rt = MockRuntime::default(); + rt.in_call.replace(true); + let mut system = System::create(&rt).unwrap(); for (f, name) in tests { @@ -546,6 +558,8 @@ mod tests { &[(blake2f, "fail-blake2f")]; let rt = MockRuntime::default(); + rt.in_call.replace(true); + let mut system = System::create(&rt).unwrap(); for (f, name) in failures { @@ -561,6 +575,8 @@ mod tests { #[test] fn bn_mul() { let rt = MockRuntime::default(); + rt.in_call.replace(true); + let mut system = System::create(&rt).unwrap(); let input = hex::decode( @@ -614,6 +630,8 @@ mod tests { #[test] fn bn_pair() { let rt = MockRuntime::default(); + rt.in_call.replace(true); + let mut system = System::create(&rt).unwrap(); let input = hex::decode( @@ -701,6 +719,8 @@ mod tests { fn blake2() { use super::blake2f; let rt = MockRuntime::default(); + rt.in_call.replace(true); + let mut system = System::create(&rt).unwrap(); // // helper to turn EIP test cases into something readable From 3d5deba2a526d07fa26ab0eb5ed3ff3a3c9fd62e Mon Sep 17 00:00:00 2001 From: Mikers Date: Mon, 9 Dec 2024 17:59:39 -1000 Subject: [PATCH 25/46] Update actors/evm/src/interpreter/system.rs Co-authored-by: Steven Allen --- actors/evm/src/interpreter/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index a58e49936..c3bc9ce41 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -94,7 +94,7 @@ pub struct System<'r, RT: Runtime> { /// The contract's EVM transient storage slots. transient_slots: StateKamt, - current_transient_data_lifespan: Option, + current_transient_data_lifespan: TransientDataLifespan, /// The contracts "nonce" (incremented when creating new actors). pub(crate) nonce: u64, From 22963df86bc7bcf1aa5ce1832230ab8161062c7f Mon Sep 17 00:00:00 2001 From: Mikers Date: Mon, 9 Dec 2024 18:26:15 -1000 Subject: [PATCH 26/46] Revert "Update actors/evm/src/interpreter/system.rs" This reverts commit 3d5deba2a526d07fa26ab0eb5ed3ff3a3c9fd62e. --- actors/evm/src/interpreter/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index c3bc9ce41..a58e49936 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -94,7 +94,7 @@ pub struct System<'r, RT: Runtime> { /// The contract's EVM transient storage slots. transient_slots: StateKamt, - current_transient_data_lifespan: TransientDataLifespan, + current_transient_data_lifespan: Option, /// The contracts "nonce" (incremented when creating new actors). pub(crate) nonce: u64, From 41c41def88905361578133f741ede44b171ac3a5 Mon Sep 17 00:00:00 2001 From: Mikers Date: Wed, 11 Dec 2024 12:21:31 -1000 Subject: [PATCH 27/46] Revert "Revert "Update actors/evm/src/interpreter/system.rs"" This reverts commit 22963df86bc7bcf1aa5ce1832230ab8161062c7f. --- actors/evm/src/interpreter/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index a58e49936..c3bc9ce41 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -94,7 +94,7 @@ pub struct System<'r, RT: Runtime> { /// The contract's EVM transient storage slots. transient_slots: StateKamt, - current_transient_data_lifespan: Option, + current_transient_data_lifespan: TransientDataLifespan, /// The contracts "nonce" (incremented when creating new actors). pub(crate) nonce: u64, From 837a003ab61a92338afec75245dc35b0b84593d7 Mon Sep 17 00:00:00 2001 From: Mikers Date: Wed, 11 Dec 2024 13:26:49 -1000 Subject: [PATCH 28/46] get get_current_transient_data_lifespan throw an error if it cannot form a valid object --- actors/evm/src/interpreter/system.rs | 57 +++++++++++++------------ actors/evm/src/interpreter/test_util.rs | 4 +- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index c3bc9ce41..ff9a2f92f 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -111,14 +111,14 @@ pub struct System<'r, RT: Runtime> { } impl<'r, RT: Runtime> System<'r, RT> { - pub(crate) fn new(rt: &'r RT, readonly: bool) -> Self + pub(crate) fn new(rt: &'r RT, readonly: bool) -> Result where RT::Blockstore: Clone, { let store = rt.store().clone(); let transient_store = rt.store().clone(); - let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); - Self { + let current_transient_data_lifespan = get_current_transient_data_lifespan(rt)?; + Ok(Self { rt, slots: StateKamt::new_with_config(store, KAMT_CONFIG.clone()), transient_slots: StateKamt::new_with_config(transient_store, KAMT_CONFIG.clone()), @@ -129,7 +129,7 @@ impl<'r, RT: Runtime> System<'r, RT> { readonly, randomness: None, tombstone: None, - } + }) } /// Resurrect the contract. This will return a new empty contract if, and only if, the contract @@ -150,7 +150,7 @@ impl<'r, RT: Runtime> System<'r, RT> { return Err(actor_error!(forbidden, "can only resurrect a dead contract")); } - return Ok(Self::new(rt, read_only)); + return Self::new(rt, read_only); } /// Create the contract. This will return a new empty contract if, and only if, the contract @@ -164,7 +164,7 @@ impl<'r, RT: Runtime> System<'r, RT> { if state_root != EMPTY_ARR_CID { return Err(actor_error!(illegal_state, "can't create over an existing actor")); } - return Ok(Self::new(rt, read_only)); + return Self::new(rt, read_only); } /// Load the actor from state. @@ -183,16 +183,17 @@ impl<'r, RT: Runtime> System<'r, RT> { if crate::is_dead(rt, &state) { // If we're "dead", return an empty read-only contract. The code will be empty, so // nothing can happen anyways. - return Ok(Self::new(rt, true)); + return Self::new(rt, true); } let read_only = rt.read_only(); - let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); + let current_transient_data_lifespan = get_current_transient_data_lifespan(rt)?; // Handle transient storage based on the presence and lifespan of `transient_data` - let transient_slots = match (current_transient_data_lifespan, state.transient_data) { - (Some(current_lifespan), Some(transient_data)) - if current_lifespan == transient_data.transient_data_lifespan => + // Handle transient storage based on the presence and lifespan of `transient_data` + let transient_slots = match state.transient_data { + Some(transient_data) + if current_transient_data_lifespan == transient_data.transient_data_lifespan => { // Lifespans match, load the transient storage StateKamt::load_with_config( @@ -303,18 +304,16 @@ impl<'r, RT: Runtime> System<'r, RT> { None => self.set_bytecode(&[])?, }; - let transient_data = match self.transient_slots.is_empty() { - true => None, - false => match self.current_transient_data_lifespan { - Some(lifespan_value) => Some(TransientData { - transient_data_state: self.transient_slots.flush().context_code( - ExitCode::USR_ILLEGAL_STATE, - "failed to flush transient storage state", - )?, - transient_data_lifespan: lifespan_value, - }), - None => None, - }, + let transient_data = if self.transient_slots.is_empty() { + None + } else { + Some(TransientData { + transient_data_state: self.transient_slots.flush().context_code( + ExitCode::USR_ILLEGAL_STATE, + "failed to flush transient storage state", + )?, + transient_data_lifespan: self.current_transient_data_lifespan, + }) }; let new_root = self @@ -361,9 +360,9 @@ impl<'r, RT: Runtime> System<'r, RT> { if let Some(transient_data) = state.transient_data { let state_transient_data_lifespan = transient_data.transient_data_lifespan; - let current_transient_data_lifespan = get_current_transient_data_lifespan(self.rt); + let current_transient_data_lifespan = get_current_transient_data_lifespan(self.rt)?; - if current_transient_data_lifespan == Some(state_transient_data_lifespan) { + if current_transient_data_lifespan == state_transient_data_lifespan { self.transient_slots.set_root(&transient_data.transient_data_state).context_code( ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore", @@ -545,11 +544,13 @@ impl<'r, RT: Runtime> System<'r, RT> { } /// Returns the current transient data lifespan based on the execution environment. -pub fn get_current_transient_data_lifespan(rt: &RT) -> Option { +pub fn get_current_transient_data_lifespan( + rt: &RT, +) -> Result { match rt.message().origin().id() { Ok(origin_id) => { - Some(TransientDataLifespan { origin: origin_id, nonce: rt.message().nonce() }) + Ok(TransientDataLifespan { origin: origin_id, nonce: rt.message().nonce() }) } - Err(_) => None, + Err(_) => Err(actor_error!(illegal_state, "failed to get current transient data lifespan")), } } diff --git a/actors/evm/src/interpreter/test_util.rs b/actors/evm/src/interpreter/test_util.rs index 3ec2a4750..f17406925 100644 --- a/actors/evm/src/interpreter/test_util.rs +++ b/actors/evm/src/interpreter/test_util.rs @@ -33,7 +33,7 @@ macro_rules! evm_unit_test { let code = vec![$($crate::evm_instruction!($inst)),*]; - let mut system = System::new(&$rt, false); + let mut system = System::new(&$rt, false).expect("Failed to initialize System"); let bytecode = Bytecode::new(code); #[allow(unused_mut)] let mut $machine = Machine { @@ -64,7 +64,7 @@ macro_rules! evm_unit_test { let code = vec![$($crate::evm_instruction!($inst)),*]; - let mut system = System::new(&rt, false); + let mut system = System::new(&rt, false).expect("Failed to initialize System"); let bytecode = Bytecode::new(code); #[allow(unused_mut)] let mut $machine = Machine { From 3c6d9a7d96e43f5c5fbff8fd8143c3277f443dac Mon Sep 17 00:00:00 2001 From: Mikers Date: Wed, 11 Dec 2024 15:50:51 -1000 Subject: [PATCH 29/46] change transient data origin from id to Address --- actors/evm/src/interpreter/system.rs | 17 +++++------------ actors/evm/src/state.rs | 3 ++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index ff9a2f92f..2a2fbc570 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -117,7 +117,7 @@ impl<'r, RT: Runtime> System<'r, RT> { { let store = rt.store().clone(); let transient_store = rt.store().clone(); - let current_transient_data_lifespan = get_current_transient_data_lifespan(rt)?; + let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); Ok(Self { rt, slots: StateKamt::new_with_config(store, KAMT_CONFIG.clone()), @@ -187,7 +187,7 @@ impl<'r, RT: Runtime> System<'r, RT> { } let read_only = rt.read_only(); - let current_transient_data_lifespan = get_current_transient_data_lifespan(rt)?; + let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); // Handle transient storage based on the presence and lifespan of `transient_data` // Handle transient storage based on the presence and lifespan of `transient_data` @@ -360,7 +360,7 @@ impl<'r, RT: Runtime> System<'r, RT> { if let Some(transient_data) = state.transient_data { let state_transient_data_lifespan = transient_data.transient_data_lifespan; - let current_transient_data_lifespan = get_current_transient_data_lifespan(self.rt)?; + let current_transient_data_lifespan = get_current_transient_data_lifespan(self.rt); if current_transient_data_lifespan == state_transient_data_lifespan { self.transient_slots.set_root(&transient_data.transient_data_state).context_code( @@ -544,13 +544,6 @@ impl<'r, RT: Runtime> System<'r, RT> { } /// Returns the current transient data lifespan based on the execution environment. -pub fn get_current_transient_data_lifespan( - rt: &RT, -) -> Result { - match rt.message().origin().id() { - Ok(origin_id) => { - Ok(TransientDataLifespan { origin: origin_id, nonce: rt.message().nonce() }) - } - Err(_) => Err(actor_error!(illegal_state, "failed to get current transient data lifespan")), - } +pub fn get_current_transient_data_lifespan(rt: &RT) -> TransientDataLifespan { + TransientDataLifespan { origin: rt.message().origin(), nonce: rt.message().nonce() } } diff --git a/actors/evm/src/state.rs b/actors/evm/src/state.rs index 52d0bfb1e..13709d967 100644 --- a/actors/evm/src/state.rs +++ b/actors/evm/src/state.rs @@ -1,6 +1,7 @@ use std::array::TryFromSliceError; use fil_actors_evm_shared::uints::U256; +use fvm_shared::address::Address; use fvm_shared::ActorID; use cid::Cid; @@ -32,7 +33,7 @@ pub struct TransientData { #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize_tuple, Deserialize_tuple)] pub struct TransientDataLifespan { /// The origin actor ID associated with the transient data. - pub origin: ActorID, + pub origin: Address, /// A unique nonce identifying the transaction. pub nonce: u64, } From 037939aae6db470d3d9b18c3623a001ce0172977 Mon Sep 17 00:00:00 2001 From: Mikers Date: Wed, 11 Dec 2024 21:44:59 -1000 Subject: [PATCH 30/46] Revert "change transient data origin from id to Address" This reverts commit 3c6d9a7d96e43f5c5fbff8fd8143c3277f443dac. --- actors/evm/src/interpreter/system.rs | 17 ++++++++++++----- actors/evm/src/state.rs | 3 +-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 2a2fbc570..ff9a2f92f 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -117,7 +117,7 @@ impl<'r, RT: Runtime> System<'r, RT> { { let store = rt.store().clone(); let transient_store = rt.store().clone(); - let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); + let current_transient_data_lifespan = get_current_transient_data_lifespan(rt)?; Ok(Self { rt, slots: StateKamt::new_with_config(store, KAMT_CONFIG.clone()), @@ -187,7 +187,7 @@ impl<'r, RT: Runtime> System<'r, RT> { } let read_only = rt.read_only(); - let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); + let current_transient_data_lifespan = get_current_transient_data_lifespan(rt)?; // Handle transient storage based on the presence and lifespan of `transient_data` // Handle transient storage based on the presence and lifespan of `transient_data` @@ -360,7 +360,7 @@ impl<'r, RT: Runtime> System<'r, RT> { if let Some(transient_data) = state.transient_data { let state_transient_data_lifespan = transient_data.transient_data_lifespan; - let current_transient_data_lifespan = get_current_transient_data_lifespan(self.rt); + let current_transient_data_lifespan = get_current_transient_data_lifespan(self.rt)?; if current_transient_data_lifespan == state_transient_data_lifespan { self.transient_slots.set_root(&transient_data.transient_data_state).context_code( @@ -544,6 +544,13 @@ impl<'r, RT: Runtime> System<'r, RT> { } /// Returns the current transient data lifespan based on the execution environment. -pub fn get_current_transient_data_lifespan(rt: &RT) -> TransientDataLifespan { - TransientDataLifespan { origin: rt.message().origin(), nonce: rt.message().nonce() } +pub fn get_current_transient_data_lifespan( + rt: &RT, +) -> Result { + match rt.message().origin().id() { + Ok(origin_id) => { + Ok(TransientDataLifespan { origin: origin_id, nonce: rt.message().nonce() }) + } + Err(_) => Err(actor_error!(illegal_state, "failed to get current transient data lifespan")), + } } diff --git a/actors/evm/src/state.rs b/actors/evm/src/state.rs index 13709d967..52d0bfb1e 100644 --- a/actors/evm/src/state.rs +++ b/actors/evm/src/state.rs @@ -1,7 +1,6 @@ use std::array::TryFromSliceError; use fil_actors_evm_shared::uints::U256; -use fvm_shared::address::Address; use fvm_shared::ActorID; use cid::Cid; @@ -33,7 +32,7 @@ pub struct TransientData { #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize_tuple, Deserialize_tuple)] pub struct TransientDataLifespan { /// The origin actor ID associated with the transient data. - pub origin: Address, + pub origin: ActorID, /// A unique nonce identifying the transaction. pub nonce: u64, } From dddf19c820ff27b6877b28ba157bfc7e480d361f Mon Sep 17 00:00:00 2001 From: Mikers Date: Wed, 11 Dec 2024 21:45:52 -1000 Subject: [PATCH 31/46] remove test: origin is always an ID address --- .../src/interpreter/instructions/context.rs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/actors/evm/src/interpreter/instructions/context.rs b/actors/evm/src/interpreter/instructions/context.rs index 5f201ee9f..255aff4d7 100644 --- a/actors/evm/src/interpreter/instructions/context.rs +++ b/actors/evm/src/interpreter/instructions/context.rs @@ -364,25 +364,6 @@ mod tests { }; } - #[test] - fn test_origin_ethaddr() { - let addr_bytes = hex_literal::hex!("FEEDFACECAFEBEEF000000000000000000001234"); - let eth_addr = EthAddress(addr_bytes); - let fil_addr = FilAddress::new_delegated(EAM_ACTOR_ID, &addr_bytes).unwrap(); - evm_unit_test! { - (rt) { - rt.in_call.replace(true); - rt.set_origin(fil_addr); - } - (m) { - ORIGIN; - } - m.step().expect("execution step failed"); - assert_eq!(m.state.stack.len(), 1); - assert_eq!(m.state.stack.pop().unwrap(), eth_addr.as_evm_word()); - }; - } - #[test] fn test_caller() { evm_unit_test! { From 074e16fda1177c5a8512ee409f347820392cd844 Mon Sep 17 00:00:00 2001 From: Mikers Date: Wed, 11 Dec 2024 21:56:33 -1000 Subject: [PATCH 32/46] remove unused import --- actors/evm/src/interpreter/instructions/context.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/actors/evm/src/interpreter/instructions/context.rs b/actors/evm/src/interpreter/instructions/context.rs index 255aff4d7..cfe2fb30c 100644 --- a/actors/evm/src/interpreter/instructions/context.rs +++ b/actors/evm/src/interpreter/instructions/context.rs @@ -153,7 +153,6 @@ mod tests { use cid::multihash::Multihash; use cid::Cid; use fil_actors_evm_shared::uints::U256; - use fil_actors_runtime::EAM_ACTOR_ID; use fvm_ipld_encoding::{DAG_CBOR, IPLD_RAW}; use fvm_shared::address::Address as FilAddress; From fb8025da4b3fbd341dcfbeeac7a644ab8e554c66 Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 16:49:40 -1000 Subject: [PATCH 33/46] remove duplicate comment --- actors/evm/src/interpreter/system.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index ff9a2f92f..a17e4f4e3 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -189,7 +189,6 @@ impl<'r, RT: Runtime> System<'r, RT> { let read_only = rt.read_only(); let current_transient_data_lifespan = get_current_transient_data_lifespan(rt)?; - // Handle transient storage based on the presence and lifespan of `transient_data` // Handle transient storage based on the presence and lifespan of `transient_data` let transient_slots = match state.transient_data { Some(transient_data) From 2c8febfc4d61171401cae749e37784a2475be354 Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 16:51:54 -1000 Subject: [PATCH 34/46] use self.current_transient_data_lifespan --- actors/evm/src/interpreter/system.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index a17e4f4e3..351ddec81 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -359,9 +359,7 @@ impl<'r, RT: Runtime> System<'r, RT> { if let Some(transient_data) = state.transient_data { let state_transient_data_lifespan = transient_data.transient_data_lifespan; - let current_transient_data_lifespan = get_current_transient_data_lifespan(self.rt)?; - - if current_transient_data_lifespan == state_transient_data_lifespan { + if self.current_transient_data_lifespan == state_transient_data_lifespan { self.transient_slots.set_root(&transient_data.transient_data_state).context_code( ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore", From f1ac7791a8afd6a77bb4416487f2a46ff3f5d38b Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 16:59:03 -1000 Subject: [PATCH 35/46] get_current_transient_data_lifespan does not need to be public --- actors/evm/src/interpreter/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 351ddec81..6afa824ea 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -541,7 +541,7 @@ impl<'r, RT: Runtime> System<'r, RT> { } /// Returns the current transient data lifespan based on the execution environment. -pub fn get_current_transient_data_lifespan( +fn get_current_transient_data_lifespan( rt: &RT, ) -> Result { match rt.message().origin().id() { From 7c6ba378b261f3292e780a31afbc6efa4de96026 Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 17:05:06 -1000 Subject: [PATCH 36/46] remove match from get_current_transient_data_lifespan and use an unwrap because we have already validated the existance of an id --- actors/evm/src/interpreter/system.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index 6afa824ea..a352eb88e 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -117,7 +117,7 @@ impl<'r, RT: Runtime> System<'r, RT> { { let store = rt.store().clone(); let transient_store = rt.store().clone(); - let current_transient_data_lifespan = get_current_transient_data_lifespan(rt)?; + let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); Ok(Self { rt, slots: StateKamt::new_with_config(store, KAMT_CONFIG.clone()), @@ -187,7 +187,7 @@ impl<'r, RT: Runtime> System<'r, RT> { } let read_only = rt.read_only(); - let current_transient_data_lifespan = get_current_transient_data_lifespan(rt)?; + let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); // Handle transient storage based on the presence and lifespan of `transient_data` let transient_slots = match state.transient_data { @@ -543,11 +543,8 @@ impl<'r, RT: Runtime> System<'r, RT> { /// Returns the current transient data lifespan based on the execution environment. fn get_current_transient_data_lifespan( rt: &RT, -) -> Result { - match rt.message().origin().id() { - Ok(origin_id) => { - Ok(TransientDataLifespan { origin: origin_id, nonce: rt.message().nonce() }) - } - Err(_) => Err(actor_error!(illegal_state, "failed to get current transient data lifespan")), - } -} +) -> TransientDataLifespan { + TransientDataLifespan { + origin: rt.message().origin().id().unwrap(), + nonce: rt.message().nonce(), + }} From a005cf77207622637117d497d1f688c14cfb261b Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 17:11:37 -1000 Subject: [PATCH 37/46] remove error case from new --- actors/evm/src/interpreter/system.rs | 19 +++++++++---------- actors/evm/src/interpreter/test_util.rs | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index a352eb88e..ec1c29e01 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -111,14 +111,14 @@ pub struct System<'r, RT: Runtime> { } impl<'r, RT: Runtime> System<'r, RT> { - pub(crate) fn new(rt: &'r RT, readonly: bool) -> Result + pub(crate) fn new(rt: &'r RT, readonly: bool) -> Self where RT::Blockstore: Clone, { let store = rt.store().clone(); let transient_store = rt.store().clone(); let current_transient_data_lifespan = get_current_transient_data_lifespan(rt); - Ok(Self { + Self { rt, slots: StateKamt::new_with_config(store, KAMT_CONFIG.clone()), transient_slots: StateKamt::new_with_config(transient_store, KAMT_CONFIG.clone()), @@ -129,7 +129,7 @@ impl<'r, RT: Runtime> System<'r, RT> { readonly, randomness: None, tombstone: None, - }) + } } /// Resurrect the contract. This will return a new empty contract if, and only if, the contract @@ -150,7 +150,7 @@ impl<'r, RT: Runtime> System<'r, RT> { return Err(actor_error!(forbidden, "can only resurrect a dead contract")); } - return Self::new(rt, read_only); + return Ok(Self::new(rt, read_only)); } /// Create the contract. This will return a new empty contract if, and only if, the contract @@ -164,7 +164,7 @@ impl<'r, RT: Runtime> System<'r, RT> { if state_root != EMPTY_ARR_CID { return Err(actor_error!(illegal_state, "can't create over an existing actor")); } - return Self::new(rt, read_only); + return Ok(Self::new(rt, read_only)); } /// Load the actor from state. @@ -183,7 +183,7 @@ impl<'r, RT: Runtime> System<'r, RT> { if crate::is_dead(rt, &state) { // If we're "dead", return an empty read-only contract. The code will be empty, so // nothing can happen anyways. - return Self::new(rt, true); + return Ok(Self::new(rt, true)); } let read_only = rt.read_only(); @@ -541,10 +541,9 @@ impl<'r, RT: Runtime> System<'r, RT> { } /// Returns the current transient data lifespan based on the execution environment. -fn get_current_transient_data_lifespan( - rt: &RT, -) -> TransientDataLifespan { +fn get_current_transient_data_lifespan(rt: &RT) -> TransientDataLifespan { TransientDataLifespan { origin: rt.message().origin().id().unwrap(), nonce: rt.message().nonce(), - }} + } +} diff --git a/actors/evm/src/interpreter/test_util.rs b/actors/evm/src/interpreter/test_util.rs index f17406925..3ec2a4750 100644 --- a/actors/evm/src/interpreter/test_util.rs +++ b/actors/evm/src/interpreter/test_util.rs @@ -33,7 +33,7 @@ macro_rules! evm_unit_test { let code = vec![$($crate::evm_instruction!($inst)),*]; - let mut system = System::new(&$rt, false).expect("Failed to initialize System"); + let mut system = System::new(&$rt, false); let bytecode = Bytecode::new(code); #[allow(unused_mut)] let mut $machine = Machine { @@ -64,7 +64,7 @@ macro_rules! evm_unit_test { let code = vec![$($crate::evm_instruction!($inst)),*]; - let mut system = System::new(&rt, false).expect("Failed to initialize System"); + let mut system = System::new(&rt, false); let bytecode = Bytecode::new(code); #[allow(unused_mut)] let mut $machine = Machine { From 8eed0c9a11df2ace3d3a81110da1be8d28f8387f Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 17:14:42 -1000 Subject: [PATCH 38/46] remove allow non snake case from transient storage tests --- integration_tests/src/tests/evm_test.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration_tests/src/tests/evm_test.rs b/integration_tests/src/tests/evm_test.rs index b3b61a7b5..1106e5479 100644 --- a/integration_tests/src/tests/evm_test.rs +++ b/integration_tests/src/tests/evm_test.rs @@ -755,7 +755,6 @@ pub fn evm_init_revert_data_test(v: &dyn VM) { assert_eq!(revert_data, expected); } -#[allow(non_snake_case)] #[vm_test] pub fn evm_transient_nested_test(v: &dyn VM) { // Step 1: Create an EthAccount with an initial balance. @@ -837,7 +836,6 @@ pub fn evm_transient_nested_test(v: &dyn VM) { assert!(event_emitted, "testNestedContracts did not succeed as expected"); } -#[allow(non_snake_case)] #[vm_test] pub fn evm_transient_reentry_test(v: &dyn VM) { // Step 1: Create an EthAccount with an initial balance. From 133f7b58ff5184e522090f478b81c7c09d24e671 Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 19:48:04 -1000 Subject: [PATCH 39/46] Update actors/evm/src/interpreter/system.rs Co-authored-by: Steven Allen --- actors/evm/src/interpreter/system.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/actors/evm/src/interpreter/system.rs b/actors/evm/src/interpreter/system.rs index ec1c29e01..a646369c2 100644 --- a/actors/evm/src/interpreter/system.rs +++ b/actors/evm/src/interpreter/system.rs @@ -357,18 +357,16 @@ impl<'r, RT: Runtime> System<'r, RT> { .context_code(ExitCode::USR_SERIALIZATION, "failed to decode state")? .context_code(ExitCode::USR_ILLEGAL_STATE, "state not in blockstore")?; - if let Some(transient_data) = state.transient_data { - let state_transient_data_lifespan = transient_data.transient_data_lifespan; - if self.current_transient_data_lifespan == state_transient_data_lifespan { - self.transient_slots.set_root(&transient_data.transient_data_state).context_code( + match &state.transient_data { + Some(TransientData { transient_data_state, transient_data_lifespan }) + if transient_data_lifespan == &self.current_transient_data_lifespan => + { + self.transient_slots.set_root(transient_data_state).context_code( ExitCode::USR_ILLEGAL_STATE, "transient_state not in blockstore", - )?; - } else { - self.transient_slots.clear(); + )? } - } else { - self.transient_slots.clear(); + _ => self.transient_slots.clear(), } self.slots From 1b57940606ce644b5f578a1d5afabd09f3d232c8 Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 22:03:16 -1000 Subject: [PATCH 40/46] Update actors/evm/tests/basic.rs Co-authored-by: Rod Vagg --- actors/evm/tests/basic.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actors/evm/tests/basic.rs b/actors/evm/tests/basic.rs index 7f527d68a..f70e3c0b5 100644 --- a/actors/evm/tests/basic.rs +++ b/actors/evm/tests/basic.rs @@ -228,8 +228,8 @@ fn transient_storage_test(transient_storage_bytecode: Vec) { // We expect this to fail because no changes are made util::invoke_contract_expect_fail(&rt, &solidity_params_test_cleared); - //use a new address for our calling context - //This will cause the transient storage data to reset because the transient storage lifecycle value has changed + // use a new address for our calling context; this will cause the transient storage + // data to reset because the transient storage lifecycle value has changed let new_context = Address::new_id(200); rt.set_origin(new_context); From 685fd63efbfe38554e6b4403518d628805ca0640 Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 22:05:27 -1000 Subject: [PATCH 41/46] Update actors/evm/tests/contracts/TransientStorageTest.sol Co-authored-by: Rod Vagg --- actors/evm/tests/contracts/TransientStorageTest.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/evm/tests/contracts/TransientStorageTest.sol b/actors/evm/tests/contracts/TransientStorageTest.sol index c5f985974..75349e901 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.sol +++ b/actors/evm/tests/contracts/TransientStorageTest.sol @@ -106,7 +106,7 @@ contract TransientStorageTest { return true; } - // New function to test reentry scenario + // New function to test reentry scenario function testReentry(address otherContract) public returns (bool){ uint256 slot = 5; uint256 value = 123; From ff09cfa7a63338d0f9d5ba301c25cb829310f893 Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 22:05:37 -1000 Subject: [PATCH 42/46] Update actors/evm/tests/contracts/TransientStorageTest.sol Co-authored-by: Rod Vagg --- actors/evm/tests/contracts/TransientStorageTest.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/actors/evm/tests/contracts/TransientStorageTest.sol b/actors/evm/tests/contracts/TransientStorageTest.sol index 75349e901..f6a6dd6a5 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.sol +++ b/actors/evm/tests/contracts/TransientStorageTest.sol @@ -79,7 +79,6 @@ contract TransientStorageTest { // Test 2.2: Verify nested contract independence function testNestedContracts(address other) public returns (bool) { - uint256 slot = 4; uint256 value = 88; From b96dbe5b62784ed800f8d6736633dc3ac4c29032 Mon Sep 17 00:00:00 2001 From: Mikers Date: Thu, 12 Dec 2024 22:05:50 -1000 Subject: [PATCH 43/46] Update actors/evm/tests/contracts/TransientStorageTest.sol Co-authored-by: Rod Vagg --- actors/evm/tests/contracts/TransientStorageTest.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/evm/tests/contracts/TransientStorageTest.sol b/actors/evm/tests/contracts/TransientStorageTest.sol index f6a6dd6a5..8541a9644 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.sol +++ b/actors/evm/tests/contracts/TransientStorageTest.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.24; contract TransientStorageTest { constructor(){ - _runTests(); + _runTests(); } function runTests() public returns (bool) { From b7ac7bad6c59b3c2de40710cda5ecde0f2747002 Mon Sep 17 00:00:00 2001 From: Mikers Date: Fri, 13 Dec 2024 14:29:45 -1000 Subject: [PATCH 44/46] remove now unused solidity test contracts that have previously been refactored into TransientStorageTest --- actors/evm/tests/contracts/NestedContract.abi | 1 - actors/evm/tests/contracts/NestedContract.bin | 1 - actors/evm/tests/contracts/NestedContract.hex | 1 - .../tests/contracts/NestedContract.signatures | 3 --- actors/evm/tests/contracts/NestedContract.sol | 18 ----------------- .../contracts/NestedContract_storage.json | 1 - .../evm/tests/contracts/ReentrantContract.abi | 1 - .../evm/tests/contracts/ReentrantContract.bin | 1 - .../evm/tests/contracts/ReentrantContract.hex | 1 - .../contracts/ReentrantContract.signatures | 5 ----- .../evm/tests/contracts/ReentrantContract.sol | 20 ------------------- .../contracts/ReentrantContract_storage.json | 1 - 12 files changed, 54 deletions(-) delete mode 100644 actors/evm/tests/contracts/NestedContract.abi delete mode 100644 actors/evm/tests/contracts/NestedContract.bin delete mode 100644 actors/evm/tests/contracts/NestedContract.hex delete mode 100644 actors/evm/tests/contracts/NestedContract.signatures delete mode 100644 actors/evm/tests/contracts/NestedContract.sol delete mode 100644 actors/evm/tests/contracts/NestedContract_storage.json delete mode 100644 actors/evm/tests/contracts/ReentrantContract.abi delete mode 100644 actors/evm/tests/contracts/ReentrantContract.bin delete mode 100644 actors/evm/tests/contracts/ReentrantContract.hex delete mode 100644 actors/evm/tests/contracts/ReentrantContract.signatures delete mode 100644 actors/evm/tests/contracts/ReentrantContract.sol delete mode 100644 actors/evm/tests/contracts/ReentrantContract_storage.json diff --git a/actors/evm/tests/contracts/NestedContract.abi b/actors/evm/tests/contracts/NestedContract.abi deleted file mode 100644 index 7fc3a8a06..000000000 --- a/actors/evm/tests/contracts/NestedContract.abi +++ /dev/null @@ -1 +0,0 @@ -[{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"readTransientData","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"writeTransientData","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/actors/evm/tests/contracts/NestedContract.bin b/actors/evm/tests/contracts/NestedContract.bin deleted file mode 100644 index ef302979c..000000000 --- a/actors/evm/tests/contracts/NestedContract.bin +++ /dev/null @@ -1 +0,0 @@ -6080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea264697066735822122022a3efe83f7aff51061bf54c745bd6c6faa7241f45c690093b50304bf5ae7f8564736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/NestedContract.hex b/actors/evm/tests/contracts/NestedContract.hex deleted file mode 100644 index ef302979c..000000000 --- a/actors/evm/tests/contracts/NestedContract.hex +++ /dev/null @@ -1 +0,0 @@ -6080604052348015600e575f5ffd5b506101988061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c806302a5e06414610038578063b279888b14610068575b5f5ffd5b610052600480360381019061004d91906100d1565b610084565b60405161005f919061010b565b60405180910390f35b610082600480360381019061007d9190610124565b610093565b005b5f5f825c905080915050919050565b80825d5050565b5f5ffd5b5f819050919050565b6100b08161009e565b81146100ba575f5ffd5b50565b5f813590506100cb816100a7565b92915050565b5f602082840312156100e6576100e561009a565b5b5f6100f3848285016100bd565b91505092915050565b6101058161009e565b82525050565b5f60208201905061011e5f8301846100fc565b92915050565b5f5f6040838503121561013a5761013961009a565b5b5f610147858286016100bd565b9250506020610158858286016100bd565b915050925092905056fea264697066735822122022a3efe83f7aff51061bf54c745bd6c6faa7241f45c690093b50304bf5ae7f8564736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/NestedContract.signatures b/actors/evm/tests/contracts/NestedContract.signatures deleted file mode 100644 index e263c6b39..000000000 --- a/actors/evm/tests/contracts/NestedContract.signatures +++ /dev/null @@ -1,3 +0,0 @@ -Function signatures: -02a5e064: readTransientData(uint256) -b279888b: writeTransientData(uint256,uint256) diff --git a/actors/evm/tests/contracts/NestedContract.sol b/actors/evm/tests/contracts/NestedContract.sol deleted file mode 100644 index 3ab066d4d..000000000 --- a/actors/evm/tests/contracts/NestedContract.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -contract NestedContract { - function writeTransientData(uint256 slot, uint256 value) external { - assembly { - tstore(slot, value) - } - } - - function readTransientData(uint256 slot) external view returns (uint256) { - uint256 value; - assembly { - value := tload(slot) - } - return value; - } -} diff --git a/actors/evm/tests/contracts/NestedContract_storage.json b/actors/evm/tests/contracts/NestedContract_storage.json deleted file mode 100644 index 325d0043f..000000000 --- a/actors/evm/tests/contracts/NestedContract_storage.json +++ /dev/null @@ -1 +0,0 @@ -{"storage":[]} \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.abi b/actors/evm/tests/contracts/ReentrantContract.abi deleted file mode 100644 index 6f552a64a..000000000 --- a/actors/evm/tests/contracts/ReentrantContract.abi +++ /dev/null @@ -1 +0,0 @@ -[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"success","type":"bool"}],"name":"ReentrySuccess","type":"event"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"},{"internalType":"uint256","name":"expectedValue","type":"uint256"}],"name":"callReentry","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.bin b/actors/evm/tests/contracts/ReentrantContract.bin deleted file mode 100644 index dc074cae3..000000000 --- a/actors/evm/tests/contracts/ReentrantContract.bin +++ /dev/null @@ -1 +0,0 @@ -6080604052348015600e575f5ffd5b506102068061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b610047600480360381019061004291906100e7565b61005d565b604051610054919061013f565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101b2565b60405180910390fd5b600191505092915050565b5f5ffd5b5f819050919050565b6100c6816100b4565b81146100d0575f5ffd5b50565b5f813590506100e1816100bd565b92915050565b5f5f604083850312156100fd576100fc6100b0565b5b5f61010a858286016100d3565b925050602061011b858286016100d3565b9150509250929050565b5f8115159050919050565b61013981610125565b82525050565b5f6020820190506101525f830184610130565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f61019c601883610158565b91506101a782610168565b602082019050919050565b5f6020820190508181035f8301526101c981610190565b905091905056fea2646970667358221220fdf471a84a6318ce450d9a366e4db4df8fd229bc05a0474ed51db62d3713620064736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.hex b/actors/evm/tests/contracts/ReentrantContract.hex deleted file mode 100644 index dc074cae3..000000000 --- a/actors/evm/tests/contracts/ReentrantContract.hex +++ /dev/null @@ -1 +0,0 @@ -6080604052348015600e575f5ffd5b506102068061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b610047600480360381019061004291906100e7565b61005d565b604051610054919061013f565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101b2565b60405180910390fd5b600191505092915050565b5f5ffd5b5f819050919050565b6100c6816100b4565b81146100d0575f5ffd5b50565b5f813590506100e1816100bd565b92915050565b5f5f604083850312156100fd576100fc6100b0565b5b5f61010a858286016100d3565b925050602061011b858286016100d3565b9150509250929050565b5f8115159050919050565b61013981610125565b82525050565b5f6020820190506101525f830184610130565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f61019c601883610158565b91506101a782610168565b602082019050919050565b5f6020820190508181035f8301526101c981610190565b905091905056fea2646970667358221220fdf471a84a6318ce450d9a366e4db4df8fd229bc05a0474ed51db62d3713620064736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/ReentrantContract.signatures b/actors/evm/tests/contracts/ReentrantContract.signatures deleted file mode 100644 index 87741e20c..000000000 --- a/actors/evm/tests/contracts/ReentrantContract.signatures +++ /dev/null @@ -1,5 +0,0 @@ -Function signatures: -d52aa447: callReentry(uint256,uint256) - -Event signatures: -df046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a: ReentrySuccess(bool) diff --git a/actors/evm/tests/contracts/ReentrantContract.sol b/actors/evm/tests/contracts/ReentrantContract.sol deleted file mode 100644 index 3e2adcb56..000000000 --- a/actors/evm/tests/contracts/ReentrantContract.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -contract ReentrantContract { - event ReentrySuccess(bool success); - - function callReentry(uint256 slot, uint256 expectedValue) external returns (bool) { - /* - * TODO - * Actually test for reentry - * */ - - uint256 storedValue; - assembly { - storedValue := tload(slot) - } - require(storedValue == expectedValue, "Reentrant value mismatch"); - return true; - } -} diff --git a/actors/evm/tests/contracts/ReentrantContract_storage.json b/actors/evm/tests/contracts/ReentrantContract_storage.json deleted file mode 100644 index 325d0043f..000000000 --- a/actors/evm/tests/contracts/ReentrantContract_storage.json +++ /dev/null @@ -1 +0,0 @@ -{"storage":[]} \ No newline at end of file From 260f4018268da3ede2a89f57eab77e646540474c Mon Sep 17 00:00:00 2001 From: Mikers Date: Fri, 13 Dec 2024 14:34:33 -1000 Subject: [PATCH 45/46] forge fmt and solc recompile --- actors/evm/tests/contracts/TransientStorageTest.bin | 2 +- actors/evm/tests/contracts/TransientStorageTest.hex | 2 +- actors/evm/tests/contracts/TransientStorageTest.sol | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/actors/evm/tests/contracts/TransientStorageTest.bin b/actors/evm/tests/contracts/TransientStorageTest.bin index f90c7d359..0908ffdda 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.bin +++ b/actors/evm/tests/contracts/TransientStorageTest.bin @@ -1 +1 @@ -608060405234801561000f575f5ffd5b5061001e61002360201b60201c565b6102fb565b61003161004160201b60201c565b61003f6100e860201b60201c565b565b5f600190505f602a905080825d5f825c9050818114610095576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161008c906101c1565b60405180910390fd5b5f600290505f815c90505f81146100e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100d89061024f565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c905081811461013c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610133906102dd565b60405180910390fd5b505050565b5f82825260208201905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6101ab602883610141565b91506101b682610151565b604082019050919050565b5f6020820190508181035f8301526101d88161019f565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610239602783610141565b9150610244826101df565b604082019050919050565b5f6020820190508181035f8301526102668161022d565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f6102c7603683610141565b91506102d28261026d565b604082019050919050565b5f6020820190508181035f8301526102f4816102bb565b9050919050565b610d0c806103085f395ff3fe608060405234801561000f575f5ffd5b506004361061009c575f3560e01c8063ad5963ca11610064578063ad5963ca14610158578063b279888b14610188578063cf83c71c146101a4578063dec9f688146101ae578063e90bf998146101b85761009c565b806302a5e064146100a057806306c0f8b9146100d057806318e1813f1461010057806323d746281461013057806354e84d1b1461014e575b5f5ffd5b6100ba60048036038101906100b59190610639565b6101c2565b6040516100c79190610673565b60405180910390f35b6100ea60048036038101906100e591906106e6565b6101d1565b6040516100f7919061072b565b60405180910390f35b61011a60048036038101906101159190610639565b610361565b604051610127919061072b565b60405180910390f35b610138610372565b604051610145919061072b565b60405180910390f35b61015661037e565b005b610172600480360381019061016d91906106e6565b6103d3565b60405161017f919061072b565b60405180910390f35b6101a2600480360381019061019d9190610744565b61048f565b005b6101ac610496565b005b6101b661053d565b005b6101c0610597565b005b5f5f825c905080915050919050565b5f5f600490505f605890505f84905081835d8073ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b81526004016102209291906107fd565b5f604051808303815f87803b158015610237575f5ffd5b505af1158015610249573d5f5f3e3d5ffd5b505050505f835c9050828114610294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028b906108a4565b60405180910390fd5b5f8273ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b81526004016102cf91906108c2565b602060405180830381865afa1580156102ea573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030e91906108ef565b9050607b8114610353576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034a90610964565b60405180910390fd5b600195505050505050919050565b5f5f825c90505f8114915050919050565b5f61037b6105f0565b90565b5f600390505f61038d82610361565b9050806103cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103c6906109f2565b60405180910390fd5b5050565b5f5f600590505f607b905080825d8373ffffffffffffffffffffffffffffffffffffffff1663dec9f6886040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610426575f5ffd5b505af1158015610438573d5f5f3e3d5ffd5b505050505f825c9050818114610483576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047a90610a80565b60405180910390fd5b60019350505050919050565b80825d5050565b5f600190505f602a905080825d5f825c90508181146104ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104e190610b0e565b60405180910390fd5b5f600290505f815c90505f8114610536576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052d90610b9c565b60405180910390fd5b5050505050565b5f600690505f6101c8905080825d5f825c9050818114610592576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161058990610c2a565b60405180910390fd5b505050565b5f600390505f6063905080825d5f825c90508181146105eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105e290610cb8565b60405180910390fd5b505050565b6105f8610496565b610600610597565b565b5f5ffd5b5f819050919050565b61061881610606565b8114610622575f5ffd5b50565b5f813590506106338161060f565b92915050565b5f6020828403121561064e5761064d610602565b5b5f61065b84828501610625565b91505092915050565b61066d81610606565b82525050565b5f6020820190506106865f830184610664565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6106b58261068c565b9050919050565b6106c5816106ab565b81146106cf575f5ffd5b50565b5f813590506106e0816106bc565b92915050565b5f602082840312156106fb576106fa610602565b5b5f610708848285016106d2565b91505092915050565b5f8115159050919050565b61072581610711565b82525050565b5f60208201905061073e5f83018461071c565b92915050565b5f5f6040838503121561075a57610759610602565b5b5f61076785828601610625565b925050602061077885828601610625565b9150509250929050565b5f819050919050565b5f819050919050565b5f6107ae6107a96107a484610782565b61078b565b610606565b9050919050565b6107be81610794565b82525050565b5f819050919050565b5f6107e76107e26107dd846107c4565b61078b565b610606565b9050919050565b6107f7816107cd565b82525050565b5f6040820190506108105f8301856107b5565b61081d60208301846107ee565b9392505050565b5f82825260208201905092915050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f61088e603783610824565b915061089982610834565b604082019050919050565b5f6020820190508181035f8301526108bb81610882565b9050919050565b5f6020820190506108d55f8301846107b5565b92915050565b5f815190506108e98161060f565b92915050565b5f6020828403121561090457610903610602565b5b5f610911848285016108db565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f61094e601e83610824565b91506109598261091a565b602082019050919050565b5f6020820190508181035f83015261097b81610942565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f6109dc603383610824565b91506109e782610982565b604082019050919050565b5f6020820190508181035f830152610a09816109d0565b9050919050565b7f5265656e74727920616c7465726564207472616e7369656e742073746f7261675f8201527f6500000000000000000000000000000000000000000000000000000000000000602082015250565b5f610a6a602183610824565b9150610a7582610a10565b604082019050919050565b5f6020820190508181035f830152610a9781610a5e565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f610af8602883610824565b9150610b0382610a9e565b604082019050919050565b5f6020820190508181035f830152610b2581610aec565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610b86602783610824565b9150610b9182610b2c565b604082019050919050565b5f6020820190508181035f830152610bb381610b7a565b9050919050565b7f5265656e7472792063616c6c6261636b206661696c656420746f2073746f72655f8201527f20636f72726563742076616c7565000000000000000000000000000000000000602082015250565b5f610c14602e83610824565b9150610c1f82610bba565b604082019050919050565b5f6020820190508181035f830152610c4181610c08565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610ca2603683610824565b9150610cad82610c48565b604082019050919050565b5f6020820190508181035f830152610ccf81610c96565b905091905056fea264697066735822122095c906ec88537a93b3cb227216e53383f0de67b1ebc5dce9dd036fd303ac8b6e64736f6c634300081c0033 \ No newline at end of file +608060405234801561000f575f5ffd5b5061001e61002360201b60201c565b6102fb565b61003161004160201b60201c565b61003f6100e860201b60201c565b565b5f600190505f602a905080825d5f825c9050818114610095576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161008c906101c1565b60405180910390fd5b5f600290505f815c90505f81146100e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100d89061024f565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c905081811461013c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610133906102dd565b60405180910390fd5b505050565b5f82825260208201905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6101ab602883610141565b91506101b682610151565b604082019050919050565b5f6020820190508181035f8301526101d88161019f565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610239602783610141565b9150610244826101df565b604082019050919050565b5f6020820190508181035f8301526102668161022d565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f6102c7603683610141565b91506102d28261026d565b604082019050919050565b5f6020820190508181035f8301526102f4816102bb565b9050919050565b610d0c806103085f395ff3fe608060405234801561000f575f5ffd5b506004361061009c575f3560e01c8063ad5963ca11610064578063ad5963ca14610158578063b279888b14610188578063cf83c71c146101a4578063dec9f688146101ae578063e90bf998146101b85761009c565b806302a5e064146100a057806306c0f8b9146100d057806318e1813f1461010057806323d746281461013057806354e84d1b1461014e575b5f5ffd5b6100ba60048036038101906100b59190610639565b6101c2565b6040516100c79190610673565b60405180910390f35b6100ea60048036038101906100e591906106e6565b6101d1565b6040516100f7919061072b565b60405180910390f35b61011a60048036038101906101159190610639565b610361565b604051610127919061072b565b60405180910390f35b610138610372565b604051610145919061072b565b60405180910390f35b61015661037e565b005b610172600480360381019061016d91906106e6565b6103d3565b60405161017f919061072b565b60405180910390f35b6101a2600480360381019061019d9190610744565b61048f565b005b6101ac610496565b005b6101b661053d565b005b6101c0610597565b005b5f5f825c905080915050919050565b5f5f600490505f605890505f84905081835d8073ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b81526004016102209291906107fd565b5f604051808303815f87803b158015610237575f5ffd5b505af1158015610249573d5f5f3e3d5ffd5b505050505f835c9050828114610294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028b906108a4565b60405180910390fd5b5f8273ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b81526004016102cf91906108c2565b602060405180830381865afa1580156102ea573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030e91906108ef565b9050607b8114610353576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034a90610964565b60405180910390fd5b600195505050505050919050565b5f5f825c90505f8114915050919050565b5f61037b6105f0565b90565b5f600390505f61038d82610361565b9050806103cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103c6906109f2565b60405180910390fd5b5050565b5f5f600590505f607b905080825d8373ffffffffffffffffffffffffffffffffffffffff1663dec9f6886040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610426575f5ffd5b505af1158015610438573d5f5f3e3d5ffd5b505050505f825c9050818114610483576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047a90610a80565b60405180910390fd5b60019350505050919050565b80825d5050565b5f600190505f602a905080825d5f825c90508181146104ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104e190610b0e565b60405180910390fd5b5f600290505f815c90505f8114610536576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052d90610b9c565b60405180910390fd5b5050505050565b5f600690505f6101c8905080825d5f825c9050818114610592576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161058990610c2a565b60405180910390fd5b505050565b5f600390505f6063905080825d5f825c90508181146105eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105e290610cb8565b60405180910390fd5b505050565b6105f8610496565b610600610597565b565b5f5ffd5b5f819050919050565b61061881610606565b8114610622575f5ffd5b50565b5f813590506106338161060f565b92915050565b5f6020828403121561064e5761064d610602565b5b5f61065b84828501610625565b91505092915050565b61066d81610606565b82525050565b5f6020820190506106865f830184610664565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6106b58261068c565b9050919050565b6106c5816106ab565b81146106cf575f5ffd5b50565b5f813590506106e0816106bc565b92915050565b5f602082840312156106fb576106fa610602565b5b5f610708848285016106d2565b91505092915050565b5f8115159050919050565b61072581610711565b82525050565b5f60208201905061073e5f83018461071c565b92915050565b5f5f6040838503121561075a57610759610602565b5b5f61076785828601610625565b925050602061077885828601610625565b9150509250929050565b5f819050919050565b5f819050919050565b5f6107ae6107a96107a484610782565b61078b565b610606565b9050919050565b6107be81610794565b82525050565b5f819050919050565b5f6107e76107e26107dd846107c4565b61078b565b610606565b9050919050565b6107f7816107cd565b82525050565b5f6040820190506108105f8301856107b5565b61081d60208301846107ee565b9392505050565b5f82825260208201905092915050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f61088e603783610824565b915061089982610834565b604082019050919050565b5f6020820190508181035f8301526108bb81610882565b9050919050565b5f6020820190506108d55f8301846107b5565b92915050565b5f815190506108e98161060f565b92915050565b5f6020828403121561090457610903610602565b5b5f610911848285016108db565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f61094e601e83610824565b91506109598261091a565b602082019050919050565b5f6020820190508181035f83015261097b81610942565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f6109dc603383610824565b91506109e782610982565b604082019050919050565b5f6020820190508181035f830152610a09816109d0565b9050919050565b7f5265656e74727920616c7465726564207472616e7369656e742073746f7261675f8201527f6500000000000000000000000000000000000000000000000000000000000000602082015250565b5f610a6a602183610824565b9150610a7582610a10565b604082019050919050565b5f6020820190508181035f830152610a9781610a5e565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f610af8602883610824565b9150610b0382610a9e565b604082019050919050565b5f6020820190508181035f830152610b2581610aec565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610b86602783610824565b9150610b9182610b2c565b604082019050919050565b5f6020820190508181035f830152610bb381610b7a565b9050919050565b7f5265656e7472792063616c6c6261636b206661696c656420746f2073746f72655f8201527f20636f72726563742076616c7565000000000000000000000000000000000000602082015250565b5f610c14602e83610824565b9150610c1f82610bba565b604082019050919050565b5f6020820190508181035f830152610c4181610c08565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610ca2603683610824565b9150610cad82610c48565b604082019050919050565b5f6020820190508181035f830152610ccf81610c96565b905091905056fea264697066735822122009f9e449a84c0ca3ce160e838d2f2f5708d24ac47e23d1cfed5d8eabdba8ee0e64736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.hex b/actors/evm/tests/contracts/TransientStorageTest.hex index f90c7d359..0908ffdda 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.hex +++ b/actors/evm/tests/contracts/TransientStorageTest.hex @@ -1 +1 @@ -608060405234801561000f575f5ffd5b5061001e61002360201b60201c565b6102fb565b61003161004160201b60201c565b61003f6100e860201b60201c565b565b5f600190505f602a905080825d5f825c9050818114610095576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161008c906101c1565b60405180910390fd5b5f600290505f815c90505f81146100e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100d89061024f565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c905081811461013c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610133906102dd565b60405180910390fd5b505050565b5f82825260208201905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6101ab602883610141565b91506101b682610151565b604082019050919050565b5f6020820190508181035f8301526101d88161019f565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610239602783610141565b9150610244826101df565b604082019050919050565b5f6020820190508181035f8301526102668161022d565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f6102c7603683610141565b91506102d28261026d565b604082019050919050565b5f6020820190508181035f8301526102f4816102bb565b9050919050565b610d0c806103085f395ff3fe608060405234801561000f575f5ffd5b506004361061009c575f3560e01c8063ad5963ca11610064578063ad5963ca14610158578063b279888b14610188578063cf83c71c146101a4578063dec9f688146101ae578063e90bf998146101b85761009c565b806302a5e064146100a057806306c0f8b9146100d057806318e1813f1461010057806323d746281461013057806354e84d1b1461014e575b5f5ffd5b6100ba60048036038101906100b59190610639565b6101c2565b6040516100c79190610673565b60405180910390f35b6100ea60048036038101906100e591906106e6565b6101d1565b6040516100f7919061072b565b60405180910390f35b61011a60048036038101906101159190610639565b610361565b604051610127919061072b565b60405180910390f35b610138610372565b604051610145919061072b565b60405180910390f35b61015661037e565b005b610172600480360381019061016d91906106e6565b6103d3565b60405161017f919061072b565b60405180910390f35b6101a2600480360381019061019d9190610744565b61048f565b005b6101ac610496565b005b6101b661053d565b005b6101c0610597565b005b5f5f825c905080915050919050565b5f5f600490505f605890505f84905081835d8073ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b81526004016102209291906107fd565b5f604051808303815f87803b158015610237575f5ffd5b505af1158015610249573d5f5f3e3d5ffd5b505050505f835c9050828114610294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028b906108a4565b60405180910390fd5b5f8273ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b81526004016102cf91906108c2565b602060405180830381865afa1580156102ea573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030e91906108ef565b9050607b8114610353576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034a90610964565b60405180910390fd5b600195505050505050919050565b5f5f825c90505f8114915050919050565b5f61037b6105f0565b90565b5f600390505f61038d82610361565b9050806103cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103c6906109f2565b60405180910390fd5b5050565b5f5f600590505f607b905080825d8373ffffffffffffffffffffffffffffffffffffffff1663dec9f6886040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610426575f5ffd5b505af1158015610438573d5f5f3e3d5ffd5b505050505f825c9050818114610483576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047a90610a80565b60405180910390fd5b60019350505050919050565b80825d5050565b5f600190505f602a905080825d5f825c90508181146104ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104e190610b0e565b60405180910390fd5b5f600290505f815c90505f8114610536576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052d90610b9c565b60405180910390fd5b5050505050565b5f600690505f6101c8905080825d5f825c9050818114610592576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161058990610c2a565b60405180910390fd5b505050565b5f600390505f6063905080825d5f825c90508181146105eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105e290610cb8565b60405180910390fd5b505050565b6105f8610496565b610600610597565b565b5f5ffd5b5f819050919050565b61061881610606565b8114610622575f5ffd5b50565b5f813590506106338161060f565b92915050565b5f6020828403121561064e5761064d610602565b5b5f61065b84828501610625565b91505092915050565b61066d81610606565b82525050565b5f6020820190506106865f830184610664565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6106b58261068c565b9050919050565b6106c5816106ab565b81146106cf575f5ffd5b50565b5f813590506106e0816106bc565b92915050565b5f602082840312156106fb576106fa610602565b5b5f610708848285016106d2565b91505092915050565b5f8115159050919050565b61072581610711565b82525050565b5f60208201905061073e5f83018461071c565b92915050565b5f5f6040838503121561075a57610759610602565b5b5f61076785828601610625565b925050602061077885828601610625565b9150509250929050565b5f819050919050565b5f819050919050565b5f6107ae6107a96107a484610782565b61078b565b610606565b9050919050565b6107be81610794565b82525050565b5f819050919050565b5f6107e76107e26107dd846107c4565b61078b565b610606565b9050919050565b6107f7816107cd565b82525050565b5f6040820190506108105f8301856107b5565b61081d60208301846107ee565b9392505050565b5f82825260208201905092915050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f61088e603783610824565b915061089982610834565b604082019050919050565b5f6020820190508181035f8301526108bb81610882565b9050919050565b5f6020820190506108d55f8301846107b5565b92915050565b5f815190506108e98161060f565b92915050565b5f6020828403121561090457610903610602565b5b5f610911848285016108db565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f61094e601e83610824565b91506109598261091a565b602082019050919050565b5f6020820190508181035f83015261097b81610942565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f6109dc603383610824565b91506109e782610982565b604082019050919050565b5f6020820190508181035f830152610a09816109d0565b9050919050565b7f5265656e74727920616c7465726564207472616e7369656e742073746f7261675f8201527f6500000000000000000000000000000000000000000000000000000000000000602082015250565b5f610a6a602183610824565b9150610a7582610a10565b604082019050919050565b5f6020820190508181035f830152610a9781610a5e565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f610af8602883610824565b9150610b0382610a9e565b604082019050919050565b5f6020820190508181035f830152610b2581610aec565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610b86602783610824565b9150610b9182610b2c565b604082019050919050565b5f6020820190508181035f830152610bb381610b7a565b9050919050565b7f5265656e7472792063616c6c6261636b206661696c656420746f2073746f72655f8201527f20636f72726563742076616c7565000000000000000000000000000000000000602082015250565b5f610c14602e83610824565b9150610c1f82610bba565b604082019050919050565b5f6020820190508181035f830152610c4181610c08565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610ca2603683610824565b9150610cad82610c48565b604082019050919050565b5f6020820190508181035f830152610ccf81610c96565b905091905056fea264697066735822122095c906ec88537a93b3cb227216e53383f0de67b1ebc5dce9dd036fd303ac8b6e64736f6c634300081c0033 \ No newline at end of file +608060405234801561000f575f5ffd5b5061001e61002360201b60201c565b6102fb565b61003161004160201b60201c565b61003f6100e860201b60201c565b565b5f600190505f602a905080825d5f825c9050818114610095576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161008c906101c1565b60405180910390fd5b5f600290505f815c90505f81146100e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100d89061024f565b60405180910390fd5b5050505050565b5f600390505f6063905080825d5f825c905081811461013c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610133906102dd565b60405180910390fd5b505050565b5f82825260208201905092915050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f6101ab602883610141565b91506101b682610151565b604082019050919050565b5f6020820190508181035f8301526101d88161019f565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610239602783610141565b9150610244826101df565b604082019050919050565b5f6020820190508181035f8301526102668161022d565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f6102c7603683610141565b91506102d28261026d565b604082019050919050565b5f6020820190508181035f8301526102f4816102bb565b9050919050565b610d0c806103085f395ff3fe608060405234801561000f575f5ffd5b506004361061009c575f3560e01c8063ad5963ca11610064578063ad5963ca14610158578063b279888b14610188578063cf83c71c146101a4578063dec9f688146101ae578063e90bf998146101b85761009c565b806302a5e064146100a057806306c0f8b9146100d057806318e1813f1461010057806323d746281461013057806354e84d1b1461014e575b5f5ffd5b6100ba60048036038101906100b59190610639565b6101c2565b6040516100c79190610673565b60405180910390f35b6100ea60048036038101906100e591906106e6565b6101d1565b6040516100f7919061072b565b60405180910390f35b61011a60048036038101906101159190610639565b610361565b604051610127919061072b565b60405180910390f35b610138610372565b604051610145919061072b565b60405180910390f35b61015661037e565b005b610172600480360381019061016d91906106e6565b6103d3565b60405161017f919061072b565b60405180910390f35b6101a2600480360381019061019d9190610744565b61048f565b005b6101ac610496565b005b6101b661053d565b005b6101c0610597565b005b5f5f825c905080915050919050565b5f5f600490505f605890505f84905081835d8073ffffffffffffffffffffffffffffffffffffffff1663b279888b6004607b6040518363ffffffff1660e01b81526004016102209291906107fd565b5f604051808303815f87803b158015610237575f5ffd5b505af1158015610249573d5f5f3e3d5ffd5b505050505f835c9050828114610294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028b906108a4565b60405180910390fd5b5f8273ffffffffffffffffffffffffffffffffffffffff166302a5e06460046040518263ffffffff1660e01b81526004016102cf91906108c2565b602060405180830381865afa1580156102ea573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030e91906108ef565b9050607b8114610353576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034a90610964565b60405180910390fd5b600195505050505050919050565b5f5f825c90505f8114915050919050565b5f61037b6105f0565b90565b5f600390505f61038d82610361565b9050806103cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103c6906109f2565b60405180910390fd5b5050565b5f5f600590505f607b905080825d8373ffffffffffffffffffffffffffffffffffffffff1663dec9f6886040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610426575f5ffd5b505af1158015610438573d5f5f3e3d5ffd5b505050505f825c9050818114610483576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047a90610a80565b60405180910390fd5b60019350505050919050565b80825d5050565b5f600190505f602a905080825d5f825c90508181146104ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104e190610b0e565b60405180910390fd5b5f600290505f815c90505f8114610536576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161052d90610b9c565b60405180910390fd5b5050505050565b5f600690505f6101c8905080825d5f825c9050818114610592576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161058990610c2a565b60405180910390fd5b505050565b5f600390505f6063905080825d5f825c90508181146105eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105e290610cb8565b60405180910390fd5b505050565b6105f8610496565b610600610597565b565b5f5ffd5b5f819050919050565b61061881610606565b8114610622575f5ffd5b50565b5f813590506106338161060f565b92915050565b5f6020828403121561064e5761064d610602565b5b5f61065b84828501610625565b91505092915050565b61066d81610606565b82525050565b5f6020820190506106865f830184610664565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6106b58261068c565b9050919050565b6106c5816106ab565b81146106cf575f5ffd5b50565b5f813590506106e0816106bc565b92915050565b5f602082840312156106fb576106fa610602565b5b5f610708848285016106d2565b91505092915050565b5f8115159050919050565b61072581610711565b82525050565b5f60208201905061073e5f83018461071c565b92915050565b5f5f6040838503121561075a57610759610602565b5b5f61076785828601610625565b925050602061077885828601610625565b9150509250929050565b5f819050919050565b5f819050919050565b5f6107ae6107a96107a484610782565b61078b565b610606565b9050919050565b6107be81610794565b82525050565b5f819050919050565b5f6107e76107e26107dd846107c4565b61078b565b610606565b9050919050565b6107f7816107cd565b82525050565b5f6040820190506108105f8301856107b5565b61081d60208301846107ee565b9392505050565b5f82825260208201905092915050565b7f4e657374656420636f6e747261637420696e74657266657265642077697468205f8201527f7468697320636f6e747261637427732073746f72616765000000000000000000602082015250565b5f61088e603783610824565b915061089982610834565b604082019050919050565b5f6020820190508181035f8301526108bb81610882565b9050919050565b5f6020820190506108d55f8301846107b5565b92915050565b5f815190506108e98161060f565b92915050565b5f6020828403121561090457610903610602565b5b5f610911848285016108db565b91505092915050565b7f4e657374656420636f6e7472616374206461746120696e636f727265637400005f82015250565b5f61094e601e83610824565b91506109598261091a565b602082019050919050565b5f6020820190508181035f83015261097b81610942565b9050919050565b7f5472616e7369656e742073746f7261676520776173206e6f7420636c656172655f8201527f64206166746572207472616e73616374696f6e00000000000000000000000000602082015250565b5f6109dc603383610824565b91506109e782610982565b604082019050919050565b5f6020820190508181035f830152610a09816109d0565b9050919050565b7f5265656e74727920616c7465726564207472616e7369656e742073746f7261675f8201527f6500000000000000000000000000000000000000000000000000000000000000602082015250565b5f610a6a602183610824565b9150610a7582610a10565b604082019050919050565b5f6020820190508181035f830152610a9781610a5e565b9050919050565b7f544c4f414420646964206e6f742072657472696576652074686520636f7272655f8201527f63742076616c7565000000000000000000000000000000000000000000000000602082015250565b5f610af8602883610824565b9150610b0382610a9e565b604082019050919050565b5f6020820190508181035f830152610b2581610aec565b9050919050565b7f556e696e697469616c697a656420544c4f414420646964206e6f7420726574755f8201527f726e207a65726f00000000000000000000000000000000000000000000000000602082015250565b5f610b86602783610824565b9150610b9182610b2c565b604082019050919050565b5f6020820190508181035f830152610bb381610b7a565b9050919050565b7f5265656e7472792063616c6c6261636b206661696c656420746f2073746f72655f8201527f20636f72726563742076616c7565000000000000000000000000000000000000602082015250565b5f610c14602e83610824565b9150610c1f82610bba565b604082019050919050565b5f6020820190508181035f830152610c4181610c08565b9050919050565b7f544c4f414420646964206e6f742072657472696576652073746f7265642076615f8201527f6c75652077697468696e207472616e73616374696f6e00000000000000000000602082015250565b5f610ca2603683610824565b9150610cad82610c48565b604082019050919050565b5f6020820190508181035f830152610ccf81610c96565b905091905056fea264697066735822122009f9e449a84c0ca3ce160e838d2f2f5708d24ac47e23d1cfed5d8eabdba8ee0e64736f6c634300081c0033 \ No newline at end of file diff --git a/actors/evm/tests/contracts/TransientStorageTest.sol b/actors/evm/tests/contracts/TransientStorageTest.sol index 8541a9644..6560a0348 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.sol +++ b/actors/evm/tests/contracts/TransientStorageTest.sol @@ -2,8 +2,7 @@ pragma solidity ^0.8.24; contract TransientStorageTest { - - constructor(){ + constructor() { _runTests(); } @@ -106,7 +105,7 @@ contract TransientStorageTest { } // New function to test reentry scenario - function testReentry(address otherContract) public returns (bool){ + function testReentry(address otherContract) public returns (bool) { uint256 slot = 5; uint256 value = 123; @@ -159,5 +158,4 @@ contract TransientStorageTest { } return value; } - } From a2e4b37bf4cb89e563b657f5f99c5fe33c2014cc Mon Sep 17 00:00:00 2001 From: Mikers Date: Fri, 13 Dec 2024 14:43:16 -1000 Subject: [PATCH 46/46] add comments to transient storage test file with test information --- actors/evm/tests/contracts/TransientStorageTest.sol | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/actors/evm/tests/contracts/TransientStorageTest.sol b/actors/evm/tests/contracts/TransientStorageTest.sol index 6560a0348..968af3e56 100644 --- a/actors/evm/tests/contracts/TransientStorageTest.sol +++ b/actors/evm/tests/contracts/TransientStorageTest.sol @@ -6,6 +6,7 @@ contract TransientStorageTest { _runTests(); } + // Test 0: Initial Constructor Test function runTests() public returns (bool) { _runTests(); } @@ -61,13 +62,14 @@ contract TransientStorageTest { require(retrievedValue == value, "TLOAD did not retrieve stored value within transaction"); } + // Test 2.2: Verify transient storage clears in subsequent transactions function testLifecycleValidationSubsequentTransaction() public { - // Test clearing by re-calling as a new transaction uint256 slot = 3; bool cleared = isStorageCleared(slot); require(cleared, "Transient storage was not cleared after transaction"); } + // Utility Function: Check if transient storage is cleared function isStorageCleared(uint256 slot) public view returns (bool) { uint256 retrievedValue; assembly { @@ -76,7 +78,7 @@ contract TransientStorageTest { return retrievedValue == 0; // True if cleared } - // Test 2.2: Verify nested contract independence + // Test 3: Verify nested contract independence function testNestedContracts(address other) public returns (bool) { uint256 slot = 4; uint256 value = 88; @@ -104,7 +106,7 @@ contract TransientStorageTest { return true; } - // New function to test reentry scenario + // Test 4: Reentry scenario function testReentry(address otherContract) public returns (bool) { uint256 slot = 5; uint256 value = 123; @@ -127,6 +129,7 @@ contract TransientStorageTest { return true; } + // Utility Function for Test 4: Reentry callback function reentryCallback() public { uint256 slot = 6; uint256 value = 456; @@ -145,12 +148,14 @@ contract TransientStorageTest { require(retrievedValue == value, "Reentry callback failed to store correct value"); } + // Utility Function for Test 3: Write to transient storage function writeTransientData(uint256 slot, uint256 value) external { assembly { tstore(slot, value) } } + // Utility Function for Test 3: Read from transient storage function readTransientData(uint256 slot) external view returns (uint256) { uint256 value; assembly {