Skip to content

Commit

Permalink
Some renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Rodrigues Lordello committed Sep 1, 2023
1 parent 4cb5cc9 commit ba63849
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion crates/contracts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion crates/contracts/solidity/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions crates/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -72,8 +72,8 @@ pub mod support {
Balances;
FetchBlock;
Multicall;
Reader;
Signatures;
SimulateCode;
Solver;
Trader;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion crates/shared/src/account_balances/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/shared/src/signature_validator/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit ba63849

Please sign in to comment.