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 16 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
27 changes: 25 additions & 2 deletions crates/evm/src/evm/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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 +290,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 +314,29 @@ 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,
};

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()))
}

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)) {
eyusufatik marked this conversation as resolved.
Show resolved Hide resolved
// replace kzg_point_evaluation if it was enabled in the Spec
*kzg_point_evaluation = Precompile::Env(kzg).into();
}
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 @@
6080604052348015600e575f5ffd5b506101f48061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c806325a05f401461002d575b5f5ffd5b61004061003b366004610141565b610054565b604051901515815260200160405180910390f35b5f60c0821461009e5760405162461bcd60e51b8152602060048201526012602482015271496e76616c696420696e7075742073697a6560701b604482015260640160405180910390fd5b6060600a6001600160a01b031684846040516100bb9291906101af565b5f60405180830381855afa9150503d805f81146100f3576040519150601f19603f3d011682016040523d82523d5f602084013e6100f8565b606091505b5060408101515f5590925090508161010e575f5ffd5b7f73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff000000015f541461013a575f5ffd5b5092915050565b5f5f60208385031215610152575f5ffd5b823567ffffffffffffffff811115610168575f5ffd5b8301601f81018513610178575f5ffd5b803567ffffffffffffffff81111561018e575f5ffd5b85602082840101111561019f575f5ffd5b6020919091019590945092505050565b818382375f910190815291905056fea264697066735822122010054b15f2c9a0211a93251f59f5ec0a6420f19958357a448ed5b5aea879aab964736f6c634300081b0033
26 changes: 26 additions & 0 deletions crates/evm/src/evm/test_data/KZGPointEvaluationCaller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

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

contract KZGPointEvaluation {
/// @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);
// 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)
}
}
}
}
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