diff --git a/Cargo.lock b/Cargo.lock index ad4cb7b..338d42a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -276,7 +276,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -433,7 +433,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -505,9 +505,9 @@ dependencies = [ [[package]] name = "cranelift" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf6f4efd94998d1260cea289fe1fbe5ab0fc0df463069849f3837b84c70ee807" +checksum = "89499de5195c24137204b43c71edfcd5e05eacc9bbcceae21833f1fc2085fbad" dependencies = [ "cranelift-codegen", "cranelift-frontend", @@ -515,18 +515,18 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a535eb1cf5a6003197dc569320c40c1cb2d2f97ef5d5348eebf067f20957381" +checksum = "5b3775cc6cc00c90d29eebea55feedb2b0168e23f5415bab7859c4004d7323d1" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11b5066db32cec1492573827183af2142d2d88fe85a83cfc9e73f0f63d3788d4" +checksum = "637f3184ba5bfa48d425bad1d2e4faf5fcf619f5e0ca107edc6dc02f589d4d74" dependencies = [ "bumpalo", "cranelift-bforest", @@ -545,39 +545,39 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64942e5774308e835fbad4dd25f253105412c90324631910e1ec27963147bddb" +checksum = "e4b35b8240462341d94d31aab807cad704683988708261aecae3d57db48b7212" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c39c33db9a86dd6d8d04166a10c53deb477aeea3500eaaefca682e4eda9bb986" +checksum = "8f3cd1555aa9df1d6d8375732de41b4cb0d787006948d55b6d004d521e9efeb0" [[package]] name = "cranelift-control" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7fc4937613aea3156a0538800a17bf56f345a5da2e79ae3df58488c93d867f" +checksum = "14b31a562a10e98ab148fa146801e20665c5f9eda4fce9b2c5a3836575887d74" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f85575e79a153ce1ddbfb7fe1813519b4bfe1eb200cc9c8353b45ad123ae4d36" +checksum = "af1e0467700a3f4fccf5feddbaebdf8b0eb82535b06a9600c4bc5df40872e75d" [[package]] name = "cranelift-frontend" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbc31d6c0ab2249fe0c21e988256b42f5f401ab2673b4fc40076c82a698bdfb9" +checksum = "6cb918ee2c23939262efd1b99d76a21212ac7bd35129582133e21a22a6ff0467" dependencies = [ "cranelift-codegen", "log", @@ -587,15 +587,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc14f37e3314c0e4c53779c2f46753bf242efff76ee9473757a1fff3b495ad37" +checksum = "966e4cfb23cf6d7f1d285d53a912baaffc5f06bcd9c9b0a2d8c66a184fae534b" [[package]] name = "cranelift-jit" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfdd1942f3233176a68c285380dbc84ff0440246a1bce308611c0a385b56ab18" +checksum = "66823211608f4966518d23f57571d8771c55430b626a8ab377479b24a4535f40" dependencies = [ "anyhow", "cranelift-codegen", @@ -613,9 +613,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121b2b5a16912554a1b9aace75b9b21eca49f28e33cbfbad4786dd9bc5361a5c" +checksum = "cec3c5879608f8073782974e2c6dda461eb4038c754e1ab02904eb94a0ee0e9f" dependencies = [ "anyhow", "cranelift-codegen", @@ -624,9 +624,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.106.0" +version = "0.106.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ea5375f76ab31f9800a23fb2b440810286a6f669a3eb467cdd7ff255ea64268" +checksum = "bea803aadfc4aabdfae7c3870f1b1f6dd4332f4091859e9758ef5fca6bf8cc87" dependencies = [ "cranelift-codegen", "libc", @@ -773,7 +773,7 @@ checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -970,7 +970,7 @@ checksum = "4fa4d8d74483041a882adaa9a29f633253a66dde85055f0495c121620ac484b2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -1196,9 +1196,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "pest" -version = "2.7.8" +version = "2.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f8023d0fb78c8e03784ea1c7f3fa36e68a723138990b8d5a47d916b651e7a8" +checksum = "311fb059dee1a7b802f036316d790138c613a4e8b180c822e3925a662e9f0c95" dependencies = [ "memchr", "thiserror", @@ -1442,8 +1442,8 @@ dependencies = [ [[package]] name = "revm-interpreter" -version = "3.4.0" -source = "git+https://github.com/bluealloy/revm#b3220c64c0a542e0ef0f99e9bcf8798fc0cf64d5" +version = "4.0.0" +source = "git+https://github.com/bluealloy/revm?rev=4d64bbcd241540f90f3a6ab2285b6fe6f8febb1f#4d64bbcd241540f90f3a6ab2285b6fe6f8febb1f" dependencies = [ "revm-primitives", ] @@ -1529,8 +1529,8 @@ dependencies = [ [[package]] name = "revm-primitives" -version = "3.1.0" -source = "git+https://github.com/bluealloy/revm#b3220c64c0a542e0ef0f99e9bcf8798fc0cf64d5" +version = "3.1.1" +source = "git+https://github.com/bluealloy/revm?rev=4d64bbcd241540f90f3a6ab2285b6fe6f8febb1f#4d64bbcd241540f90f3a6ab2285b6fe6f8febb1f" dependencies = [ "alloy-primitives", "auto_impl", @@ -1675,7 +1675,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -1734,9 +1734,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "strsim" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" @@ -1751,9 +1751,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.57" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a6ae1e52eb25aab8f3fb9fca13be982a373b8f1157ca14b897a825ba4a2d35" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -1789,7 +1789,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -1857,7 +1857,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -2000,7 +2000,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", "wasm-bindgen-shared", ] @@ -2022,7 +2022,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2035,9 +2035,9 @@ checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasmtime-jit-icache-coherence" -version = "19.0.0" +version = "19.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2796e4b4989db62899d2117e1e0258b839d088c044591b14e3a0396e7b3ae53a" +checksum = "59c48eb4223d6556ffbf3decb146d0da124f1fd043f41c98b705252cb6a5c186" dependencies = [ "cfg-if", "libc", @@ -2186,7 +2186,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] [[package]] @@ -2206,5 +2206,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.57", + "syn 2.0.58", ] diff --git a/Cargo.toml b/Cargo.toml index 9555379..ca4e10c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,8 +40,8 @@ revm-jit-cranelift = { version = "0.1.0", path = "crates/revm-jit-cranelift", de revm-jit-llvm = { version = "0.1.0", path = "crates/revm-jit-llvm", default-features = false } alloy-primitives = { version = "0.7.0", default-features = false } -revm-primitives = { version = "3.1.0", default-features = false } -revm-interpreter = { version = "3.4.0", default-features = false } +revm-primitives = { version = "3.1.1", default-features = false } +revm-interpreter = { version = "4.0.0", default-features = false } ruint = { version = "1.12.1", default-features = false } eyre = "0.6" @@ -51,5 +51,5 @@ tracing-error = "0.2" tracing-subscriber = "0.3" [patch.crates-io] -revm-primitives = { git = "https://github.com/bluealloy/revm" } -revm-interpreter = { git = "https://github.com/bluealloy/revm" } +revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "4d64bbcd241540f90f3a6ab2285b6fe6f8febb1f" } +revm-interpreter = { git = "https://github.com/bluealloy/revm", rev = "4d64bbcd241540f90f3a6ab2285b6fe6f8febb1f" } diff --git a/crates/revm-jit-builtins/src/lib.rs b/crates/revm-jit-builtins/src/lib.rs index 7329cf6..5236c35 100644 --- a/crates/revm-jit-builtins/src/lib.rs +++ b/crates/revm-jit-builtins/src/lib.rs @@ -19,8 +19,8 @@ use revm_interpreter::{ }; use revm_jit_context::{EvmContext, EvmWord}; use revm_primitives::{ - spec_to_generic, Bytes, CreateScheme, Log, LogData, SpecId, BLOCK_HASH_HISTORY, KECCAK_EMPTY, - MAX_INITCODE_SIZE, U256, + Bytes, CreateScheme, Log, LogData, SpecId, BLOCK_HASH_HISTORY, KECCAK_EMPTY, MAX_INITCODE_SIZE, + U256, }; #[cfg(feature = "ir")] @@ -98,8 +98,7 @@ pub unsafe extern "C" fn __revm_jit_builtin_exp( spec_id: SpecId, ) -> InstructionResult { let exponent = exponent_ptr.to_u256(); - // TODO: SpecId - gas_opt!(ecx, spec_to_generic!(spec_id, rgas::exp_cost::(exponent))); + gas_opt!(ecx, rgas::exp_cost(spec_id, exponent)); *exponent_ptr = base.to_u256().pow(exponent).into(); InstructionResult::Continue } @@ -135,7 +134,7 @@ pub unsafe extern "C" fn __revm_jit_builtin_balance( let (balance, is_cold) = try_host!(ecx.host.balance(address.to_address())); *address = balance.into(); let gas = if spec_id.is_enabled_in(SpecId::ISTANBUL) { - spec_to_generic!(spec_id, rgas::account_access_gas::(is_cold)) + rgas::account_access_gas(spec_id, is_cold) } else if spec_id.is_enabled_in(SpecId::TANGERINE) { 400 } else { @@ -194,8 +193,7 @@ pub unsafe extern "C" fn __revm_jit_builtin_extcodecopy( ) -> InstructionResult { let (code, is_cold) = try_host!(ecx.host.code(address.to_address())); let len = tri!(usize::try_from(len)); - // TODO: SpecId - gas_opt!(ecx, spec_to_generic!(spec_id, rgas::extcodecopy_cost::(len as u64, is_cold))); + gas_opt!(ecx, rgas::extcodecopy_cost(spec_id, len as u64, is_cold)); if len != 0 { let memory_offset = try_into_usize!(memory_offset.as_u256()); let code_offset = code_offset.to_u256(); @@ -349,7 +347,7 @@ pub unsafe extern "C" fn __revm_jit_builtin_sload( ) -> InstructionResult { let address = ecx.contract.address; let (res, is_cold) = try_opt!(ecx.host.sload(address, index.to_u256())); - gas!(ecx, spec_to_generic!(spec_id, rgas::sload_cost::(is_cold))); + gas!(ecx, rgas::sload_cost(spec_id, is_cold)); *index = res.into(); InstructionResult::Continue } @@ -363,16 +361,8 @@ pub unsafe extern "C" fn __revm_jit_builtin_sstore( let SStoreResult { original_value: original, present_value: old, new_value: new, is_cold } = try_opt!(ecx.host.sstore(ecx.contract.address, index.to_u256(), value.to_u256())); - // TODO: SpecId - gas_opt!( - ecx, - spec_to_generic!( - spec_id, - rgas::sstore_cost::(original, old, new, ecx.gas.remaining(), is_cold) - ) - ); - ecx.gas - .record_refund(spec_to_generic!(spec_id, rgas::sstore_refund::(original, old, new))); + gas_opt!(ecx, rgas::sstore_cost(spec_id, original, old, new, ecx.gas.remaining(), is_cold)); + ecx.gas.record_refund(rgas::sstore_refund(spec_id, original, old, new)); InstructionResult::Continue } @@ -431,10 +421,17 @@ pub unsafe extern "C" fn __revm_jit_builtin_log( #[no_mangle] pub unsafe extern "C" fn __revm_jit_builtin_create( ecx: &mut EvmContext<'_>, - rev![value, code_offset, len, salt]: &mut [EvmWord; 4], + sp: *mut EvmWord, spec_id: SpecId, create_kind: CreateKind, ) -> InstructionResult { + let len = match create_kind { + CreateKind::Create => 3, + CreateKind::Create2 => 4, + }; + let mut sp = sp.add(len); + pop!(sp; value, code_offset, len); + let len = tri!(usize::try_from(len)); let code = if len != 0 { if spec_id.is_enabled_in(SpecId::SHANGHAI) { @@ -460,9 +457,10 @@ pub unsafe extern "C" fn __revm_jit_builtin_create( }; let is_create2 = create_kind == CreateKind::Create2; - gas_opt!(ecx, if is_create2 { rgas::create2_cost(len) } else { Some(rgas::CREATE) }); + gas_opt!(ecx, if is_create2 { rgas::create2_cost(len as u64) } else { Some(rgas::CREATE) }); let scheme = if is_create2 { + pop!(sp; salt); CreateScheme::Create2 { salt: salt.to_u256() } } else { CreateScheme::Create @@ -499,16 +497,8 @@ pub unsafe extern "C" fn __revm_jit_builtin_call( CallKind::DelegateCall | CallKind::StaticCall => 6, }; let mut sp = sp.add(len); - macro_rules! pop { - ($($x:ident),* $(,)?) => { - $( - sp = sp.sub(1); - let $x = &mut *sp; - )* - }; - } - pop!(local_gas_limit, to); + pop!(sp; local_gas_limit, to); let local_gas_limit = local_gas_limit.to_u256(); let to = to.to_address(); @@ -519,7 +509,7 @@ pub unsafe extern "C" fn __revm_jit_builtin_call( let value = match call_kind { CallKind::Call | CallKind::CallCode => { - pop!(value); + pop!(sp; value); let value = value.to_u256(); if matches!(call_kind, CallKind::Call) && ecx.is_static && value != U256::ZERO { return InstructionResult::CallNotAllowedInsideStatic; @@ -529,7 +519,7 @@ pub unsafe extern "C" fn __revm_jit_builtin_call( CallKind::DelegateCall | CallKind::StaticCall => U256::ZERO, }; - pop!(in_offset, in_len, out_offset, out_len); + pop!(sp; in_offset, in_len, out_offset, out_len); let in_len = try_into_usize!(in_len.to_u256()); let input = if in_len != 0 { @@ -593,18 +583,15 @@ pub unsafe extern "C" fn __revm_jit_builtin_call( let (is_cold, exist) = try_host!(ecx.host.load_account(to)); let is_new = !exist; - // TODO: SpecId gas!( ecx, - spec_to_generic!( + rgas::call_cost( spec_id, - rgas::call_cost::( - value != U256::ZERO, - is_new, - is_cold, - matches!(call_kind, CallKind::Call | CallKind::CallCode), - matches!(call_kind, CallKind::Call | CallKind::StaticCall), - ) + value != U256::ZERO, + is_new, + is_cold, + matches!(call_kind, CallKind::Call | CallKind::CallCode), + matches!(call_kind, CallKind::Call | CallKind::StaticCall), ) ); @@ -671,8 +658,7 @@ pub unsafe extern "C" fn __revm_jit_builtin_selfdestruct( if !spec_id.is_enabled_in(SpecId::LONDON) && !res.previously_destroyed { ecx.gas.record_refund(rgas::SELFDESTRUCT); } - // TODO: SpecId - gas!(ecx, spec_to_generic!(spec_id, rgas::selfdestruct_cost::(res))); + gas!(ecx, rgas::selfdestruct_cost(spec_id, res)); InstructionResult::Continue } diff --git a/crates/revm-jit-builtins/src/macros.rs b/crates/revm-jit-builtins/src/macros.rs index 51e6d18..d638c21 100644 --- a/crates/revm-jit-builtins/src/macros.rs +++ b/crates/revm-jit-builtins/src/macros.rs @@ -58,6 +58,15 @@ macro_rules! read_words { }; } +macro_rules! pop { + ($sp:expr; $($x:ident),* $(,)?) => { + $( + $sp = $sp.sub(1); + let $x = &mut *$sp; + )* + }; +} + macro_rules! try_into_usize { ($x:expr) => { match $x { diff --git a/crates/revm-jit/src/compiler.rs b/crates/revm-jit/src/compiler.rs index 3136759..3e25d37 100644 --- a/crates/revm-jit/src/compiler.rs +++ b/crates/revm-jit/src/compiler.rs @@ -2715,7 +2715,7 @@ mod tests { scheme: primitives::CreateScheme::Create, value: 0x42_U256, init_code: Bytes::copy_from_slice(&0x69_U256.to_be_bytes::<32>()), - gas_limit: 66921, + gas_limit: 66917, }) }, }), @@ -2733,7 +2733,7 @@ mod tests { scheme: primitives::CreateScheme::Create2 { salt: 100_U256 }, value: 0x42_U256, init_code: Bytes::copy_from_slice(&0x69_U256.to_be_bytes::<32>()), - gas_limit: 66921, + gas_limit: 66908, }) }, }), @@ -2763,7 +2763,7 @@ mod tests { value: 5_U256, }, input: Bytes::copy_from_slice(&[0; 3]), - gas_limit: 7, + gas_limit: gas::CALL_STIPEND + 7, context: CallContext { address: Address::from_word(6_U256.into()), caller: DEF_ADDR, @@ -2772,7 +2772,7 @@ mod tests { scheme: interpreter::CallScheme::Call, }, is_static: false, - return_memory_offset: 1..1+2, + return_memory_offset: 2..2+1, }), }, }), @@ -2783,15 +2783,15 @@ mod tests { bytecode: &[op::PUSH1, 0x69, op::PUSH0, op::MSTORE, op::PUSH1, 32, op::PUSH0, op::RETURN], expected_return: InstructionResult::Return, expected_memory: &0x69_U256.to_be_bytes::<32>(), - expected_gas: 3 + 2 + (3 + gas::memory_gas(1)) + 3 + 2 + 0, + expected_gas: 3 + 2 + (3 + gas::memory_gas(1)) + 3 + 2, expected_next_action: InterpreterAction::Return { result: InterpreterResult { result: InstructionResult::Return, output: Bytes::copy_from_slice(&0x69_U256.to_be_bytes::<32>()), gas: { let mut gas = Gas::new(DEF_GAS_LIMIT); - let cost = 3 + 2 + (3 + gas::memory_gas(1)) + 3 + 2 + 0; - assert!(gas.record_cost(cost)); + assert!(gas.record_cost(3 + 2 + 3 + 3 + 2)); + assert!(gas.record_memory(gas::memory_gas(1))); gas }, }, @@ -2801,15 +2801,15 @@ mod tests { bytecode: &[op::PUSH1, 0x69, op::PUSH0, op::MSTORE, op::PUSH1, 32, op::PUSH0, op::REVERT], expected_return: InstructionResult::Revert, expected_memory: &0x69_U256.to_be_bytes::<32>(), - expected_gas: 3 + 2 + (3 + gas::memory_gas(1)) + 3 + 2 + 0, + expected_gas: 3 + 2 + (3 + gas::memory_gas(1)) + 3 + 2, expected_next_action: InterpreterAction::Return { result: InterpreterResult { - result: InstructionResult::Return, + result: InstructionResult::Revert, output: Bytes::copy_from_slice(&0x69_U256.to_be_bytes::<32>()), gas: { let mut gas = Gas::new(DEF_GAS_LIMIT); - let cost = 3 + 2 + (3 + gas::memory_gas(1)) + 3 + 2 + 0; - assert!(gas.record_cost(cost)); + assert!(gas.record_cost(3 + 2 + 3 + 3 + 2)); + assert!(gas.record_memory(gas::memory_gas(1))); gas }, }, @@ -3137,7 +3137,7 @@ mod tests { stack_does_not_match_interpreter, expected_memory, expected_gas, - expected_next_action: _, // TODO + ref expected_next_action, assert_host, assert_ecx, } = *test_case; @@ -3153,19 +3153,24 @@ mod tests { let mut interpreter = ecx.to_interpreter(Default::default()); let memory = interpreter.take_memory(); let mut int_host = TestHost::new(); - interpreter.run(memory, &table, &mut int_host); + + let interpreter_action = interpreter.run(memory, &table, &mut int_host); + assert_eq!( interpreter.instruction_result, expected_return, "interpreter return value mismatch" ); + if !stack_does_not_match_interpreter { assert_eq!(interpreter.stack.data(), expected_stack, "interpreter stack mismatch"); } + assert_eq!( MemDisplay(interpreter.shared_memory.context_memory()), MemDisplay(expected_memory), "interpreter memory mismatch" ); + let mut expected_gas = expected_gas; if expected_gas == GAS_WHAT_THE_INTERPRETER_SAYS { println!("asked for interpreter gas: {}", interpreter.gas.spent()); @@ -3173,25 +3178,53 @@ mod tests { } else { assert_eq!(interpreter.gas.spent(), expected_gas, "interpreter gas mismatch"); } + + // Check next action only if it's not the default. This should be `None` but `run` + // returns a default value. + if !(expected_next_action.is_none() + && interpreter_action + == (InterpreterAction::Return { + result: InterpreterResult { + result: interpreter.instruction_result, + output: Bytes::new(), + gas: interpreter.gas, + }, + })) + { + assert_eq!( + interpreter_action, *expected_next_action, + "interpreter next action mismatch" + ); + } + if let Some(assert_host) = assert_host { assert_host(&int_host); } // JIT. let actual_return = unsafe { f.call(Some(&mut stack), Some(&mut stack_len), ecx) }; + assert_eq!(actual_return, expected_return, "return value mismatch"); + let actual_stack = stack.as_slice().iter().take(stack_len).map(|x| x.to_u256()).collect::>(); + assert_eq!(actual_stack, *expected_stack, "stack mismatch"); + assert_eq!( MemDisplay(ecx.memory.context_memory()), MemDisplay(expected_memory), "interpreter memory mismatch" ); + assert_eq!(ecx.gas.spent(), expected_gas, "gas mismatch"); + + assert_eq!(*ecx.next_action, *expected_next_action, "next action mismatch"); + if let Some(assert_host) = assert_host { assert_host(ecx.host.downcast_mut().unwrap()); } + if let Some(assert_ecx) = assert_ecx { assert_ecx(ecx); }