Skip to content

Commit 577f83f

Browse files
authored
Pass all Shanghai and Cancun tests (#378)
* Several fixes for create initcode limit * Move initcode check earlier to the call * Pass all Shanghai tests * Run cargo fmt * Add missing ExpectException type * EIP-7516 blob base fee * EIP-4844 initial support * Add KZGPointEvaluation precompile * Pass all Cancun tests * Add all static config pointers * Cargo fmt
1 parent af1e5c6 commit 577f83f

File tree

22 files changed

+469
-39
lines changed

22 files changed

+469
-39
lines changed

future/tests/usability.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ impl RuntimeEnvironment for UnimplementedHandler {
6161
fn block_base_fee_per_gas(&self) -> U256 {
6262
unimplemented!()
6363
}
64+
fn blob_base_fee_per_gas(&self) -> U256 {
65+
unimplemented!()
66+
}
67+
fn blob_versioned_hash(&self, _index: U256) -> H256 {
68+
unimplemented!()
69+
}
6470
fn chain_id(&self) -> U256 {
6571
unimplemented!()
6672
}

fuzz/src/backend.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ impl RuntimeEnvironment for MockBackend {
104104
Default::default()
105105
}
106106

107+
fn blob_base_fee_per_gas(&self) -> U256 {
108+
Default::default()
109+
}
110+
111+
fn blob_versioned_hash(&self, _index: U256) -> H256 {
112+
Default::default()
113+
}
114+
107115
fn chain_id(&self) -> U256 {
108116
Default::default()
109117
}

interpreter/src/etable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ where
432432
table.0[Opcode::CHAINID.as_usize()] = eval_chainid as _;
433433
table.0[Opcode::SELFBALANCE.as_usize()] = eval_selfbalance as _;
434434
table.0[Opcode::BASEFEE.as_usize()] = eval_basefee as _;
435+
table.0[Opcode::BLOBHASH.as_usize()] = eval_blobhash as _;
436+
table.0[Opcode::BLOBBASEFEE.as_usize()] = eval_blobbasefee as _;
435437

436438
table.0[Opcode::SLOAD.as_usize()] = eval_sload as _;
437439
table.0[Opcode::SSTORE.as_usize()] = eval_sstore as _;

interpreter/src/eval/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,24 @@ pub fn eval_gaslimit<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBack
660660
self::system::gaslimit(machine, handle)
661661
}
662662

663+
/// `BLOBHASH`
664+
pub fn eval_blobhash<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
665+
machine: &mut Machine<S>,
666+
handle: &mut H,
667+
_position: usize,
668+
) -> Control<Tr> {
669+
self::system::blobhash(machine, handle)
670+
}
671+
672+
/// `BLOBBASEFEE`
673+
pub fn eval_blobbasefee<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
674+
machine: &mut Machine<S>,
675+
handle: &mut H,
676+
_position: usize,
677+
) -> Control<Tr> {
678+
self::system::blobbasefee(machine, handle)
679+
}
680+
663681
/// `SLOAD`
664682
pub fn eval_sload<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
665683
machine: &mut Machine<S>,
@@ -935,6 +953,8 @@ where
935953
Opcode::CHAINID => eval_chainid(machine, handle, position),
936954
Opcode::SELFBALANCE => eval_selfbalance(machine, handle, position),
937955
Opcode::BASEFEE => eval_basefee(machine, handle, position),
956+
Opcode::BLOBHASH => eval_blobhash(machine, handle, position),
957+
Opcode::BLOBBASEFEE => eval_blobbasefee(machine, handle, position),
938958

939959
Opcode::SLOAD => eval_sload(machine, handle, position),
940960
Opcode::SSTORE => eval_sstore(machine, handle, position),

interpreter/src/eval/system.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,27 @@ pub fn basefee<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, T
124124
Control::Continue(1)
125125
}
126126

127+
pub fn blobhash<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
128+
machine: &mut Machine<S>,
129+
handler: &H,
130+
) -> Control<Tr> {
131+
pop_u256!(machine, index);
132+
let hash = handler.blob_versioned_hash(index);
133+
push_h256!(machine, hash);
134+
135+
Control::Continue(1)
136+
}
137+
138+
pub fn blobbasefee<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
139+
machine: &mut Machine<S>,
140+
handler: &H,
141+
) -> Control<Tr> {
142+
let blob_basefee = handler.blob_base_fee_per_gas();
143+
push_u256!(machine, blob_basefee);
144+
145+
Control::Continue(1)
146+
}
147+
127148
pub fn extcodesize<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
128149
machine: &mut Machine<S>,
129150
handler: &mut H,

