From 9d6b43638783d98749785e9d76f0f30a3f5b8cb4 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Mon, 16 Nov 2026 16:09:24 +0100 Subject: [PATCH 1/3] kona,op-reth: pin the fork-boundary execution rules op-e2e/opgeth tested The deleted op-e2e/opgeth tests pinned fork-boundary execution rules on op-geth. Several had no op-reth or kona equivalent: - TestForkActivationEVMRules activates Canyon, Ecotone, Fjord and Isthmus after genesis and checks PUSH0, TSTORE, a failing KZG proof, P256VERIFY and valid and malformed BLS12-381 inputs before and after the activation block, then proves the blocks with kona. - A kona-client test checks that a precompile input the host rejects gives the same halt as the provider op-reth runs, at every spec. - TestDepositGasParity checks depositNonce, depositReceiptVersion and the nonce increment, and adds a deposit whose value exceeds the sender's balance plus mint. - TestPrecompiles gains P256VERIFY. The op-reth doc comment records why the OP payload-attribute checks answer -32602 rather than op-geth's -38003. Co-Authored-By: Claude Opus 5.5 --- .../fpvm_evm/precompiles/kzg_point_eval.rs | 14 +- .../src/fpvm_evm/precompiles/provider.rs | 201 ++++++++++++-- .../src/fpvm_evm/precompiles/test_utils.rs | 18 ++ rust/kona/tests/proofs/deposit_gas_test.go | 112 +++++++- rust/kona/tests/proofs/fixtures.go | 7 + .../tests/proofs/fork_activation_evm_test.go | 246 ++++++++++++++++++ rust/op-reth/crates/node/src/engine.rs | 8 + 7 files changed, 568 insertions(+), 38 deletions(-) create mode 100644 rust/kona/tests/proofs/fork_activation_evm_test.go diff --git a/rust/kona/bin/client/src/fpvm_evm/precompiles/kzg_point_eval.rs b/rust/kona/bin/client/src/fpvm_evm/precompiles/kzg_point_eval.rs index e5c3220099e..52af758d736 100644 --- a/rust/kona/bin/client/src/fpvm_evm/precompiles/kzg_point_eval.rs +++ b/rust/kona/bin/client/src/fpvm_evm/precompiles/kzg_point_eval.rs @@ -46,21 +46,13 @@ where mod test { use super::*; use crate::fpvm_evm::precompiles::test_utils::{ - execute_native_precompile, test_accelerated_precompile, - test_accelerated_precompile_capture_hint, + VALID_KZG_EVALUATION, execute_native_precompile, kzg_point_eval_input, + test_accelerated_precompile, test_accelerated_precompile_capture_hint, }; - use alloy_eips::eip4844::VERSIONED_HASH_VERSION_KZG; use alloy_primitives::hex; - use sha2::{Digest, Sha256}; fn valid_kzg_input() -> Vec { - let commitment = hex!("8f59a8d2a1a625a17f3fea0fe5eb8c896db3764f3185481bc22f91b4aaffcca25f26936857bc3a7c2539ea8ec3a952b7").to_vec(); - let mut versioned_hash = Sha256::digest(&commitment).to_vec(); - versioned_hash[0] = VERSIONED_HASH_VERSION_KZG; - let z = hex!("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000").to_vec(); - let y = hex!("1522a4a7f34e1ea350ae07c29c96c7e79655aa926122e95fe69fcbd932ca49e9").to_vec(); - let proof = hex!("a62ad71d14c5719385c0686f1871430475bf3a00f0aa3f7b8dd99a9abc2160744faf0070725e00b60ad9a026a15b1a8c").to_vec(); - [versioned_hash, z, y, commitment, proof].concat() + kzg_point_eval_input(VALID_KZG_EVALUATION) } #[tokio::test(flavor = "multi_thread")] diff --git a/rust/kona/bin/client/src/fpvm_evm/precompiles/provider.rs b/rust/kona/bin/client/src/fpvm_evm/precompiles/provider.rs index 90b348d05ba..3df1dd3e09e 100644 --- a/rust/kona/bin/client/src/fpvm_evm/precompiles/provider.rs +++ b/rust/kona/bin/client/src/fpvm_evm/precompiles/provider.rs @@ -341,7 +341,9 @@ where #[cfg(test)] mod test { use super::*; + use crate::fpvm_evm::precompiles::test_utils::{VALID_KZG_EVALUATION, kzg_point_eval_input}; use alloy_op_evm::{OpEvmContext, OpTx}; + use alloy_primitives::hex; use kona_preimage::{HintWriterClient, PreimageOracleClient}; use op_revm::{L1BlockInfo, OpSpecId, OpTransaction}; use revm::{ @@ -596,6 +598,189 @@ mod test { } } + /// A call that passes every check an accelerated precompile makes itself, gas and length, but + /// whose input the host rejects. The client learns of the failure only from the host's answer. + struct HostRejectedCall { + name: &'static str, + address: Address, + /// The first spec that accelerates `address`. + first_spec: OpSpecId, + input: Vec, + } + + /// One host-rejected call for each accelerated precompile whose host can reject an input. + /// ecrecover is not one: revm returns no output for a bad signature instead of failing, and + /// the client maps any host failure to the same empty output. + fn host_rejected_calls() -> Vec { + let mut kzg_wrong_evaluation = VALID_KZG_EVALUATION; + kzg_wrong_evaluation[31] ^= 1; + + // G1 point (1, 3) is not on y^2 = x^3 + 3; the G2 point is the point at infinity. + let mut bn254_off_curve = vec![0u8; bn254::PAIR_ELEMENT_LEN]; + bn254_off_curve[31] = 1; + bn254_off_curve[63] = 3; + + vec![ + HostRejectedCall { + name: "bn254 pairing: G1 point not on the curve", + address: bn254::pair::ADDRESS, + first_spec: OpSpecId::BEDROCK, + input: bn254_off_curve, + }, + HostRejectedCall { + name: "kzg point evaluation: proof does not verify", + address: KZG_POINT_EVAL_ADDR, + first_spec: OpSpecId::ECOTONE, + input: kzg_point_eval_input(kzg_wrong_evaluation), + }, + // One failure vector per BLS12-381 precompile from the EIP-2537 test suite, named as + // in kona/sp1/crates/bls12-381-check/testdata/eip2537. + HostRejectedCall { + name: "bls_g1add_point_not_on_curve", + address: bls12_381_const::G1_ADD_ADDRESS, + first_spec: OpSpecId::ISTHMUS, + input: hex!("0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb00000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a2100000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21").to_vec(), + }, + HostRejectedCall { + name: "bls_g2add_invalid_field_element", + address: bls12_381_const::G2_ADD_ADDRESS, + first_spec: OpSpecId::ISTHMUS, + input: hex!("000000000000000000000000000000001c4bb49d2a0ef12b7123acdd7110bd292b5bc659edc54dc21b81de057194c79b2a5803255959bbef8e7f56c8c12168630000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451").to_vec(), + }, + HostRejectedCall { + name: "bls_g1msm_point_not_on_curve", + address: bls12_381_const::G1_MSM_ADDRESS, + first_spec: OpSpecId::ISTHMUS, + input: hex!("0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb00000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a210000000000000000000000000000000000000000000000000000000000000002").to_vec(), + }, + HostRejectedCall { + name: "bls_g2msm_invalid_field_element", + address: bls12_381_const::G2_MSM_ADDRESS, + first_spec: OpSpecId::ISTHMUS, + input: hex!("000000000000000000000000000000001c4bb49d2a0ef12b7123acdd7110bd292b5bc659edc54dc21b81de057194c79b2a5803255959bbef8e7f56c8c12168630000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000002").to_vec(), + }, + HostRejectedCall { + name: "bls_invalid_fq_element", + address: bls12_381_const::MAP_FP_TO_G1_ADDRESS, + first_spec: OpSpecId::ISTHMUS, + input: hex!("000000000000000000000000000000002f6d9c5465982c0421b61e74579709b3b5b91e57bdd4f6015742b4ff301abb7ef895b9cce00c33c7d48f8e5fa4ac09ae").to_vec(), + }, + HostRejectedCall { + name: "bls_mapg2_invalid_fq_element", + address: bls12_381_const::MAP_FP2_TO_G2_ADDRESS, + first_spec: OpSpecId::ISTHMUS, + input: hex!("0000000000000000000000000000000021366f100476ce8d3be6cfc90d59fe13349e388ed12b6dd6dc31ccd267ff000e2c993a063ca66beced06f804d4b8e5af0000000000000000000000000000000002829ce3c021339ccb5caf3e187f6370e1e2a311dec9b75363117063ab2015603ff52c3d3b98f19c2f65575e99e8b78c").to_vec(), + }, + HostRejectedCall { + name: "bls_pairing_e(G1_not_in_correct_subgroup,-G2)=e(-G1,G2)", + address: bls12_381_const::PAIRING_ADDRESS, + first_spec: OpSpecId::ISTHMUS, + input: hex!("000000000000000000000000000000000123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef00000000000000000000000000000000193fb7cedb32b2c3adc06ec11a96bc0d661869316f5e4a577a9f7c179593987beb4fb2ee424dbb2f5dd891e228b46c4a00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17f9ee3837a55024f78c71363275a75d75d86bab79f74782aa0000000000000000000000000000000013fa4d4a0ad8b1ce186ed5061789213d993923066dddaf1040bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed").to_vec(), + }, + ] + } + + /// For an input the host rejects, an accelerated precompile has to return what the + /// [`EthPrecompiles`] it wraps, the one op-reth runs, returns for the same call: a halt that + /// spends all of the call's gas. Any other status or gas makes kona and op-reth compute + /// different receipts for the same block. Each case runs at every spec from the one that + /// first accelerates it, because a fork can swap in its own accelerated function, and with + /// and without a reservoir on the call. + #[tokio::test(flavor = "multi_thread")] + async fn test_host_rejected_input_matches_wrapped_provider() { + use crate::fpvm_evm::precompiles::test_utils::test_accelerated_precompile; + + const SPECS: [OpSpecId; 11] = [ + OpSpecId::BEDROCK, + OpSpecId::REGOLITH, + OpSpecId::CANYON, + OpSpecId::ECOTONE, + OpSpecId::FJORD, + OpSpecId::GRANITE, + OpSpecId::HOLOCENE, + OpSpecId::ISTHMUS, + OpSpecId::JOVIAN, + OpSpecId::KARST, + OpSpecId::LAGOON, + ]; + const GAS_LIMIT: u64 = 1_000_000; + + test_accelerated_precompile(|hint_writer, oracle_reader| { + let mut ctx = create_test_context(); + for spec in SPECS { + let mut precompiles = OpFpvmPrecompiles::new_with_spec( + spec, + hint_writer.clone(), + oracle_reader.clone(), + ); + let mut wrapped = precompiles.inner.clone(); + + for HostRejectedCall { name, address, first_spec, input } in host_rejected_calls() { + if !spec.is_enabled_in(first_spec) { + continue; + } + + // Without a host rejection the case would test a check the client makes + // itself, not the host-failure path. + let accelerated = precompiles + .accelerated_precompiles + .get(&address) + .copied() + .unwrap_or_else(|| panic!("{name}: not accelerated at {spec:?}")); + let res = accelerated(&input, GAS_LIMIT, hint_writer, oracle_reader); + assert!( + matches!(&res, Err(revm::precompile::PrecompileHalt::Other(msg)) if msg.contains("Error executing precompile in host")), + "{name} at {spec:?}: expected the host to reject the input, got {res:?}" + ); + + for reservoir in [0, 4_096] { + let call_inputs = create_call_inputs_with_reservoir( + address, + input.clone().into(), + GAS_LIMIT, + reservoir, + ); + let ours = precompiles.run(&mut ctx, &call_inputs).unwrap(); + let theirs = PrecompileProvider::::run( + &mut wrapped, + &mut ctx, + &call_inputs, + ) + .unwrap(); + + assert!( + theirs.as_ref().is_some_and(|r| r.result == InstructionResult::PrecompileError), + "{name} at {spec:?}: the wrapped provider must reject the input, got {theirs:?}" + ); + assert_eq!( + ours, theirs, + "{name} at {spec:?} with reservoir {reservoir}: diverged from the wrapped provider" + ); + } + } + } + + // Every accelerated precompile but ecrecover has a case, so a newly accelerated one + // fails here until it gets one. + let lagoon = OpFpvmPrecompiles::new_with_spec( + OpSpecId::LAGOON, + hint_writer.clone(), + oracle_reader.clone(), + ); + let mut accelerated: Vec<_> = lagoon + .accelerated_precompiles + .keys() + .copied() + .filter(|address| *address != ECRECOVER_ADDR) + .collect(); + accelerated.sort(); + let mut covered: Vec<_> = host_rejected_calls().iter().map(|c| c.address).collect(); + covered.sort(); + assert_eq!(accelerated, covered, "accelerated precompiles without a host-rejected call"); + }) + .await; + } + #[test] fn test_run_nonexistent_precompile() { let (hint_chan, preimage_chan) = ( @@ -801,13 +986,10 @@ mod test { #[tokio::test(flavor = "multi_thread")] async fn test_provider_dispatches_l1_precompile_gas() { - use alloy_eips::eip4844::VERSIONED_HASH_VERSION_KZG; - use alloy_primitives::hex; use revm::precompile::{ bls12_381_const::{G1_ADD_INPUT_LENGTH, G2_ADD_INPUT_LENGTH}, bn254::PAIR_ELEMENT_LEN, }; - use sha2::{Digest, Sha256}; // For each of the four precompiles whose L1 cost diverges from the L2 charge, drive // `OpFpvmPrecompiles::run` at JOVIAN and assert the hint payload carries the L1 cost. @@ -816,20 +998,9 @@ mod test { // if the per-leaf tests still pass. Current L1 values reflect EIP-7904. // KZG: 0x0a, valid input → expect 89_363 - let kzg_input: Bytes = { - let commitment = hex!("8f59a8d2a1a625a17f3fea0fe5eb8c896db3764f3185481bc22f91b4aaffcca25f26936857bc3a7c2539ea8ec3a952b7").to_vec(); - let mut versioned_hash = Sha256::digest(&commitment).to_vec(); - versioned_hash[0] = VERSIONED_HASH_VERSION_KZG; - let z = - hex!("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000").to_vec(); - let y = - hex!("1522a4a7f34e1ea350ae07c29c96c7e79655aa926122e95fe69fcbd932ca49e9").to_vec(); - let proof = hex!("a62ad71d14c5719385c0686f1871430475bf3a00f0aa3f7b8dd99a9abc2160744faf0070725e00b60ad9a026a15b1a8c").to_vec(); - [versioned_hash, z, y, commitment, proof].concat().into() - }; run_dispatch_and_assert_oracle_gas( super::super::kzg_point_eval::KZG_POINT_EVAL_ADDR, - kzg_input, + kzg_point_eval_input(VALID_KZG_EVALUATION).into(), 89_363, ) .await; diff --git a/rust/kona/bin/client/src/fpvm_evm/precompiles/test_utils.rs b/rust/kona/bin/client/src/fpvm_evm/precompiles/test_utils.rs index 59d2186e113..1be0583ce31 100644 --- a/rust/kona/bin/client/src/fpvm_evm/precompiles/test_utils.rs +++ b/rust/kona/bin/client/src/fpvm_evm/precompiles/test_utils.rs @@ -76,6 +76,24 @@ async fn test_accelerated_precompile_inner( }); } +/// The claimed evaluation `y` at which the proof in [`kzg_point_eval_input`] verifies. +pub(crate) const VALID_KZG_EVALUATION: [u8; 32] = + alloy_primitives::hex!("1522a4a7f34e1ea350ae07c29c96c7e79655aa926122e95fe69fcbd932ca49e9"); + +/// A KZG point-evaluation input claiming that the blob evaluates to `y`. +pub(crate) fn kzg_point_eval_input(y: [u8; 32]) -> Vec { + use alloy_eips::eip4844::VERSIONED_HASH_VERSION_KZG; + use alloy_primitives::hex; + use sha2::{Digest, Sha256}; + + let commitment = hex!("8f59a8d2a1a625a17f3fea0fe5eb8c896db3764f3185481bc22f91b4aaffcca25f26936857bc3a7c2539ea8ec3a952b7").to_vec(); + let mut versioned_hash = Sha256::digest(&commitment).to_vec(); + versioned_hash[0] = VERSIONED_HASH_VERSION_KZG; + let z = hex!("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000").to_vec(); + let proof = hex!("a62ad71d14c5719385c0686f1871430475bf3a00f0aa3f7b8dd99a9abc2160744faf0070725e00b60ad9a026a15b1a8c").to_vec(); + [versioned_hash, z, y.to_vec(), commitment, proof].concat() +} + /// Executes a precompile on [`revm`]. pub(crate) fn execute_native_precompile>( address: Address, diff --git a/rust/kona/tests/proofs/deposit_gas_test.go b/rust/kona/tests/proofs/deposit_gas_test.go index 9f1576933b8..10813b8eaf7 100644 --- a/rust/kona/tests/proofs/deposit_gas_test.go +++ b/rust/kona/tests/proofs/deposit_gas_test.go @@ -5,6 +5,7 @@ import ( "testing" batcherFlags "github.com/ethereum-optimism/optimism/op-batcher/flags" + optypes "github.com/ethereum-optimism/optimism/op-core/types" actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers" "github.com/ethereum-optimism/optimism/rust/kona/tests/proofs/helpers" "github.com/ethereum/go-ethereum/common" @@ -21,6 +22,7 @@ const ( var ( revertDepositTarget = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") revertDepositCode = common.FromHex("0x60006000fd") + unfundedDepositMint = big.NewInt(params.GWei) ) type depositGasVariant uint8 @@ -29,6 +31,10 @@ const ( l1InfoDeposit depositGasVariant = iota ordinaryDepositSuccess ordinaryDepositRevert + // ordinaryDepositUnfunded sends more value than the sender holds on L2 after the mint. The + // transfer fails before execution, so only the mint and the nonce increment remain. Unlike a + // deposit that reverts, a deposit that fails this way reports its whole gas limit. + ordinaryDepositUnfunded ) func TestDepositGasParity(gt *testing.T) { @@ -56,6 +62,9 @@ func TestDepositGasParity(gt *testing.T) { }) env := helpers.NewL2FaultProofEnv(t, testCfg, helpers.NewTestParams(), batcherCfg) preRegolith := testCfg.Hardfork.Precedence < helpers.Regolith.Precedence + preCanyon := testCfg.Hardfork.Precedence < helpers.Canyon.Precedence + l2 := env.Engine.EthClient() + var unfundedDepositValue *big.Int if testCfg.Custom == l1InfoDeposit { // Every naturally built L2 block starts with an L1-info deposit. Do not force the @@ -67,19 +76,41 @@ func TestDepositGasParity(gt *testing.T) { target = revertDepositTarget } + // A deposit has no nonce of its own. Give Alice a nonzero L2 nonce first, so the + // receipt's deposit nonce can only match if it is read from her account. + env.Alice.L2.ActResetTxOpts(t) + env.Alice.L2.ActSetTxToAddr(&env.Dp.Addresses.Bob)(t) + env.Alice.L2.ActMakeTx(t) + env.Sequencer.ActL2StartBlock(t) + env.Engine.ActL2IncludeTx(env.Alice.Address())(t) + env.Sequencer.ActL2EndBlock(t) + env.Alice.L2.ActCheckReceiptStatusOfLastTx(true)(t) + // Submit the ordinary deposit through the real portal, mine its L1 receipt, and let // the sequencer derive it when adopting the new L1 origin. env.Alice.L1.ActResetTxOpts(t) env.Alice.L2.ActResetTxOpts(t) env.Alice.L2.ActSetTxToAddr(&target)(t) env.Alice.L2.ActSetTxGasLimit(userDepositGasLimit)(t) + if testCfg.Custom == ordinaryDepositUnfunded { + balance, err := l2.BalanceAt(t.Ctx(), env.Alice.Address(), nil) + require.NoError(t, err) + // One mint more than Alice holds once the mint is applied. + unfundedDepositValue = new(big.Int).Add(balance, new(big.Int).Mul(unfundedDepositMint, big.NewInt(2))) + env.Alice.L1.ActSetTxValue(unfundedDepositMint)(t) + env.Alice.L2.ActSetTxValue(unfundedDepositValue)(t) + } env.Alice.ActDeposit(t) env.Miner.ActL1StartBlock(helpers.L1BlockTime)(t) env.Miner.ActL1IncludeTx(env.Alice.Address())(t) env.Miner.ActL1EndBlock(t) env.Sequencer.ActL1HeadSignal(t) env.Sequencer.ActBuildToL1HeadUnsafe(t) - env.Alice.ActCheckDepositStatus(true, testCfg.Custom == ordinaryDepositSuccess)(t) + // ActCheckDepositStatus decodes the first log of the L1 receipt. With a mint, that log + // is the lockbox's, not the deposit event; the receipt checks below cover this case. + if testCfg.Custom != ordinaryDepositUnfunded { + env.Alice.ActCheckDepositStatus(true, testCfg.Custom == ordinaryDepositSuccess)(t) + } } // Inspect the exact L2 block that contains the deposit under test. @@ -96,6 +127,30 @@ func TestDepositGasParity(gt *testing.T) { require.Len(t, txs, 2, "deposit block must contain L1-info and the portal deposit") } + parentBlock := new(big.Int).SetUint64(testedBlockRef.Number - 1) + testedBlockNum := new(big.Int).SetUint64(testedBlockRef.Number) + // A deposit receipt carries the deposit nonce from Regolith and the receipt version from + // Canyon. From Canyon both are in the receipt's consensus encoding, which FetchReceipts + // checks against the receipts root; before Canyon the nonce is stored and served only. The + // nonce is the sender's nonce before the deposit, which is its nonce in the parent block: + // no block here holds two txs from one sender. + requireDepositReceiptFields := func(depositTx *optypes.DepositTx, receipt *optypes.Receipt) { + if preRegolith { + require.Nil(t, receipt.DepositNonce, "deposit receipts carry no deposit nonce before Regolith") + } else { + nonce, err := l2.NonceAt(t.Ctx(), depositTx.From, parentBlock) + require.NoError(t, err) + require.NotNil(t, receipt.DepositNonce, "deposit receipts carry the deposit nonce from Regolith") + require.Equal(t, nonce, *receipt.DepositNonce, "deposit nonce must be the sender's nonce before the deposit") + } + if preCanyon { + require.Nil(t, receipt.DepositReceiptVersion, "deposit receipts carry no version before Canyon") + } else { + require.NotNil(t, receipt.DepositReceiptVersion, "deposit receipts carry a version from Canyon") + require.Equal(t, optypes.CanyonDepositReceiptVersion, *receipt.DepositReceiptVersion) + } + } + l1InfoTx := txs[0] l1InfoReceipt := receipts[0] require.Equal(t, preRegolith, l1InfoTx.IsSystemTransaction, "L1-info system flag must transition at Regolith") @@ -106,31 +161,63 @@ func TestDepositGasParity(gt *testing.T) { require.NotZero(t, l1InfoReceipt.GasUsed, "post-Regolith L1-info deposit must report actual gas") require.Less(t, l1InfoReceipt.GasUsed, l1InfoTx.Gas, "L1-info gas limit must exceed actual gas") } + requireDepositReceiptFields(l1InfoTx, l1InfoReceipt) if testCfg.Custom != l1InfoDeposit { depositTx := txs[1] depositReceipt := receipts[1] require.False(t, depositTx.IsSystemTransaction, "ordinary portal deposit must not be a system transaction") require.Equal(t, userDepositGasLimit, depositTx.Gas) - - expectedStatus := uint64(types.ReceiptStatusSuccessful) - expectedActualGas := uint64(params.TxGas) - if testCfg.Custom == ordinaryDepositRevert { - expectedStatus = types.ReceiptStatusFailed - expectedActualGas = revertDepositGas + requireDepositReceiptFields(depositTx, depositReceipt) + + // Gas the deposit reports from Regolith on. Before Regolith every non-system + // deposit reports its gas limit. + var expectedReportedGas uint64 + switch testCfg.Custom { + case ordinaryDepositSuccess: + require.Equal(t, types.ReceiptStatusSuccessful, depositReceipt.Status) + require.Equal(t, env.Dp.Addresses.Bob, *depositTx.To) + expectedReportedGas = params.TxGas + case ordinaryDepositRevert: + require.Equal(t, types.ReceiptStatusFailed, depositReceipt.Status) require.Equal(t, revertDepositTarget, *depositTx.To) - } else { + expectedReportedGas = revertDepositGas + case ordinaryDepositUnfunded: + require.Equal(t, types.ReceiptStatusFailed, depositReceipt.Status) require.Equal(t, env.Dp.Addresses.Bob, *depositTx.To) - } - require.Greater(t, userDepositGasLimit, expectedActualGas, "fixture must leave unused deposit gas") - require.Equal(t, expectedStatus, depositReceipt.Status) + require.Zero(t, unfundedDepositMint.Cmp(depositTx.Mint), "deposit must mint %v, minted %v", unfundedDepositMint, depositTx.Mint) + require.Zero(t, unfundedDepositValue.Cmp(depositTx.Value), "deposit must send %v, sent %v", unfundedDepositValue, depositTx.Value) + expectedReportedGas = userDepositGasLimit - expectedReportedGas := expectedActualGas + // Only the mint stays: the value never reaches the target. + for addr, delta := range map[common.Address]*big.Int{ + depositTx.From: unfundedDepositMint, + *depositTx.To: new(big.Int), + } { + before, err := l2.BalanceAt(t.Ctx(), addr, parentBlock) + require.NoError(t, err) + after, err := l2.BalanceAt(t.Ctx(), addr, testedBlockNum) + require.NoError(t, err) + want := new(big.Int).Add(before, delta) + require.Zero(t, want.Cmp(after), "balance of %s: want %v, got %v", addr, want, after) + } + } + if testCfg.Custom != ordinaryDepositUnfunded { + require.Greater(t, userDepositGasLimit, expectedReportedGas, "fixture must leave unused deposit gas") + } if preRegolith { expectedReportedGas = userDepositGasLimit } require.Equal(t, expectedReportedGas, depositReceipt.GasUsed, "deposit receipt gas must follow the active fork's accounting rules") + + // Every deposit increments the sender's nonce, whether it succeeds or fails. + nonceBefore, err := l2.NonceAt(t.Ctx(), depositTx.From, parentBlock) + require.NoError(t, err) + require.NotZero(t, nonceBefore, "the sender must have a nonzero nonce before the deposit") + nonceAfter, err := l2.NonceAt(t.Ctx(), depositTx.From, testedBlockNum) + require.NoError(t, err) + require.Equal(t, nonceBefore+1, nonceAfter, "deposit must increment the sender's nonce") } var cumulativeGas uint64 @@ -159,5 +246,6 @@ func TestDepositGasParity(gt *testing.T) { matrix.AddDefaultTestCasesWithName("L1InfoDeposit", l1InfoDeposit, forks, runDepositGasTest) matrix.AddDefaultTestCasesWithName("OrdinaryDepositSuccess", ordinaryDepositSuccess, forks, runDepositGasTest) matrix.AddDefaultTestCasesWithName("OrdinaryDepositRevert", ordinaryDepositRevert, forks, runDepositGasTest) + matrix.AddDefaultTestCasesWithName("OrdinaryDepositUnfunded", ordinaryDepositUnfunded, forks, runDepositGasTest) matrix.Run(gt) } diff --git a/rust/kona/tests/proofs/fixtures.go b/rust/kona/tests/proofs/fixtures.go index db81f7b382b..5509ec8a10c 100644 --- a/rust/kona/tests/proofs/fixtures.go +++ b/rust/kona/tests/proofs/fixtures.go @@ -118,4 +118,11 @@ var PrecompileTestFixtures = []PrecompileTestFixture{ ActivationFork: forks.Isthmus, Accelerated: true, }, + { + Name: "p256Verify", + Address: common.BytesToAddress([]byte{0x01, 0x00}), + Input: common.FromHex("4cee90eb86eaa050036147a12d49004b6b9c72bd725d39d4785011fe190f0b4da73bd4903f0ce3b639bbbf6e8e80d16931ff4bcf5993d58468e8fb19086e8cac36dbcd03009df8c59286b162af3bd7fcc0450c9aa81be5d10d312af6c66b1d604aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff37618b065f9832de4ca6ca971a7a1adc826d0f7c00181a5fb2ddf79ae00b4e10e"), + Output: common.FromHex("0000000000000000000000000000000000000000000000000000000000000001"), + ActivationFork: forks.Fjord, + }, } diff --git a/rust/kona/tests/proofs/fork_activation_evm_test.go b/rust/kona/tests/proofs/fork_activation_evm_test.go new file mode 100644 index 00000000000..521d0a39cd6 --- /dev/null +++ b/rust/kona/tests/proofs/fork_activation_evm_test.go @@ -0,0 +1,246 @@ +package proofs + +import ( + "bytes" + "math/big" + "slices" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/params" + "github.com/stretchr/testify/require" + + batcherFlags "github.com/ethereum-optimism/optimism/op-batcher/flags" + "github.com/ethereum-optimism/optimism/op-chain-ops/genesis" + "github.com/ethereum-optimism/optimism/op-core/forks" + optypes "github.com/ethereum-optimism/optimism/op-core/types" + actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers" + "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/contracts/bindings/invoker" + "github.com/ethereum-optimism/optimism/op-service/eth" + "github.com/ethereum-optimism/optimism/rust/kona/tests/proofs/helpers" +) + +// forkActivationBlock is the L2 block that activates the fork under test. +const forkActivationBlock = 3 + +// forkActivationProbeGas is the gas limit of every probe transaction. +const forkActivationProbeGas = uint64(2_000_000) + +// statusProbe is a transaction whose receipt status a fork flips. +type statusProbe struct { + name string + // to is nil for a contract creation that runs data as its initcode. + to *common.Address + data []byte + // succeedsFromFork is the status from the fork on. Before the fork the status is the + // opposite. A failing probe halts, so it spends its whole gas limit. + succeedsFromFork bool +} + +// forkActivationCase lists EVM rules that a fork switches on. +type forkActivationCase struct { + fork forks.Name + statusProbes []statusProbe + // outputs are precompile calls made through the Invoker. Each returns no output before the + // fork, when its address has no code, and the fixture's Output from the fork on. The Invoker + // uses PUSH0 and MCOPY, so only a fork after Ecotone can have outputs. + outputs []PrecompileTestFixture +} + +// blsMalformedInputs are the EIP-2537 failure vectors: well-formed calls that each BLS12-381 +// precompile must reject from Isthmus on. +var blsMalformedInputs = []statusProbe{ + // A G1 point not on the curve. + {name: "blsG1AddOffCurve", to: ptr(common.BytesToAddress([]byte{0x0b})), data: common.FromHex("0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb00000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a2100000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21")}, + // A non-canonical field element. + {name: "blsG2AddNonCanonical", to: ptr(common.BytesToAddress([]byte{0x0d})), data: common.FromHex("000000000000000000000000000000001c4bb49d2a0ef12b7123acdd7110bd292b5bc659edc54dc21b81de057194c79b2a5803255959bbef8e7f56c8c12168630000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451")}, + // A G1 point not on the curve. + {name: "blsG1MsmOffCurve", to: ptr(common.BytesToAddress([]byte{0x0c})), data: common.FromHex("0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb00000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a210000000000000000000000000000000000000000000000000000000000000002")}, + // A non-canonical field element. + {name: "blsG2MsmNonCanonical", to: ptr(common.BytesToAddress([]byte{0x0e})), data: common.FromHex("000000000000000000000000000000001c4bb49d2a0ef12b7123acdd7110bd292b5bc659edc54dc21b81de057194c79b2a5803255959bbef8e7f56c8c12168630000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000002")}, + // A non-canonical field element. + {name: "blsHashToG1NonCanonical", to: ptr(common.BytesToAddress([]byte{0x10})), data: common.FromHex("000000000000000000000000000000002f6d9c5465982c0421b61e74579709b3b5b91e57bdd4f6015742b4ff301abb7ef895b9cce00c33c7d48f8e5fa4ac09ae")}, + // A non-canonical field element. + {name: "blsHashToG2NonCanonical", to: ptr(common.BytesToAddress([]byte{0x11})), data: common.FromHex("0000000000000000000000000000000021366f100476ce8d3be6cfc90d59fe13349e388ed12b6dd6dc31ccd267ff000e2c993a063ca66beced06f804d4b8e5af0000000000000000000000000000000002829ce3c021339ccb5caf3e187f6370e1e2a311dec9b75363117063ab2015603ff52c3d3b98f19c2f65575e99e8b78c")}, + // A G1 point outside the subgroup. + {name: "blsPairingCheckOutsideSubgroup", to: ptr(common.BytesToAddress([]byte{0x0f})), data: common.FromHex("000000000000000000000000000000000123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef00000000000000000000000000000000193fb7cedb32b2c3adc06ec11a96bc0d661869316f5e4a577a9f7c179593987beb4fb2ee424dbb2f5dd891e228b46c4a00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17f9ee3837a55024f78c71363275a75d75d86bab79f74782aa0000000000000000000000000000000013fa4d4a0ad8b1ce186ed5061789213d993923066dddaf1040bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed")}, +} + +// TestForkActivationEVMRules activates a fork after genesis, as live chains activated it, and +// checks the EVM rules that the fork switches on. It runs the same probes in a block before the +// activation block and in a block after it, then proves those blocks and the activation block with +// the fault-proof program. TestPrecompiles activates each precompile's fork at genesis, so it cannot +// catch an engine that picks its opcodes or precompiles from the genesis fork instead of from each +// block's timestamp. +func TestForkActivationEVMRules(gt *testing.T) { + kzg := precompileFixture(gt, "kzgPointEvaluation") + // Changing the claimed evaluation y, at bytes 64..96, makes the proof fail to verify. + kzgWrongEvaluation := bytes.Clone(kzg.Input) + kzgWrongEvaluation[95] ^= 1 + + p256 := precompileFixture(gt, "p256Verify") + // A signature that does not verify does not make P256VERIFY fail: it returns no output. + // Changing the message hash, at bytes 0..32, makes the signature fail to verify. + p256WrongHash := bytes.Clone(p256.Input) + p256WrongHash[31] ^= 1 + p256Unverified := PrecompileTestFixture{Name: "p256VerifyWrongHash", Address: p256.Address, Input: p256WrongHash, Output: []byte{}} + + var blsOutputs []PrecompileTestFixture + for _, fixture := range PrecompileTestFixtures { + if fixture.ActivationFork == forks.Isthmus { + blsOutputs = append(blsOutputs, fixture) + } + } + require.Len(gt, blsOutputs, len(blsMalformedInputs), "one valid-output fixture per EIP-2537 precompile") + + matrix := helpers.NewMatrix[forkActivationCase]() + for _, c := range []forkActivationCase{ + {fork: forks.Canyon, statusProbes: []statusProbe{ + {name: "PUSH0", data: []byte{byte(vm.PUSH0)}, succeedsFromFork: true}, + }}, + {fork: forks.Ecotone, statusProbes: []statusProbe{ + {name: "TSTORE", data: []byte{byte(vm.PUSH1), 1, byte(vm.PUSH1), 1, byte(vm.TSTORE)}, succeedsFromFork: true}, + {name: "kzgPointEvaluationWrongEvaluation", to: &kzg.Address, data: kzgWrongEvaluation}, + }}, + {fork: forks.Fjord, outputs: []PrecompileTestFixture{p256, p256Unverified}}, + {fork: forks.Isthmus, statusProbes: blsMalformedInputs, outputs: blsOutputs}, + } { + // The fork before the one under test is active at genesis. It only names the subtest: + // runForkActivationTest schedules every fork itself. + genesisFork := lookupHardforkHelper(forks.Prev(c.fork)) + require.NotNil(gt, genesisFork, "no hardfork helper for the fork before %s", c.fork) + matrix.AddTestCase(string(c.fork), c, helpers.NewForkMatrix(genesisFork), runForkActivationTest, helpers.ExpectNoError()) + } + matrix.Run(gt) +} + +func runForkActivationTest(gt *testing.T, testCfg *helpers.TestCfg[forkActivationCase]) { + t := actionsHelpers.NewDefaultTesting(gt) + c := testCfg.Custom + batcherCfg := helpers.NewBatcherCfg(func(b *actionsHelpers.BatcherCfg) { + // Calldata is the only batch transport before Ecotone. + b.DataAvailabilityType = batcherFlags.CalldataType + }) + env := helpers.NewL2FaultProofEnv(t, testCfg, helpers.NewTestParams(), batcherCfg, func(dc *genesis.DeployConfig) { + dc.ActivateForkAtOffset(c.fork, forkActivationBlock*dc.L2BlockTime) + }) + l2 := env.Engine.EthClient() + alice := env.Alice.Address() + chainID := env.Sd.RollupCfg.L2ChainID + signer := types.LatestSignerForChainID(chainID) + invokerABI, err := invoker.InvokerMetaData.GetAbi() + require.NoError(t, err) + + // Probes are signed here rather than with Alice's L2 user: it estimates gas, which fails for + // a transaction that fails. + nonce, err := l2.NonceAt(t.Ctx(), alice, nil) + require.NoError(t, err) + send := func(to *common.Address, data []byte) *types.Transaction { + tip := big.NewInt(params.GWei) + feeCap := new(big.Int).Add(new(big.Int).Mul(env.Engine.LatestHeader(t).BaseFee, big.NewInt(2)), tip) + tx := types.MustSignNewTx(env.Dp.Secrets.Alice, signer, &types.DynamicFeeTx{ + ChainID: chainID, + Nonce: nonce, + GasTipCap: tip, + GasFeeCap: feeCap, + Gas: forkActivationProbeGas, + To: to, + Data: data, + }) + nonce++ + require.NoError(t, l2.SendTransaction(t.Ctx(), tx)) + return tx + } + buildBlock := func(txs []*types.Transaction) eth.L2BlockRef { + env.Sequencer.ActL2StartBlock(t) + for range txs { + env.Engine.ActL2IncludeTx(alice)(t) + } + return env.Sequencer.ActL2EndBlock(t) + } + receipt := func(tx *types.Transaction, block eth.L2BlockRef) *optypes.Receipt { + r, err := env.Engine.SourceClient().TransactionReceipt(t.Ctx(), tx.Hash()) + require.NoError(t, err) + require.Equal(t, block.Hash, r.BlockHash, "transaction must be in block %d", block.Number) + return r + } + + var deployTxs []*types.Transaction + if len(c.outputs) > 0 { + deployTxs = append(deployTxs, send(nil, common.FromHex(invoker.InvokerMetaData.Bin))) + } + deployBlock := buildBlock(deployTxs) + var invokerAddr common.Address + if len(deployTxs) > 0 { + r := receipt(deployTxs[0], deployBlock) + require.Equal(t, types.ReceiptStatusSuccessful, r.Status, "Invoker deployment") + invokerAddr = r.ContractAddress + } + + // sendProbes sends every probe, the status probes first. + sendProbes := func() []*types.Transaction { + var txs []*types.Transaction + for _, probe := range c.statusProbes { + txs = append(txs, send(probe.to, probe.data)) + } + for _, fixture := range c.outputs { + calldata, err := invokerABI.Pack("invokePrecompile", fixture.Address, fixture.Input) + require.NoError(t, err) + txs = append(txs, send(&invokerAddr, calldata)) + } + return txs + } + checkProbes := func(block eth.L2BlockRef, txs []*types.Transaction, forkActive bool) { + for i, probe := range c.statusProbes { + r := receipt(txs[i], block) + if probe.succeedsFromFork == forkActive { + require.Equal(t, types.ReceiptStatusSuccessful, r.Status, "%s with %s active: %v", probe.name, c.fork, forkActive) + } else { + require.Equal(t, types.ReceiptStatusFailed, r.Status, "%s with %s active: %v", probe.name, c.fork, forkActive) + require.Equal(t, txs[i].Gas(), r.GasUsed, "%s must halt, spending its whole gas limit", probe.name) + } + } + for i, fixture := range c.outputs { + r := receipt(txs[len(c.statusProbes)+i], block) + require.Equal(t, types.ReceiptStatusSuccessful, r.Status, "Invoker call to %s", fixture.Name) + require.Len(t, r.Logs, 1) + var out struct { + Result []byte + DelegateCallResult []byte + } + require.NoError(t, invokerABI.UnpackIntoInterface(&out, "PrecompileInvoked", r.Logs[0].Data)) + want := []byte{} + if forkActive { + want = fixture.Output + } + require.Equal(t, want, out.Result, "%s with %s active: %v", fixture.Name, c.fork, forkActive) + require.Equal(t, want, out.DelegateCallResult, "%s with %s active: %v", fixture.Name, c.fork, forkActive) + } + } + + beforeTxs := sendProbes() + before := buildBlock(beforeTxs) + env.Sequencer.ActL2EmptyBlock(t) + activation := env.Sequencer.L2Unsafe() + require.Equal(t, uint64(forkActivationBlock), activation.Number) + require.True(t, env.Sd.RollupCfg.IsActivationBlockForFork(activation.Time, c.fork), "block %d must activate %s", activation.Number, c.fork) + afterTxs := sendProbes() + after := buildBlock(afterTxs) + + checkProbes(before, beforeTxs, false) + checkProbes(after, afterTxs, true) + + require.Equal(t, after, env.BatchMineAndSync(t), "derivation must reproduce the engine-built blocks") + for _, block := range []eth.L2BlockRef{before, activation, after} { + env.RunFaultProofProgram(t, block.Number, testCfg.CheckResult, testCfg.InputParams...) + } +} + +// precompileFixture returns the fixture of PrecompileTestFixtures called name. +func precompileFixture(t *testing.T, name string) PrecompileTestFixture { + i := slices.IndexFunc(PrecompileTestFixtures, func(f PrecompileTestFixture) bool { return f.Name == name }) + require.NotEqual(t, -1, i, "no precompile fixture %s", name) + return PrecompileTestFixtures[i] +} diff --git a/rust/op-reth/crates/node/src/engine.rs b/rust/op-reth/crates/node/src/engine.rs index a548af1ab32..725c9f9135a 100644 --- a/rust/op-reth/crates/node/src/engine.rs +++ b/rust/op-reth/crates/node/src/engine.rs @@ -240,6 +240,14 @@ pub fn validate_op_version_specific_fields( /// /// These are the checks [`OpEngineValidator`] runs on the attributes of an /// `engine_forkchoiceUpdated` call, taking `version` from the method called. They read no state. +/// +/// The gas limit, EIP-1559 and minimum base fee checks fail with +/// [`EngineObjectValidationError::InvalidParams`], which the engine API answers with `-32602`. The +/// version-specific checks answer as the engine API spec requires, with `-38003` (invalid payload +/// attributes) or `-38005`. op-node always sets the OP fields, so only a fork schedule that differs +/// between op-node and op-reth fails their checks. op-node retries a call that fails with +/// `-32602`, which keeps that mismatch visible as a stall. On `-38003` it gives up on the +/// attributes: it drops a derived batch, or from Holocene replaces it with a deposits-only block. pub fn ensure_well_formed_payload_attributes( chain_spec: &ChainSpec, version: EngineApiMessageVersion, From e2dd1480a2765592e1a56849e45be706f224f7ad Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Wed, 18 Nov 2026 13:02:37 +0100 Subject: [PATCH 2/3] kona,op-reth: pin the fork-boundary header and state rules from review - TestDepositGasParity checks that from Regolith the RPC transaction reports the deposit nonce as its nonce. - TestForkActivationEVMRules, Canyon case: blocks have no withdrawals before Canyon and empty withdrawals from its activation block on. The activation block force-deploys the create2 deployer. The case removes the genesis preinstall, which would otherwise hide the deployment. The PUSH0 probe also runs in the activation block, which catches an engine that takes its rules from the parent block's timestamp. - Ecotone case: blocks have no parent beacon block root before Ecotone, and the root of their L1 origin from its activation block on. The test first mines an L1 block, because the L1 genesis has a zero root. - The comment on ensure_well_formed_payload_attributes now gives only the error-code mapping. Co-Authored-By: Claude Opus 5.5 --- rust/kona/tests/proofs/deposit_gas_test.go | 16 ++- .../tests/proofs/fork_activation_evm_test.go | 115 ++++++++++++++++-- rust/op-reth/crates/node/src/engine.rs | 10 +- 3 files changed, 119 insertions(+), 22 deletions(-) diff --git a/rust/kona/tests/proofs/deposit_gas_test.go b/rust/kona/tests/proofs/deposit_gas_test.go index 10813b8eaf7..8bd45bdcdd1 100644 --- a/rust/kona/tests/proofs/deposit_gas_test.go +++ b/rust/kona/tests/proofs/deposit_gas_test.go @@ -9,6 +9,7 @@ import ( actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers" "github.com/ethereum-optimism/optimism/rust/kona/tests/proofs/helpers" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" "github.com/stretchr/testify/require" @@ -131,9 +132,10 @@ func TestDepositGasParity(gt *testing.T) { testedBlockNum := new(big.Int).SetUint64(testedBlockRef.Number) // A deposit receipt carries the deposit nonce from Regolith and the receipt version from // Canyon. From Canyon both are in the receipt's consensus encoding, which FetchReceipts - // checks against the receipts root; before Canyon the nonce is stored and served only. The - // nonce is the sender's nonce before the deposit, which is its nonce in the parent block: - // no block here holds two txs from one sender. + // checks against the receipts root; before Canyon the nonce is stored and served only. From + // Regolith the RPC transaction also reports the deposit nonce as its nonce. The nonce is the + // sender's nonce before the deposit, which is its nonce in the parent block: no block here + // holds two txs from one sender. requireDepositReceiptFields := func(depositTx *optypes.DepositTx, receipt *optypes.Receipt) { if preRegolith { require.Nil(t, receipt.DepositNonce, "deposit receipts carry no deposit nonce before Regolith") @@ -142,6 +144,14 @@ func TestDepositGasParity(gt *testing.T) { require.NoError(t, err) require.NotNil(t, receipt.DepositNonce, "deposit receipts carry the deposit nonce from Regolith") require.Equal(t, nonce, *receipt.DepositNonce, "deposit nonce must be the sender's nonce before the deposit") + + // Read as raw JSON: a decoded DepositTx has no nonce. + var rpcTx struct { + Nonce *hexutil.Uint64 `json:"nonce"` + } + require.NoError(t, env.Engine.RPCClient().CallContext(t.Ctx(), &rpcTx, "eth_getTransactionByHash", receipt.TxHash)) + require.NotNil(t, rpcTx.Nonce, "RPC deposit transactions have a nonce from Regolith") + require.Equal(t, nonce, uint64(*rpcTx.Nonce), "the RPC nonce of a deposit must be its deposit nonce") } if preCanyon { require.Nil(t, receipt.DepositReceiptVersion, "deposit receipts carry no version before Canyon") diff --git a/rust/kona/tests/proofs/fork_activation_evm_test.go b/rust/kona/tests/proofs/fork_activation_evm_test.go index 521d0a39cd6..a76e58fd736 100644 --- a/rust/kona/tests/proofs/fork_activation_evm_test.go +++ b/rust/kona/tests/proofs/fork_activation_evm_test.go @@ -9,12 +9,14 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" "github.com/stretchr/testify/require" batcherFlags "github.com/ethereum-optimism/optimism/op-batcher/flags" "github.com/ethereum-optimism/optimism/op-chain-ops/genesis" "github.com/ethereum-optimism/optimism/op-core/forks" + "github.com/ethereum-optimism/optimism/op-core/predeploys" optypes "github.com/ethereum-optimism/optimism/op-core/types" actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/contracts/bindings/invoker" @@ -39,6 +41,11 @@ type statusProbe struct { succeedsFromFork bool } +// forkActivationBlocks are the blocks built around a fork's activation. +type forkActivationBlocks struct { + before, activation, after eth.L2BlockRef +} + // forkActivationCase lists EVM rules that a fork switches on. type forkActivationCase struct { fork forks.Name @@ -47,8 +54,22 @@ type forkActivationCase struct { // fork, when its address has no code, and the fixture's Output from the fork on. The Invoker // uses PUSH0 and MCOPY, so only a fork after Ecotone can have outputs. outputs []PrecompileTestFixture + // probeActivationBlock also sends the probes into the activation block. This catches an engine + // that takes its rules from the parent block's timestamp. Only a fork whose activation block + // may carry user transactions can set it: op-node's sequencer leaves them out of each activation + // block that carries upgrade transactions (Ecotone, Fjord, Isthmus, and Jovian on), and + // derivation drops them from Jovian on. + probeActivationBlock bool + // l2Alloc replaces accounts of the default L2 genesis. + l2Alloc types.GenesisAlloc + // checkBlocks checks header fields and state that the fork changes. + checkBlocks func(t actionsHelpers.Testing, env *helpers.L2FaultProofEnv, blocks forkActivationBlocks) } +// create2DeployerCodeHash is the code hash of the create2 deployer that Canyon force-deploys +// (CREATE_2_DEPLOYER_CODEHASH in alloy-op-evm/src/block/canyon.rs). +var create2DeployerCodeHash = common.HexToHash("0xb0550b5b431e30d38000efb7107aaa0ade03d48a7198a140edda9d27134468b2") + // blsMalformedInputs are the EIP-2537 failure vectors: well-formed calls that each BLS12-381 // precompile must reject from Isthmus on. var blsMalformedInputs = []statusProbe{ @@ -70,10 +91,11 @@ var blsMalformedInputs = []statusProbe{ // TestForkActivationEVMRules activates a fork after genesis, as live chains activated it, and // checks the EVM rules that the fork switches on. It runs the same probes in a block before the -// activation block and in a block after it, then proves those blocks and the activation block with -// the fault-proof program. TestPrecompiles activates each precompile's fork at genesis, so it cannot -// catch an engine that picks its opcodes or precompiles from the genesis fork instead of from each -// block's timestamp. +// activation block and in a block after it, and in the activation block too when that block may +// carry user transactions. For Canyon and Ecotone it also checks header fields and state that the +// fork changes. It then proves the three blocks with the fault-proof program. TestPrecompiles +// activates each precompile's fork at genesis, so it cannot catch an engine that picks its opcodes +// or precompiles from the genesis fork instead of from each block's timestamp. func TestForkActivationEVMRules(gt *testing.T) { kzg := precompileFixture(gt, "kzgPointEvaluation") // Changing the claimed evaluation y, at bytes 64..96, makes the proof fail to verify. @@ -97,13 +119,25 @@ func TestForkActivationEVMRules(gt *testing.T) { matrix := helpers.NewMatrix[forkActivationCase]() for _, c := range []forkActivationCase{ - {fork: forks.Canyon, statusProbes: []statusProbe{ - {name: "PUSH0", data: []byte{byte(vm.PUSH0)}, succeedsFromFork: true}, - }}, - {fork: forks.Ecotone, statusProbes: []statusProbe{ - {name: "TSTORE", data: []byte{byte(vm.PUSH1), 1, byte(vm.PUSH1), 1, byte(vm.TSTORE)}, succeedsFromFork: true}, - {name: "kzgPointEvaluationWrongEvaluation", to: &kzg.Address, data: kzgWrongEvaluation}, - }}, + { + fork: forks.Canyon, + statusProbes: []statusProbe{ + {name: "PUSH0", data: []byte{byte(vm.PUSH0)}, succeedsFromFork: true}, + }, + probeActivationBlock: true, + // The default L2 genesis preinstalls the create2 deployer, so Canyon's force-deployment + // would change nothing. An empty account removes it. + l2Alloc: types.GenesisAlloc{predeploys.Create2DeployerAddr: {Balance: new(big.Int)}}, + checkBlocks: checkCanyonBlocks, + }, + { + fork: forks.Ecotone, + statusProbes: []statusProbe{ + {name: "TSTORE", data: []byte{byte(vm.PUSH1), 1, byte(vm.PUSH1), 1, byte(vm.TSTORE)}, succeedsFromFork: true}, + {name: "kzgPointEvaluationWrongEvaluation", to: &kzg.Address, data: kzgWrongEvaluation}, + }, + checkBlocks: checkEcotoneBlocks, + }, {fork: forks.Fjord, outputs: []PrecompileTestFixture{p256, p256Unverified}}, {fork: forks.Isthmus, statusProbes: blsMalformedInputs, outputs: blsOutputs}, } { @@ -119,6 +153,11 @@ func TestForkActivationEVMRules(gt *testing.T) { func runForkActivationTest(gt *testing.T, testCfg *helpers.TestCfg[forkActivationCase]) { t := actionsHelpers.NewDefaultTesting(gt) c := testCfg.Custom + if c.l2Alloc != nil { + allocs := *actionsHelpers.DefaultAlloc + allocs.L2Alloc = c.l2Alloc + testCfg.Allocs = &allocs + } batcherCfg := helpers.NewBatcherCfg(func(b *actionsHelpers.BatcherCfg) { // Calldata is the only batch transport before Ecotone. b.DataAvailabilityType = batcherFlags.CalldataType @@ -126,6 +165,11 @@ func runForkActivationTest(gt *testing.T, testCfg *helpers.TestCfg[forkActivatio env := helpers.NewL2FaultProofEnv(t, testCfg, helpers.NewTestParams(), batcherCfg, func(dc *genesis.DeployConfig) { dc.ActivateForkAtOffset(c.fork, forkActivationBlock*dc.L2BlockTime) }) + // The L1 genesis has a zero parent beacon block root. An L1 block timed for the first L2 block + // becomes the L1 origin of every block below, so checkEcotoneBlocks sees a real root. + env.Miner.ActL1StartBlock(env.Sd.RollupCfg.BlockTime)(t) + env.Miner.ActL1EndBlock(t) + env.Sequencer.ActL1HeadSignal(t) l2 := env.Engine.EthClient() alice := env.Alice.Address() chainID := env.Sd.RollupCfg.L2ChainID @@ -222,15 +266,24 @@ func runForkActivationTest(gt *testing.T, testCfg *helpers.TestCfg[forkActivatio beforeTxs := sendProbes() before := buildBlock(beforeTxs) - env.Sequencer.ActL2EmptyBlock(t) - activation := env.Sequencer.L2Unsafe() + var activationTxs []*types.Transaction + if c.probeActivationBlock { + activationTxs = sendProbes() + } + activation := buildBlock(activationTxs) require.Equal(t, uint64(forkActivationBlock), activation.Number) require.True(t, env.Sd.RollupCfg.IsActivationBlockForFork(activation.Time, c.fork), "block %d must activate %s", activation.Number, c.fork) afterTxs := sendProbes() after := buildBlock(afterTxs) checkProbes(before, beforeTxs, false) + if c.probeActivationBlock { + checkProbes(activation, activationTxs, true) + } checkProbes(after, afterTxs, true) + if c.checkBlocks != nil { + c.checkBlocks(t, env, forkActivationBlocks{before: before, activation: activation, after: after}) + } require.Equal(t, after, env.BatchMineAndSync(t), "derivation must reproduce the engine-built blocks") for _, block := range []eth.L2BlockRef{before, activation, after} { @@ -238,6 +291,42 @@ func runForkActivationTest(gt *testing.T, testCfg *helpers.TestCfg[forkActivatio } } +// checkCanyonBlocks checks that blocks carry withdrawals from Canyon on, and that the activation +// block force-deploys the create2 deployer. +func checkCanyonBlocks(t actionsHelpers.Testing, env *helpers.L2FaultProofEnv, blocks forkActivationBlocks) { + require.Nil(t, env.Engine.HeaderByHash(t, blocks.before.Hash).WithdrawalsHash, "blocks have no withdrawals before Canyon") + for _, block := range []eth.L2BlockRef{blocks.activation, blocks.after} { + withdrawalsHash := env.Engine.HeaderByHash(t, block.Hash).WithdrawalsHash + require.NotNil(t, withdrawalsHash, "block %d must have withdrawals", block.Number) + require.Equal(t, types.EmptyWithdrawalsHash, *withdrawalsHash, "block %d must have empty withdrawals", block.Number) + } + + code := func(block eth.L2BlockRef) []byte { + code, err := env.Engine.EthClient().CodeAt(t.Ctx(), predeploys.Create2DeployerAddr, new(big.Int).SetUint64(block.Number)) + require.NoError(t, err) + return code + } + require.Empty(t, code(blocks.before), "the create2 deployer must not exist before Canyon") + require.Equal(t, create2DeployerCodeHash, crypto.Keccak256Hash(code(blocks.activation)), "Canyon must force-deploy the create2 deployer") +} + +// checkEcotoneBlocks checks that from Ecotone on each block carries the parent beacon block root of +// its L1 origin. +func checkEcotoneBlocks(t actionsHelpers.Testing, env *helpers.L2FaultProofEnv, blocks forkActivationBlocks) { + require.Nil(t, env.Engine.HeaderByHash(t, blocks.before.Hash).ParentBeaconRoot, "blocks have no parent beacon block root before Ecotone") + for _, block := range []eth.L2BlockRef{blocks.activation, blocks.after} { + origin, err := env.Miner.EthClient().HeaderByHash(t.Ctx(), block.L1Origin.Hash) + require.NoError(t, err) + // op-node falls back to the zero hash when the L1 origin has no root, which would make the + // check below pass for any engine that defaults to zero. + require.NotNil(t, origin.ParentBeaconRoot, "the L1 origin of block %d must have a parent beacon block root", block.Number) + require.NotEqual(t, common.Hash{}, *origin.ParentBeaconRoot, "the L1 origin of block %d must have a nonzero parent beacon block root", block.Number) + root := env.Engine.HeaderByHash(t, block.Hash).ParentBeaconRoot + require.NotNil(t, root, "block %d must have a parent beacon block root", block.Number) + require.Equal(t, *origin.ParentBeaconRoot, *root, "block %d must carry the parent beacon block root of its L1 origin", block.Number) + } +} + // precompileFixture returns the fixture of PrecompileTestFixtures called name. func precompileFixture(t *testing.T, name string) PrecompileTestFixture { i := slices.IndexFunc(PrecompileTestFixtures, func(f PrecompileTestFixture) bool { return f.Name == name }) diff --git a/rust/op-reth/crates/node/src/engine.rs b/rust/op-reth/crates/node/src/engine.rs index 725c9f9135a..8e8125b5493 100644 --- a/rust/op-reth/crates/node/src/engine.rs +++ b/rust/op-reth/crates/node/src/engine.rs @@ -242,12 +242,10 @@ pub fn validate_op_version_specific_fields( /// `engine_forkchoiceUpdated` call, taking `version` from the method called. They read no state. /// /// The gas limit, EIP-1559 and minimum base fee checks fail with -/// [`EngineObjectValidationError::InvalidParams`], which the engine API answers with `-32602`. The -/// version-specific checks answer as the engine API spec requires, with `-38003` (invalid payload -/// attributes) or `-38005`. op-node always sets the OP fields, so only a fork schedule that differs -/// between op-node and op-reth fails their checks. op-node retries a call that fails with -/// `-32602`, which keeps that mismatch visible as a stall. On `-38003` it gives up on the -/// attributes: it drops a derived batch, or from Holocene replaces it with a deposits-only block. +/// [`EngineObjectValidationError::InvalidParams`], which the engine API answers with `-32602`. +/// The version-specific checks answer with `-38003` (invalid payload attributes) or `-38005`, as +/// the engine API spec requires. op-node retries a call that fails with `-32602`, so a fork +/// schedule mismatch stalls it instead of changing what it derives. pub fn ensure_well_formed_payload_attributes( chain_spec: &ChainSpec, version: EngineApiMessageVersion, From 05566b030a037fffbe148f26ebab0516b45844b2 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Wed, 18 Nov 2026 13:52:45 +0100 Subject: [PATCH 3/3] op-reth: limit the stall note to the Holocene and Jovian checks op-node retries only on -32602. The version-specific checks answer with -38003, which makes op-node drop the attributes and build a deposits-only block, or with -38005, which makes it reset. So only a mismatch in the Holocene or Jovian checks stalls op-node. Co-Authored-By: Claude Opus 5.5 --- rust/op-reth/crates/node/src/engine.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/op-reth/crates/node/src/engine.rs b/rust/op-reth/crates/node/src/engine.rs index 8e8125b5493..ace18f63a23 100644 --- a/rust/op-reth/crates/node/src/engine.rs +++ b/rust/op-reth/crates/node/src/engine.rs @@ -244,8 +244,8 @@ pub fn validate_op_version_specific_fields( /// The gas limit, EIP-1559 and minimum base fee checks fail with /// [`EngineObjectValidationError::InvalidParams`], which the engine API answers with `-32602`. /// The version-specific checks answer with `-38003` (invalid payload attributes) or `-38005`, as -/// the engine API spec requires. op-node retries a call that fails with `-32602`, so a fork -/// schedule mismatch stalls it instead of changing what it derives. +/// the engine API spec requires. op-node retries a call that fails with `-32602`, so a Holocene +/// or Jovian schedule mismatch stalls it instead of changing what it derives. pub fn ensure_well_formed_payload_attributes( chain_spec: &ChainSpec, version: EngineApiMessageVersion,