Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fork1 tests v2 #1604

Merged
merged 17 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ reth-rpc-eth-types = { workspace = true, optional = true }
reth-rpc-server-types = { workspace = true, optional = true }
reth-rpc-types-compat = { workspace = true, optional = true }
reth-transaction-pool = { workspace = true, optional = true }
revm = { workspace = true, features = ["secp256k1"] }
revm = { workspace = true, default-features = false, features = ["secp256k1"] }
revm-inspectors = { workspace = true, optional = true }
secp256k1 = { workspace = true, optional = true }

Expand All @@ -64,7 +64,8 @@ rayon = { workspace = true }
reth-chainspec = { workspace = true }
reth-db = { workspace = true }
reth-errors = { workspace = true }
revm = { workspace = true, features = ["optional_block_gas_limit", "optional_eip3607", "optional_no_base_fee", "secp256k1"] }
revm = { workspace = true, default-features = false, features = ["optional_block_gas_limit", "optional_eip3607", "optional_no_base_fee", "secp256k1"] }
sha2 = { workspace = true }
sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", features = ["macros"] }
sov-prover-storage-manager = { path = "../sovereign-sdk/full-node/sov-prover-storage-manager", features = ["test-utils"] }
sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface", features = ["testing"] }
Expand All @@ -84,6 +85,7 @@ native = [
"reth-rpc-eth-api",
"reth-rpc-server-types",
"reth-rpc-types-compat",
"revm/serde",
"reth-transaction-pool",
"revm-inspectors",
"reth-provider",
Expand Down
21 changes: 19 additions & 2 deletions crates/evm/src/evm/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ 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::{
spec_to_generic, Address, EVMError, Env, HandlerCfg, InvalidTransaction, ResultAndState, Spec,
SpecId, B256, U256,
};
use revm::{Context, Database, FrameResult, InnerEvmContext, JournalEntry};
use revm::{Context, ContextPrecompiles, Database, FrameResult, InnerEvmContext, JournalEntry};
#[cfg(feature = "native")]
use revm::{EvmContext, Inspector};
use sov_modules_api::{native_debug, native_error, native_warn};
Expand Down Expand Up @@ -290,7 +291,7 @@ where
// validation.env =
validation.tx_against_state =
Arc::new(CitreaHandler::<SPEC, EXT, DB>::validate_tx_against_state);
// pre_execution.load_accounts =
pre_execution.load_precompiles = Arc::new(CitreaHandler::<SPEC, EXT, DB>::load_precompiles);
// pre_execution.load_accounts =
pre_execution.deduct_caller = Arc::new(CitreaHandler::<SPEC, EXT, DB>::deduct_caller);
// execution.last_frame_return =
Expand All @@ -314,6 +315,22 @@ 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> {
let mut precompiles = revm::handler::mainnet::load_precompiles::<SPEC, DB>();

if SPEC::enabled(SpecId::CANCUN) {
precompiles
.to_mut()
.remove(&u64_to_address(0x0A))
.expect("after cancun point eval should be removed");
}

precompiles
}

our_precompiles::<SPEC, DB>()
}
fn validate_tx_against_state(
context: &mut Context<EXT, DB>,
) -> Result<(), EVMError<DB::Error>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"bytes","name":"input","type":"bytes"}],"name":"verifyPointEvaluation","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6080604052348015600e575f5ffd5b506103208061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c806325a05f401461002d575b5f5ffd5b610047600480360381019061004291906101a0565b61005d565b6040516100549190610205565b60405180910390f35b5f60c083839050146100a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009b90610278565b60405180910390fd5b6060600a73ffffffffffffffffffffffffffffffffffffffff1684846040516100ce9291906102d2565b5f60405180830381855afa9150503d805f8114610106576040519150601f19603f3d011682016040523d82523d5f602084013e61010b565b606091505b5080925081935050505f815114610120575f5ffd5b60408101515f5581610130575f5ffd5b5092915050565b5f5ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5f83601f8401126101605761015f61013f565b5b8235905067ffffffffffffffff81111561017d5761017c610143565b5b60208301915083600182028301111561019957610198610147565b5b9250929050565b5f5f602083850312156101b6576101b5610137565b5b5f83013567ffffffffffffffff8111156101d3576101d261013b565b5b6101df8582860161014b565b92509250509250929050565b5f8115159050919050565b6101ff816101eb565b82525050565b5f6020820190506102185f8301846101f6565b92915050565b5f82825260208201905092915050565b7f496e76616c696420696e7075742073697a6500000000000000000000000000005f82015250565b5f61026260128361021e565b915061026d8261022e565b602082019050919050565b5f6020820190508181035f83015261028f81610256565b9050919050565b5f81905092915050565b828183375f83830152505050565b5f6102b98385610296565b93506102c68385846102a0565b82840190509392505050565b5f6102de8284866102ae565b9150819050939250505056fea264697066735822122052f3d3eafaae24a10a4cb029d517a2fc7b949c9ee79750ca303d13aba9fb158264736f6c634300081b0033
21 changes: 21 additions & 0 deletions crates/evm/src/evm/test_data/KZGPointEvaluationCaller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

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(
bytes calldata input // 192 bytes
) external returns (bool success) {
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);
}
}
49 changes: 49 additions & 0 deletions crates/evm/src/smart_contracts/kzg_point_evaluation_caller.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use alloy_primitives::Bytes;
use alloy_sol_types::{sol, SolCall};

use super::TestContract;

// KZGPointEvaluationCallerContract wrapper.
sol! {
#[sol(abi)]
KZGPointEvaluationCaller,
"./src/evm/test_data/KZGPointEvaluationCaller.abi"
}

/// KZGPointEvaluationContract wrapper.
pub struct KZGPointEvaluationCallerContract {
bytecode: Vec<u8>,
}

impl Default for KZGPointEvaluationCallerContract {
fn default() -> Self {
let bytecode = {
let bytecode_hex =
include_str!("../../../evm/src/evm/test_data/KZGPointEvaluationCaller.bin");
hex::decode(bytecode_hex).unwrap()
};

Self { bytecode }
}
}

impl TestContract for KZGPointEvaluationCallerContract {
fn byte_code(&self) -> Vec<u8> {
self.byte_code()
}
}

impl KZGPointEvaluationCallerContract {
/// KZGPointEvaluation bytecode.
pub fn byte_code(&self) -> Vec<u8> {
self.bytecode.clone()
}

/// Claims the gift.
pub fn call_kzg_point_evaluation(
&self,
input: Bytes, // 192 bytes
) -> Vec<u8> {
KZGPointEvaluationCaller::verifyPointEvaluationCall { input }.abi_encode()
}
}
2 changes: 2 additions & 0 deletions crates/evm/src/smart_contracts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod caller_contract;
mod coinbase_contract;
mod hive_contract;
mod infinite_loop_contract;
mod kzg_point_evaluation_caller;
mod logs_contract;
mod mcopy_contract;
mod payable_contract;
Expand All @@ -20,6 +21,7 @@ pub use caller_contract::CallerContract;
pub use coinbase_contract::CoinbaseContract;
pub use hive_contract::HiveContract;
pub use infinite_loop_contract::InfiniteLoopContract;
pub use kzg_point_evaluation_caller::KZGPointEvaluationCallerContract;
pub use logs_contract::{AnotherLogEvent, LogEvent, LogsContract};
pub use mcopy_contract::McopyContract;
pub use payable_contract::SimplePayableContract;
Expand Down
Loading
Loading