From 0dfe99d01e3c2071e2577c64bb40d3811779f961 Mon Sep 17 00:00:00 2001 From: eyusufatik Date: Thu, 19 Dec 2024 16:44:42 +0300 Subject: [PATCH] remove point eval precompile on runtime --- crates/evm/src/evm/handler.rs | 20 +++++++------------ .../test_data/KZGPointEvaluationCaller.bin | 2 +- .../test_data/KZGPointEvaluationCaller.sol | 9 ++------- crates/evm/src/tests/fork_tests.rs | 4 ++-- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/crates/evm/src/evm/handler.rs b/crates/evm/src/evm/handler.rs index ffcd8c096..a323e3110 100644 --- a/crates/evm/src/evm/handler.rs +++ b/crates/evm/src/evm/handler.rs @@ -8,6 +8,7 @@ use revm::handler::register::{EvmHandler, HandleRegisters}; #[cfg(feature = "native")] use revm::interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter}; use revm::interpreter::{Gas, InstructionResult}; +use revm::precompile::u64_to_address; #[cfg(feature = "native")] use revm::primitives::Log; use revm::primitives::{ @@ -316,22 +317,15 @@ struct CitreaHandler { impl CitreaHandler { fn load_precompiles() -> ContextPrecompiles { fn our_precompiles() -> ContextPrecompiles { - use revm::precompile::{ - u64_to_address, Bytes, Precompile, PrecompileOutput, PrecompileResult, - }; + let mut precompiles = revm::handler::mainnet::load_precompiles::(); - pub fn kzg(_input: &Bytes, _gas_limit: u64, _env: &Env) -> PrecompileResult { - pub const GAS_COST: u64 = 0; - pub const RETURN_VALUE: &[u8; 64] = &[0; 64]; - Ok(PrecompileOutput::new(GAS_COST, RETURN_VALUE.into())) + if SPEC::enabled(SpecId::CANCUN) { + precompiles + .to_mut() + .remove(&u64_to_address(0x0A)) + .expect("after cancun point eval should be removed"); } - let mut precompiles = revm::handler::mainnet::load_precompiles::(); - let precompiles_inner = precompiles.to_mut(); - if let Some(kzg_point_evaluation) = precompiles_inner.get_mut(&u64_to_address(0x0A)) { - // replace kzg_point_evaluation if it was enabled in the Spec - *kzg_point_evaluation = Precompile::Env(kzg).into(); - } precompiles } diff --git a/crates/evm/src/evm/test_data/KZGPointEvaluationCaller.bin b/crates/evm/src/evm/test_data/KZGPointEvaluationCaller.bin index a4f08955b..6afea8cd5 100644 --- a/crates/evm/src/evm/test_data/KZGPointEvaluationCaller.bin +++ b/crates/evm/src/evm/test_data/KZGPointEvaluationCaller.bin @@ -1 +1 @@ -6080604052348015600e575f5ffd5b506101f48061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c806325a05f401461002d575b5f5ffd5b61004061003b366004610141565b610054565b604051901515815260200160405180910390f35b5f60c0821461009e5760405162461bcd60e51b8152602060048201526012602482015271496e76616c696420696e7075742073697a6560701b604482015260640160405180910390fd5b6060600a6001600160a01b031684846040516100bb9291906101af565b5f60405180830381855afa9150503d805f81146100f3576040519150601f19603f3d011682016040523d82523d5f602084013e6100f8565b606091505b5060408101515f5590925090508161010e575f5ffd5b7f73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff000000015f541461013a575f5ffd5b5092915050565b5f5f60208385031215610152575f5ffd5b823567ffffffffffffffff811115610168575f5ffd5b8301601f81018513610178575f5ffd5b803567ffffffffffffffff81111561018e575f5ffd5b85602082840101111561019f575f5ffd5b6020919091019590945092505050565b818382375f910190815291905056fea264697066735822122010054b15f2c9a0211a93251f59f5ec0a6420f19958357a448ed5b5aea879aab964736f6c634300081b0033 \ No newline at end of file +6080604052348015600e575f5ffd5b506103208061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c806325a05f401461002d575b5f5ffd5b610047600480360381019061004291906101a0565b61005d565b6040516100549190610205565b60405180910390f35b5f60c083839050146100a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009b90610278565b60405180910390fd5b6060600a73ffffffffffffffffffffffffffffffffffffffff1684846040516100ce9291906102d2565b5f60405180830381855afa9150503d805f8114610106576040519150601f19603f3d011682016040523d82523d5f602084013e61010b565b606091505b5080925081935050505f815114610120575f5ffd5b60408101515f5581610130575f5ffd5b5092915050565b5f5ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5f83601f8401126101605761015f61013f565b5b8235905067ffffffffffffffff81111561017d5761017c610143565b5b60208301915083600182028301111561019957610198610147565b5b9250929050565b5f5f602083850312156101b6576101b5610137565b5b5f83013567ffffffffffffffff8111156101d3576101d261013b565b5b6101df8582860161014b565b92509250509250929050565b5f8115159050919050565b6101ff816101eb565b82525050565b5f6020820190506102185f8301846101f6565b92915050565b5f82825260208201905092915050565b7f496e76616c696420696e7075742073697a6500000000000000000000000000005f82015250565b5f61026260128361021e565b915061026d8261022e565b602082019050919050565b5f6020820190508181035f83015261028f81610256565b9050919050565b5f81905092915050565b828183375f83830152505050565b5f6102b98385610296565b93506102c68385846102a0565b82840190509392505050565b5f6102de8284866102ae565b9150819050939250505056fea264697066735822122052f3d3eafaae24a10a4cb029d517a2fc7b949c9ee79750ca303d13aba9fb158264736f6c634300081b0033 \ No newline at end of file diff --git a/crates/evm/src/evm/test_data/KZGPointEvaluationCaller.sol b/crates/evm/src/evm/test_data/KZGPointEvaluationCaller.sol index a7d9434c9..970b75635 100644 --- a/crates/evm/src/evm/test_data/KZGPointEvaluationCaller.sol +++ b/crates/evm/src/evm/test_data/KZGPointEvaluationCaller.sol @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.26; -contract KZGPointEvaluation { +contract KZGPointEvaluationCaller { /// @notice Calls the 0x0A precompile to perform point evaluation /// @param input A 192-byte input representing the polynomial versioned hash, commitment, point, and proof function verifyPointEvaluation( @@ -11,16 +11,11 @@ contract KZGPointEvaluation { require(input.length == 192, "Invalid input size"); bytes memory out; (success, out) = address(10).staticcall(input); + require(out.length == 0); // Write the 32 bytes of out to first storage slot assembly { sstore(0, mload(add(out, 64))) } require(success); - // Read the first storage slot and assert it to be 52435875175126190479447740508185965837690552500527637822603658699938581184513 - assembly { - if iszero(eq(sload(0), 52435875175126190479447740508185965837690552500527637822603658699938581184513)) { - revert(0, 0) - } - } } } \ No newline at end of file diff --git a/crates/evm/src/tests/fork_tests.rs b/crates/evm/src/tests/fork_tests.rs index d9d661559..f117f5b8c 100644 --- a/crates/evm/src/tests/fork_tests.rs +++ b/crates/evm/src/tests/fork_tests.rs @@ -653,8 +653,6 @@ fn test_kzg_point_eval_should_revert() { .iter(&mut working_set.accessory_state()) .collect(); - assert!(!receipts.last().unwrap().receipt.success); - let db_account = DbAccount::new(contract_addr); let storage_value = db_account .storage @@ -662,11 +660,13 @@ fn test_kzg_point_eval_should_revert() { .unwrap(); assert_ne!( storage_value, + // expected if point eval precompile was enabled U256::from_str( "52435875175126190479447740508185965837690552500527637822603658699938581184513" ) .unwrap() ); + assert!(receipts.last().unwrap().receipt.success); } #[test]