Skip to content

Commit

Permalink
Compliance fix 2 (#219)
Browse files Browse the repository at this point in the history
* Add support for access list in jsontests

* Fix control flow

* Fix storage reset

* Filter out errorous zero value from test files
  • Loading branch information
sorpaas committed Nov 18, 2023
1 parent 7443848 commit 9f5645d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 19 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ jobs:
- name: Run tests
run: |
cargo run --release --verbose -p jsontests -- \
jsontests/res/ethtests/GeneralStateTests/stExample/add11.json \
jsontests/res/ethtests/GeneralStateTests/stSLoadTest/
jsontests/res/ethtests/GeneralStateTests/stExample/ \
jsontests/res/ethtests/GeneralStateTests/stSLoadTest/ \
jsontests/res/ethtests/GeneralStateTests/VMTests/vmArithmeticTest/ \
jsontests/res/ethtests/GeneralStateTests/VMTests/vmBitwiseLogicOperation/
15 changes: 6 additions & 9 deletions interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,31 +160,28 @@ impl<S> Machine<S> {
let opcode = Opcode(self.code[position]);
let control = etable[opcode.as_usize()](self, handle, opcode, self.position);

let mut ret = match control {
match control {
Control::Continue => {
self.position += 1;
Ok(())
}
Control::ContinueN(p) => {
self.position = position + p;
Ok(())
}
Control::Exit(e) => {
self.position = self.code.len();
Err(Capture::Exit(e))
return Err(Capture::Exit(e));
}
Control::Jump(p) => {
self.position = p;
Ok(())
}
Control::Trap(opcode) => Err(Capture::Trap(opcode)),
Control::Trap(opcode) => return Err(Capture::Trap(opcode)),
};

if position >= self.code.len() {
ret = Err(Capture::Exit(ExitSucceed::Stopped.into()));
if self.position >= self.code.len() {
return Err(Capture::Exit(ExitSucceed::Stopped.into()));
}

ret
Ok(())
}

/// Pick the next opcode.
Expand Down
14 changes: 13 additions & 1 deletion jsontests/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pub fn run_test(_filename: &str, _test_name: &str, test: Test, debug: bool) -> R
_ => return Err(Error::UnsupportedFork),
};

if test.post.expect_exception == Some(TestExpectException::TR_TypeNotSupported) {
// The `evm` crate does not understand transaction format, only the `ethereum` crate. So
// there's nothing for us to test here for `TR_TypeNotSupported`.
return Ok(());
}

let env = InMemoryEnvironment {
block_hashes: BTreeMap::new(), // TODO: fill in this field.
block_number: test.env.current_number,
Expand All @@ -35,6 +41,7 @@ pub fn run_test(_filename: &str, _test_name: &str, test: Test, debug: bool) -> R
let storage = account
.storage
.into_iter()
.filter(|(_, value)| *value != U256::zero())
.map(|(key, value)| (u256_to_h256(key), u256_to_h256(value)))
.collect::<BTreeMap<_, _>>();

Expand All @@ -60,7 +67,12 @@ pub fn run_test(_filename: &str, _test_name: &str, test: Test, debug: bool) -> R
data: test.transaction.data,
gas_limit: test.transaction.gas_limit,
gas_price: test.transaction.gas_price,
access_list: Vec::new(),
access_list: test
.transaction
.access_list
.into_iter()
.map(|access| (access.address, access.storage_keys))
.collect(),
};

let mut run_backend = InMemoryBackend {
Expand Down
22 changes: 21 additions & 1 deletion jsontests/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ impl TestMulti {
sender: self.transaction.sender,
to: self.transaction.to,
value: self.transaction.value[post_state.indexes.value],
access_list: match &self.transaction.access_lists {
Some(access_lists) => access_lists[post_state.indexes.data].clone(),
None => Vec::new(),
},
},
});
}
Expand Down Expand Up @@ -113,7 +117,14 @@ pub struct TestPostState {
pub indexes: TestPostStateIndexes,
pub logs: H256,
pub txbytes: HexBytes,
pub expect_exception: Option<String>,
pub expect_exception: Option<TestExpectException>,
}

#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
#[allow(non_camel_case_types)]
pub enum TestExpectException {
TR_TypeNotSupported,
TR_IntrinsicGas,
}

#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
Expand Down Expand Up @@ -144,6 +155,14 @@ pub struct TestMultiTransaction {
pub sender: H160,
pub to: H160,
pub value: Vec<U256>,
pub access_lists: Option<Vec<Vec<TestAccessListItem>>>,
}

#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TestAccessListItem {
pub address: H160,
pub storage_keys: Vec<H256>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand All @@ -156,6 +175,7 @@ pub struct TestTransaction {
pub sender: H160,
pub to: H160,
pub value: U256,
pub access_list: Vec<TestAccessListItem>,
}

#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
Expand Down
13 changes: 7 additions & 6 deletions src/backend/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ impl RuntimeBackend for InMemoryBackend {
}

fn set_storage(&mut self, address: H160, index: H256, value: H256) -> Result<(), ExitError> {
self.current_layer_mut()
.state
.entry(address)
.or_default()
.storage
.insert(index, value);
let entry = self.current_layer_mut().state.entry(address).or_default();

if value == H256::default() {
entry.storage.remove(&index);
} else {
entry.storage.insert(index, value);
}
Ok(())
}

Expand Down
7 changes: 7 additions & 0 deletions src/standard/invoker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ where
access_list,
..
} => {
for (address, keys) in &access_list {
handler.mark_hot(*address, None)?;
for key in keys {
handler.mark_hot(*address, Some(*key))?;
}
}

let code = handler.code(address);

let gasometer =
Expand Down

0 comments on commit 9f5645d

Please sign in to comment.