interpreter/src/opcode.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ impl Opcode {
291291
pub const SELFBALANCE: Opcode = Opcode(0x47);
292292
/// `BASEFEE`
293293
pub const BASEFEE: Opcode = Opcode(0x48);
294+
/// `BLOBHASH`
295+
pub const BLOBHASH: Opcode = Opcode(0x49);
296+
/// `BLOBBASEFEE`
297+
pub const BLOBBASEFEE: Opcode = Opcode(0x4a);
294298

295299
/// `SLOAD`
296300
pub const SLOAD: Opcode = Opcode(0x54);

interpreter/src/runtime.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ pub trait RuntimeEnvironment {
199199
fn block_gas_limit(&self) -> U256;
200200
/// Environmental block base fee.
201201
fn block_base_fee_per_gas(&self) -> U256;
202+
/// Blob hash.
203+
fn blob_versioned_hash(&self, index: U256) -> H256;
204+
/// Blob base fee per gas.
205+
fn blob_base_fee_per_gas(&self) -> U256;
202206
/// Get environmental chain ID.
203207
fn chain_id(&self) -> U256;
204208
}

interpreter/tests/usability.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ impl RuntimeEnvironment for UnimplementedHandler {
9292
fn block_base_fee_per_gas(&self) -> U256 {
9393
unimplemented!()
9494
}
95+
fn blob_base_fee_per_gas(&self) -> U256 {
96+
unimplemented!()
97+
}
98+
fn blob_versioned_hash(&self, _index: U256) -> H256 {
99+
unimplemented!()
100+
}
95101
fn chain_id(&self) -> U256 {
96102
unimplemented!()
97103
}

jsontests/src/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
use crate::types::TestExpectException;
2+
13
#[derive(Debug, thiserror::Error)]
24
#[allow(dead_code)]
35
pub enum TestError {
46
#[error("state root is different")]
57
StateMismatch,
68
#[error("expect error, but got okay")]
7-
ExpectException,
9+
ExpectException(TestExpectException),
810
#[error("unexpected decoding error")]
911
UnexpectedDecoding,
1012
}

jsontests/src/run.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ pub fn run_test(
188188
Fork::Istanbul => Config::istanbul(),
189189
Fork::Berlin => Config::berlin(),
190190
Fork::London => Config::london(),
191+
Fork::Shanghai => Config::shanghai(),
192+
Fork::Cancun => Config::cancun(),
191193
_ => return Err(Error::UnsupportedFork),
192194
};
193195
config_change(&mut config);
@@ -206,10 +208,21 @@ pub fn run_test(
206208
Some(TestExpectException::TR_NoFunds) => return Ok(()),
207209
Some(TestExpectException::TR_GasLimitReached) => return Ok(()),
208210
Some(TestExpectException::TR_TipGtFeeCap) => return Ok(()),
211+
Some(TestExpectException::TE_TYPE_3_TX_PRE_FORK) => return Ok(()),
212+
Some(TestExpectException::TE_TYPE_3_TX_PRE_FORK_OR_TX_ZERO_BLOBS) => return Ok(()),
213+
Some(TestExpectException::TE_TYPE_3_TX_BLOB_COUNT_EXCEEDED) => return Ok(()),
214+
Some(TestExpectException::TE_INSUFFICIENT_ACCOUNT_FUNDS) => return Ok(()),
209215

210216
_ => (),
211217
}
212218

219+
if test.transaction.blob_versioned_hashes.is_some() {
220+
// Rust EVM doesn't deal directly with transactions. Currently we expect
221+
// users of Rust EVM to deduct blob costs themselves for TYPE 3
222+
// transactions, but this may change in the future.
223+
return Ok(());
224+
}
225+
213226
let env = InMemoryEnvironment {
214227
block_hashes: {
215228
let mut block_hashes = BTreeMap::new();
@@ -229,6 +242,12 @@ pub fn run_test(
229242
block_randomness: test.env.current_random,
230243
block_gas_limit: test.env.current_gas_limit,
231244
block_base_fee_per_gas: test.env.current_base_fee.unwrap_or_default(),
245+
blob_base_fee_per_gas: U256::zero(),
246+
blob_versioned_hashes: test
247+
.transaction
248+
.blob_versioned_hashes
249+
.clone()
250+
.unwrap_or_default(),
232251
chain_id: U256::one(),
233252
};
234253

@@ -366,11 +385,11 @@ pub fn run_test(
366385

367386
let state_root = crate::hash::state_root(&run_backend);
368387

369-
if test.post.expect_exception.is_some() {
388+
if let Some(expect_exception) = test.post.expect_exception {
370389
if run_result.is_err() {
371390
return Ok(());
372391
} else {
373-
return Err(TestError::ExpectException.into());
392+
return Err(TestError::ExpectException(expect_exception).into());
374393
}
375394
}
376395

@@ -421,6 +440,7 @@ pub fn run_test(
421440
to: test.transaction.to,
422441
value: vec![test.transaction.value],
423442
access_lists: Some(vec![Some(test.transaction.access_list)]),
443+
blob_versioned_hashes: test.transaction.blob_versioned_hashes,
424444
},
425445
},
426446
);

0 commit comments

Comments
 (0)