Skip to content

Commit 9f5645d

Browse files
authored
Compliance fix 2 (#219)
* Add support for access list in jsontests * Fix control flow * Fix storage reset * Filter out errorous zero value from test files
1 parent 7443848 commit 9f5645d

File tree

6 files changed

+58
-19
lines changed

6 files changed

+58
-19
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ jobs:
3636
- name: Run tests
3737
run: |
3838
cargo run --release --verbose -p jsontests -- \
39-
jsontests/res/ethtests/GeneralStateTests/stExample/add11.json \
40-
jsontests/res/ethtests/GeneralStateTests/stSLoadTest/
39+
jsontests/res/ethtests/GeneralStateTests/stExample/ \
40+
jsontests/res/ethtests/GeneralStateTests/stSLoadTest/ \
41+
jsontests/res/ethtests/GeneralStateTests/VMTests/vmArithmeticTest/ \
42+
jsontests/res/ethtests/GeneralStateTests/VMTests/vmBitwiseLogicOperation/

interpreter/src/lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,31 +160,28 @@ impl<S> Machine<S> {
160160
let opcode = Opcode(self.code[position]);
161161
let control = etable[opcode.as_usize()](self, handle, opcode, self.position);
162162

163-
let mut ret = match control {
163+
match control {
164164
Control::Continue => {
165165
self.position += 1;
166-
Ok(())
167166
}
168167
Control::ContinueN(p) => {
169168
self.position = position + p;
170-
Ok(())
171169
}
172170
Control::Exit(e) => {
173171
self.position = self.code.len();
174-
Err(Capture::Exit(e))
172+
return Err(Capture::Exit(e));
175173
}
176174
Control::Jump(p) => {
177175
self.position = p;
178-
Ok(())
179176
}
180-
Control::Trap(opcode) => Err(Capture::Trap(opcode)),
177+
Control::Trap(opcode) => return Err(Capture::Trap(opcode)),
181178
};
182179

183-
if position >= self.code.len() {
184-
ret = Err(Capture::Exit(ExitSucceed::Stopped.into()));
180+
if self.position >= self.code.len() {
181+
return Err(Capture::Exit(ExitSucceed::Stopped.into()));
185182
}
186183

187-
ret
184+
Ok(())
188185
}
189186

190187
/// Pick the next opcode.

jsontests/src/run.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ pub fn run_test(_filename: &str, _test_name: &str, test: Test, debug: bool) -> R
1515
_ => return Err(Error::UnsupportedFork),
1616
};
1717

18+
if test.post.expect_exception == Some(TestExpectException::TR_TypeNotSupported) {
19+
// The `evm` crate does not understand transaction format, only the `ethereum` crate. So
20+
// there's nothing for us to test here for `TR_TypeNotSupported`.
21+
return Ok(());
22+
}
23+
1824
let env = InMemoryEnvironment {
1925
block_hashes: BTreeMap::new(), // TODO: fill in this field.
2026
block_number: test.env.current_number,
@@ -35,6 +41,7 @@ pub fn run_test(_filename: &str, _test_name: &str, test: Test, debug: bool) -> R
3541
let storage = account
3642
.storage
3743
.into_iter()
44+
.filter(|(_, value)| *value != U256::zero())
3845
.map(|(key, value)| (u256_to_h256(key), u256_to_h256(value)))
3946
.collect::<BTreeMap<_, _>>();
4047

@@ -60,7 +67,12 @@ pub fn run_test(_filename: &str, _test_name: &str, test: Test, debug: bool) -> R
6067
data: test.transaction.data,
6168
gas_limit: test.transaction.gas_limit,
6269
gas_price: test.transaction.gas_price,
63-
access_list: Vec::new(),
70+
access_list: test
71+
.transaction
72+
.access_list
73+
.into_iter()
74+
.map(|access| (access.address, access.storage_keys))
75+
.collect(),
6476
};
6577

6678
let mut run_backend = InMemoryBackend {

jsontests/src/types.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ impl TestMulti {
3939
sender: self.transaction.sender,
4040
to: self.transaction.to,
4141
value: self.transaction.value[post_state.indexes.value],
42+
access_list: match &self.transaction.access_lists {
43+
Some(access_lists) => access_lists[post_state.indexes.data].clone(),
44+
None => Vec::new(),
45+
},
4246
},
4347
});
4448
}
@@ -113,7 +117,14 @@ pub struct TestPostState {
113117
pub indexes: TestPostStateIndexes,
114118
pub logs: H256,
115119
pub txbytes: HexBytes,
116-
pub expect_exception: Option<String>,
120+
pub expect_exception: Option<TestExpectException>,
121+
}
122+
123+
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
124+
#[allow(non_camel_case_types)]
125+
pub enum TestExpectException {
126+
TR_TypeNotSupported,
127+
TR_IntrinsicGas,
117128
}
118129

119130
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
@@ -144,6 +155,14 @@ pub struct TestMultiTransaction {
144155
pub sender: H160,
145156
pub to: H160,
146157
pub value: Vec<U256>,
158+
pub access_lists: Option<Vec<Vec<TestAccessListItem>>>,
159+
}
160+
161+
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
162+
#[serde(rename_all = "camelCase")]
163+
pub struct TestAccessListItem {
164+
pub address: H160,
165+
pub storage_keys: Vec<H256>,
147166
}
148167

149168
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -156,6 +175,7 @@ pub struct TestTransaction {
156175
pub sender: H160,
157176
pub to: H160,
158177
pub value: U256,
178+
pub access_list: Vec<TestAccessListItem>,
159179
}
160180

161181
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]

src/backend/in_memory.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ impl RuntimeBackend for InMemoryBackend {
174174
}
175175

176176
fn set_storage(&mut self, address: H160, index: H256, value: H256) -> Result<(), ExitError> {
177-
self.current_layer_mut()
178-
.state
179-
.entry(address)
180-
.or_default()
181-
.storage
182-
.insert(index, value);
177+
let entry = self.current_layer_mut().state.entry(address).or_default();
178+
179+
if value == H256::default() {
180+
entry.storage.remove(&index);
181+
} else {
182+
entry.storage.insert(index, value);
183+
}
183184
Ok(())
184185
}
185186

src/standard/invoker/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ where
193193
access_list,
194194
..
195195
} => {
196+
for (address, keys) in &access_list {
197+
handler.mark_hot(*address, None)?;
198+
for key in keys {
199+
handler.mark_hot(*address, Some(*key))?;
200+
}
201+
}
202+
196203
let code = handler.code(address);
197204

198205
let gasometer =

0 commit comments

Comments
 (0)