diff --git a/crates/contracts/artifacts/Reader.json b/crates/contracts/artifacts/SimulateCode.json similarity index 100% rename from crates/contracts/artifacts/Reader.json rename to crates/contracts/artifacts/SimulateCode.json diff --git a/crates/contracts/build.rs b/crates/contracts/build.rs index 8a9274043d..ae4c0c560c 100644 --- a/crates/contracts/build.rs +++ b/crates/contracts/build.rs @@ -525,8 +525,8 @@ fn main() { // Support contract used for various order simulations. generate_contract("Balances"); - generate_contract("Reader"); generate_contract("Signatures"); + generate_contract("SimulateCode"); // Support contract used for global block stream. generate_contract("FetchBlock"); diff --git a/crates/contracts/solidity/Makefile b/crates/contracts/solidity/Makefile index 64ca9a8585..f9fa3b9073 100644 --- a/crates/contracts/solidity/Makefile +++ b/crates/contracts/solidity/Makefile @@ -11,8 +11,8 @@ CONTRACTS := \ Balances.sol \ FetchBlock.sol \ Multicall.sol \ - Reader.sol \ Signatures.sol \ + SimulateCode.sol \ Solver.sol \ Trader.sol ARTIFACTS := $(patsubst %.sol,$(ARTIFACTDIR)/%.json,$(CONTRACTS)) diff --git a/crates/contracts/solidity/Reader.sol b/crates/contracts/solidity/SimulateCode.sol similarity index 73% rename from crates/contracts/solidity/Reader.sol rename to crates/contracts/solidity/SimulateCode.sol index 45eb94ce45..95d8f92e75 100644 --- a/crates/contracts/solidity/Reader.sol +++ b/crates/contracts/solidity/SimulateCode.sol @@ -3,17 +3,18 @@ pragma solidity ^0.8.17; import { IStorageAccessible } from "./interfaces/IStorageAccessible.sol"; -/// @title A contract for simulating delegate calls on the Settlement contract. -contract Reader { +/// @title A contract for simulating arbitrary code in the context of a +/// `StorageAccessible` contract. +contract SimulateCode { /// @dev This looks like a constructor but it is not... In fact, nodes /// support `eth_call`s for contract creation and **return the code of the /// contract that would be created**. This means we can use contructors to /// execute arbitrary code on the current state of the EVM, and "manually" /// return with some inline assembly that data (as this is the mechanism - /// used for contract creation). See the / `FetchBlock.sol` contract for + /// used for contract creation). See the `FetchBlock.sol` contract for /// another application of this trick. /// - /// The reader contract does this to: + /// The contract does this to: /// 1. Deploy some arbitrary contract code /// 2. Use the `StorageAccessible` pattern to execute the contract code /// deployed in step 1. within the another contract context (usually the @@ -26,18 +27,18 @@ contract Reader { /// /// @param target - The `StorageAccessible` implementation. /// @param code - Creation code for the reader contract. - /// @param call - The calldata to pass in the DELEGATECALL simulation. + /// @param call - The calldata to pass in the `DELEGATECALL` simulation. constructor( IStorageAccessible target, bytes memory code, bytes memory call ) { - address reader; + address implementation; assembly { - reader := create(callvalue(), add(code, 32), mload(code)) + implementation := create(callvalue(), add(code, 32), mload(code)) } - bytes memory result = target.simulateDelegatecall(reader, call); + bytes memory result = target.simulateDelegatecall(implementation, call); assembly { return(add(32, result), mload(result)) } diff --git a/crates/contracts/src/lib.rs b/crates/contracts/src/lib.rs index aae5148df9..9d445a5606 100644 --- a/crates/contracts/src/lib.rs +++ b/crates/contracts/src/lib.rs @@ -7,7 +7,7 @@ mod macros; #[cfg(feature = "bin")] pub mod paths; -pub mod reader; +pub mod storage_accessible; pub mod vault; pub mod web3; @@ -72,8 +72,8 @@ pub mod support { Balances; FetchBlock; Multicall; - Reader; Signatures; + SimulateCode; Solver; Trader; } diff --git a/crates/contracts/src/reader.rs b/crates/contracts/src/storage_accessible.rs similarity index 77% rename from crates/contracts/src/reader.rs rename to crates/contracts/src/storage_accessible.rs index 282b1a4cc8..e0c38b7cd4 100644 --- a/crates/contracts/src/reader.rs +++ b/crates/contracts/src/storage_accessible.rs @@ -1,7 +1,7 @@ -//! Module to help encoding `eth_call`s for the `Reader.sol` contract. +//! Module to help encoding `eth_call`s for the `StorageAccessible` contracts. use { - crate::support::Reader, + crate::support::SimulateCode, ethcontract::{ common::abi, tokens::Tokenize, @@ -10,6 +10,8 @@ use { }, }; +/// Encode a call to a `StorageAccessible` `target` to execute `call` with the +/// contract created with `code` pub fn call(target: H160, code: Bytes, call: Bytes) -> CallRequest { // Unfortunately, the `ethcontract` crate does not expose the logic to build // creation code for a contract. Luckily, it isn't complicated - you just @@ -23,7 +25,7 @@ pub fn call(target: H160, code: Bytes, call: Bytes) -> CallRequest { CallRequest { data: Some( [ - Reader::raw_contract() + SimulateCode::raw_contract() .bytecode .to_bytes() .unwrap() diff --git a/crates/shared/src/account_balances/simulation.rs b/crates/shared/src/account_balances/simulation.rs index 57fadeebd0..16b5da407f 100644 --- a/crates/shared/src/account_balances/simulation.rs +++ b/crates/shared/src/account_balances/simulation.rs @@ -62,7 +62,7 @@ impl Balances { ) .tx; - let call = contracts::reader::call( + let call = contracts::storage_accessible::call( self.settlement, contracts::bytecode!(contracts::support::Balances), tx.data.unwrap(), diff --git a/crates/shared/src/signature_validator/simulation.rs b/crates/shared/src/signature_validator/simulation.rs index 0558170e11..dbe4bbb521 100644 --- a/crates/shared/src/signature_validator/simulation.rs +++ b/crates/shared/src/signature_validator/simulation.rs @@ -53,7 +53,7 @@ impl Validator { ) .tx; - let call = contracts::reader::call( + let call = contracts::storage_accessible::call( self.settlement, contracts::bytecode!(contracts::support::Signatures), tx.data.unwrap(),