Skip to content

Commit

Permalink
remove point eval precompile on runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
eyusufatik committed Dec 19, 2024
1 parent 6c58bd4 commit 0dfe99d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
20 changes: 7 additions & 13 deletions crates/evm/src/evm/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -316,22 +317,15 @@ struct CitreaHandler<SPEC, EXT, DB> {
impl<SPEC: Spec, EXT: CitreaExternalExt, DB: Database> CitreaHandler<SPEC, EXT, DB> {
fn load_precompiles() -> ContextPrecompiles<DB> {
fn our_precompiles<SPEC: Spec, DB: Database>() -> ContextPrecompiles<DB> {
use revm::precompile::{
u64_to_address, Bytes, Precompile, PrecompileOutput, PrecompileResult,
};
let mut precompiles = revm::handler::mainnet::load_precompiles::<SPEC, DB>();

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::<SPEC, DB>();
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
}

Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/evm/test_data/KZGPointEvaluationCaller.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6080604052348015600e575f5ffd5b506101f48061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c806325a05f401461002d575b5f5ffd5b61004061003b366004610141565b610054565b604051901515815260200160405180910390f35b5f60c0821461009e5760405162461bcd60e51b8152602060048201526012602482015271496e76616c696420696e7075742073697a6560701b604482015260640160405180910390fd5b6060600a6001600160a01b031684846040516100bb9291906101af565b5f60405180830381855afa9150503d805f81146100f3576040519150601f19603f3d011682016040523d82523d5f602084013e6100f8565b606091505b5060408101515f5590925090508161010e575f5ffd5b7f73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff000000015f541461013a575f5ffd5b5092915050565b5f5f60208385031215610152575f5ffd5b823567ffffffffffffffff811115610168575f5ffd5b8301601f81018513610178575f5ffd5b803567ffffffffffffffff81111561018e575f5ffd5b85602082840101111561019f575f5ffd5b6020919091019590945092505050565b818382375f910190815291905056fea264697066735822122010054b15f2c9a0211a93251f59f5ec0a6420f19958357a448ed5b5aea879aab964736f6c634300081b0033
6080604052348015600e575f5ffd5b506103208061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c806325a05f401461002d575b5f5ffd5b610047600480360381019061004291906101a0565b61005d565b6040516100549190610205565b60405180910390f35b5f60c083839050146100a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009b90610278565b60405180910390fd5b6060600a73ffffffffffffffffffffffffffffffffffffffff1684846040516100ce9291906102d2565b5f60405180830381855afa9150503d805f8114610106576040519150601f19603f3d011682016040523d82523d5f602084013e61010b565b606091505b5080925081935050505f815114610120575f5ffd5b60408101515f5581610130575f5ffd5b5092915050565b5f5ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5f83601f8401126101605761015f61013f565b5b8235905067ffffffffffffffff81111561017d5761017c610143565b5b60208301915083600182028301111561019957610198610147565b5b9250929050565b5f5f602083850312156101b6576101b5610137565b5b5f83013567ffffffffffffffff8111156101d3576101d261013b565b5b6101df8582860161014b565b92509250509250929050565b5f8115159050919050565b6101ff816101eb565b82525050565b5f6020820190506102185f8301846101f6565b92915050565b5f82825260208201905092915050565b7f496e76616c696420696e7075742073697a6500000000000000000000000000005f82015250565b5f61026260128361021e565b915061026d8261022e565b602082019050919050565b5f6020820190508181035f83015261028f81610256565b9050919050565b5f81905092915050565b828183375f83830152505050565b5f6102b98385610296565b93506102c68385846102a0565b82840190509392505050565b5f6102de8284866102ae565b9150819050939250505056fea264697066735822122052f3d3eafaae24a10a4cb029d517a2fc7b949c9ee79750ca303d13aba9fb158264736f6c634300081b0033
9 changes: 2 additions & 7 deletions crates/evm/src/evm/test_data/KZGPointEvaluationCaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
}
}
}
}
4 changes: 2 additions & 2 deletions crates/evm/src/tests/fork_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,20 +653,20 @@ 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
.get(&U256::ZERO, &mut working_set)
.unwrap();
assert_ne!(
storage_value,
// expected if point eval precompile was enabled
U256::from_str(
"52435875175126190479447740508185965837690552500527637822603658699938581184513"
)
.unwrap()
);
assert!(receipts.last().unwrap().receipt.success);
}

#[test]
Expand Down

0 comments on commit 0dfe99d

Please sign in to comment.