Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ jobs:
- name: Run heavy tests
run: cargo test --verbose --release --features scroll --all --exclude integration-tests --exclude circuit-benchmarks serial_ -- --ignored --skip max_tx
- name: Run parallel assignment tests(bytecode)
if: false
run: cargo test --release --package zkevm-circuits --lib bytecode_circuit::test --features scroll,parallel_syn -- --nocapture
- name: Run parallel assignment tests(state)
if: false
run: cargo test --release --package zkevm-circuits --lib state_circuit::test --features scroll,parallel_syn -- --nocapture

build:
Expand Down
19 changes: 17 additions & 2 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod access;
mod block;
mod builder_client;
mod call;
/// Curie hardfork
pub mod curie;
mod execution;
mod input_state_ref;
#[cfg(feature = "scroll")]
Expand Down Expand Up @@ -276,7 +278,7 @@ impl<'a> CircuitInputBuilder {
&mut self,
eth_block: &EthBlock,
geth_traces: &[eth_types::GethExecTrace],
is_final_block: bool,
is_last_block: bool,
check_last_tx: bool,
) -> Result<(), Error> {
// accumulates gas across all txs in the block
Expand Down Expand Up @@ -374,7 +376,7 @@ impl<'a> CircuitInputBuilder {
}
}
}
if is_final_block {
if is_last_block {
self.set_value_ops_call_context_rwc_eor();
self.set_end_block()?;
}
Expand Down Expand Up @@ -493,6 +495,19 @@ impl<'a> CircuitInputBuilder {
withdraw_root_before,
),
)?;
let last_block_num = state
.block
.headers
.last_key_value()
.map(|(_, v)| v.number)
.unwrap_or_default();

// Curie sys contract upgrade
let is_curie_fork_block =
curie::is_curie_fork(state.block.chain_id, last_block_num.as_u64());
if is_curie_fork_block {
curie::apply_curie(&mut state, &mut end_block_step)?;
}

let mut push_op = |step: &mut ExecStep, rwc: RWCounter, rw: RW, op: StartOp| {
let op_ref = state.block.container.insert(Operation::new(rwc, rw, op));
Expand Down
96 changes: 96 additions & 0 deletions bus-mapping/src/circuit_input_builder/curie.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Adapted from https://github.com/scroll-tech/go-ethereum/blob/8dc419a70b94f5ca185dcf818a48a3bd2eefc392/consensus/misc/curie.go

use eth_types::{
utils::{hash_code, hash_code_keccak},
ToWord, Word,
};

use crate::{
l2_predeployed::l1_gas_price_oracle,
operation::{AccountField, AccountOp, StorageOp, RW},
Error,
};

use super::{CircuitInputStateRef, ExecStep};

/// Whether this blk is the hardfork height of curie
pub fn is_curie_fork(chain_id: u64, blk: u64) -> bool {
if chain_id == 222222 && blk == 5 {
log::info!("enable curie fork: chain id {chain_id} block {blk}");
return true;
}
false
}

/// Insert needed rws for the contract upgrade
/// Num of rws: 7
pub fn apply_curie(state: &mut CircuitInputStateRef, step: &mut ExecStep) -> Result<(), Error> {
// The chunk should not includes other txs.
let v1_codesize = l1_gas_price_oracle::V1_BYTECODE.len();
let v1_codehash = hash_code(&l1_gas_price_oracle::V1_BYTECODE);
let v1_keccak_codehash = hash_code_keccak(&l1_gas_price_oracle::V1_BYTECODE);
log::debug!("l1_oracle poseidon codehash {:?}", v1_codehash);
log::debug!("l1_oracle keccak codehash {:?}", v1_keccak_codehash);
let v2_codesize = l1_gas_price_oracle::V2_BYTECODE.len();
let v2_codehash = hash_code(&l1_gas_price_oracle::V2_BYTECODE);
let v2_keccak_codehash = hash_code_keccak(&l1_gas_price_oracle::V2_BYTECODE);

state.push_op(
step,
RW::WRITE,
AccountOp {
address: *l1_gas_price_oracle::ADDRESS,
field: AccountField::CodeHash,
value_prev: v1_codehash.to_word(),
value: v2_codehash.to_word(),
},
)?;
state.push_op(
step,
RW::WRITE,
AccountOp {
address: *l1_gas_price_oracle::ADDRESS,
field: AccountField::KeccakCodeHash,
value_prev: v1_keccak_codehash.to_word(),
value: v2_keccak_codehash.to_word(),
},
)?;
state.push_op(
step,
RW::WRITE,
AccountOp {
address: *l1_gas_price_oracle::ADDRESS,
field: AccountField::CodeSize,
value_prev: v1_codesize.to_word(),
value: v2_codesize.to_word(),
},
)?;

for (slot, value) in [
(*l1_gas_price_oracle::IS_CURIE_SLOT, Word::from(1)),
(*l1_gas_price_oracle::L1_BLOB_BASEFEE_SLOT, Word::from(1)),
(
*l1_gas_price_oracle::COMMIT_SCALAR_SLOT,
*l1_gas_price_oracle::INITIAL_COMMIT_SCALAR,
),
(
*l1_gas_price_oracle::BLOB_SCALAR_SLOT,
*l1_gas_price_oracle::INITIAL_BLOB_SCALAR,
),
] {
state.push_op(
step,
RW::WRITE,
StorageOp::new(
*l1_gas_price_oracle::ADDRESS,
slot,
value,
Word::from(0),
0,
Word::zero(),
),
)?;
}

Ok(())
}
1 change: 1 addition & 0 deletions bus-mapping/src/data/v1_l1_oracle_bytecode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561001057600080fd5b50600436106100cf5760003560e01c8063715018a61161008c578063bede39b511610066578063bede39b51461018d578063de26c4a1146101a0578063f2fde38b146101b3578063f45e65d8146101c657600080fd5b8063715018a6146101475780638da5cb5b1461014f57806393e59dc11461017a57600080fd5b80630c18c162146100d45780633577afc5146100f05780633d0f963e1461010557806349948e0e14610118578063519b4bd31461012b5780637046559714610134575b600080fd5b6100dd60025481565b6040519081526020015b60405180910390f35b6101036100fe366004610671565b6101cf565b005b61010361011336600461068a565b610291565b6100dd6101263660046106d0565b61031c565b6100dd60015481565b610103610142366004610671565b610361565b610103610416565b600054610162906001600160a01b031681565b6040516001600160a01b0390911681526020016100e7565b600454610162906001600160a01b031681565b61010361019b366004610671565b61044c565b6100dd6101ae3660046106d0565b610533565b6101036101c136600461068a565b610595565b6100dd60035481565b6000546001600160a01b031633146102025760405162461bcd60e51b81526004016101f990610781565b60405180910390fd5b621c9c388111156102555760405162461bcd60e51b815260206004820152601760248201527f657863656564206d6178696d756d206f7665726865616400000000000000000060448201526064016101f9565b60028190556040518181527f32740b35c0ea213650f60d44366b4fb211c9033b50714e4a1d34e65d5beb9bb4906020015b60405180910390a150565b6000546001600160a01b031633146102bb5760405162461bcd60e51b81526004016101f990610781565b600480546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527f22d1c35fe072d2e42c3c8f9bd4a0d34aa84a0101d020a62517b33fdb3174e5f7910160405180910390a15050565b60008061032883610533565b905060006001548261033a91906107b8565b9050633b9aca006003548261034f91906107b8565b61035991906107e5565b949350505050565b6000546001600160a01b0316331461038b5760405162461bcd60e51b81526004016101f990610781565b61039b633b9aca006103e86107b8565b8111156103e15760405162461bcd60e51b8152602060048201526014602482015273657863656564206d6178696d756d207363616c6560601b60448201526064016101f9565b60038190556040518181527f3336cd9708eaf2769a0f0dc0679f30e80f15dcd88d1921b5a16858e8b85c591a90602001610286565b6000546001600160a01b031633146104405760405162461bcd60e51b81526004016101f990610781565b61044a6000610621565b565b6004805460405163efc7840160e01b815233928101929092526001600160a01b03169063efc7840190602401602060405180830381865afa158015610495573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104b99190610807565b6104fe5760405162461bcd60e51b81526020600482015260166024820152752737ba103bb434ba32b634b9ba32b21039b2b73232b960511b60448201526064016101f9565b60018190556040518181527f351fb23757bb5ea0546c85b7996ddd7155f96b939ebaa5ff7bc49c75f27f2c4490602001610286565b80516000908190815b818110156105865784818151811061055657610556610829565b01602001516001600160f81b0319166000036105775760048301925061057e565b6010830192505b60010161053c565b50506002540160400192915050565b6000546001600160a01b031633146105bf5760405162461bcd60e51b81526004016101f990610781565b6001600160a01b0381166106155760405162461bcd60e51b815260206004820152601d60248201527f6e6577206f776e657220697320746865207a65726f206164647265737300000060448201526064016101f9565b61061e81610621565b50565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006020828403121561068357600080fd5b5035919050565b60006020828403121561069c57600080fd5b81356001600160a01b03811681146106b357600080fd5b9392505050565b634e487b7160e01b600052604160045260246000fd5b6000602082840312156106e257600080fd5b813567ffffffffffffffff808211156106fa57600080fd5b818401915084601f83011261070e57600080fd5b813581811115610720576107206106ba565b604051601f8201601f19908116603f01168101908382118183101715610748576107486106ba565b8160405282815287602084870101111561076157600080fd5b826020860160208301376000928101602001929092525095945050505050565b60208082526017908201527f63616c6c6572206973206e6f7420746865206f776e6572000000000000000000604082015260600190565b60008160001904831182151516156107e057634e487b7160e01b600052601160045260246000fd5b500290565b60008261080257634e487b7160e01b600052601260045260246000fd5b500490565b60006020828403121561081957600080fd5b815180151581146106b357600080fd5b634e487b7160e01b600052603260045260246000fdfea26469706673582212205ea335809638809cf032c794fd966e2439020737b1dcc2218435cb438286efcf64736f6c63430008100033
1 change: 1 addition & 0 deletions bus-mapping/src/data/v2_l1_oracle_bytecode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561000f575f80fd5b5060043610610132575f3560e01c8063715018a6116100b4578063a911d77f11610079578063a911d77f1461024c578063bede39b514610254578063de26c4a114610267578063e88a60ad1461027a578063f2fde38b1461028d578063f45e65d8146102a0575f80fd5b8063715018a6146101eb57806384189161146101f35780638da5cb5b146101fc57806393e59dc114610226578063944b247f14610239575f80fd5b80633d0f963e116100fa5780633d0f963e146101a057806349948e0e146101b3578063519b4bd3146101c65780636a5e67e5146101cf57806370465597146101d8575f80fd5b80630c18c1621461013657806313dad5be1461015257806323e524ac1461016f5780633577afc51461017857806339455d3a1461018d575b5f80fd5b61013f60025481565b6040519081526020015b60405180910390f35b60085461015f9060ff1681565b6040519015158152602001610149565b61013f60065481565b61018b6101863660046109c3565b6102a9565b005b61018b61019b3660046109da565b61033b565b61018b6101ae3660046109fa565b610438565b61013f6101c1366004610a3b565b6104bb565b61013f60015481565b61013f60075481565b61018b6101e63660046109c3565b6104e0565b61018b61056e565b61013f60055481565b5f5461020e906001600160a01b031681565b6040516001600160a01b039091168152602001610149565b60045461020e906001600160a01b031681565b61018b6102473660046109c3565b6105a2565b61018b610636565b61018b6102623660046109c3565b610692565b61013f610275366004610a3b565b61074f565b61018b6102883660046109c3565b61076c565b61018b61029b3660046109fa565b610800565b61013f60035481565b5f546001600160a01b031633146102db5760405162461bcd60e51b81526004016102d290610ae6565b60405180910390fd5b621c9c388111156102ff57604051635742c80560e11b815260040160405180910390fd5b60028190556040518181527f32740b35c0ea213650f60d44366b4fb211c9033b50714e4a1d34e65d5beb9bb4906020015b60405180910390a150565b6004805460405163efc7840160e01b815233928101929092526001600160a01b03169063efc7840190602401602060405180830381865afa158015610382573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103a69190610b1d565b6103c3576040516326b3506d60e11b815260040160405180910390fd5b600182905560058190556040518281527f351fb23757bb5ea0546c85b7996ddd7155f96b939ebaa5ff7bc49c75f27f2c449060200160405180910390a16040518181527f9a14bfb5d18c4c3cf14cae19c23d7cf1bcede357ea40ca1f75cd49542c71c214906020015b60405180910390a15050565b5f546001600160a01b031633146104615760405162461bcd60e51b81526004016102d290610ae6565b600480546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527f22d1c35fe072d2e42c3c8f9bd4a0d34aa84a0101d020a62517b33fdb3174e5f7910161042c565b6008545f9060ff16156104d7576104d18261088b565b92915050565b6104d1826108d1565b5f546001600160a01b031633146105095760405162461bcd60e51b81526004016102d290610ae6565b610519633b9aca006103e8610b50565b81111561053957604051631e44fdeb60e11b815260040160405180910390fd5b60038190556040518181527f3336cd9708eaf2769a0f0dc0679f30e80f15dcd88d1921b5a16858e8b85c591a90602001610330565b5f546001600160a01b031633146105975760405162461bcd60e51b81526004016102d290610ae6565b6105a05f610914565b565b5f546001600160a01b031633146105cb5760405162461bcd60e51b81526004016102d290610ae6565b6105e1633b9aca00670de0b6b3a7640000610b50565b8111156106015760405163874f603160e01b815260040160405180910390fd5b60068190556040518181527f2ab3f5a4ebbcbf3c24f62f5454f52f10e1a8c9dcc5acac8f19199ce881a6a10890602001610330565b5f546001600160a01b0316331461065f5760405162461bcd60e51b81526004016102d290610ae6565b60085460ff1615610683576040516379f9c57560e01b815260040160405180910390fd5b6008805460ff19166001179055565b6004805460405163efc7840160e01b815233928101929092526001600160a01b03169063efc7840190602401602060405180830381865afa1580156106d9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106fd9190610b1d565b61071a576040516326b3506d60e11b815260040160405180910390fd5b60018190556040518181527f351fb23757bb5ea0546c85b7996ddd7155f96b939ebaa5ff7bc49c75f27f2c4490602001610330565b6008545f9060ff161561076357505f919050565b6104d182610963565b5f546001600160a01b031633146107955760405162461bcd60e51b81526004016102d290610ae6565b6107ab633b9aca00670de0b6b3a7640000610b50565b8111156107cb5760405163f37ec21560e01b815260040160405180910390fd5b60078190556040518181527f6b332a036d8c3ead57dcb06c87243bd7a2aed015ddf2d0528c2501dae56331aa90602001610330565b5f546001600160a01b031633146108295760405162461bcd60e51b81526004016102d290610ae6565b6001600160a01b03811661087f5760405162461bcd60e51b815260206004820152601d60248201527f6e6577206f776e657220697320746865207a65726f206164647265737300000060448201526064016102d2565b61088881610914565b50565b5f633b9aca0060055483516007546108a39190610b50565b6108ad9190610b50565b6001546006546108bd9190610b50565b6108c79190610b67565b6104d19190610b7a565b5f806108dc83610963565b90505f600154826108ed9190610b50565b9050633b9aca00600354826109029190610b50565b61090c9190610b7a565b949350505050565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80515f908190815b818110156109b45784818151811061098557610985610b99565b01602001516001600160f81b0319165f036109a5576004830192506109ac565b6010830192505b60010161096b565b50506002540160400192915050565b5f602082840312156109d3575f80fd5b5035919050565b5f80604083850312156109eb575f80fd5b50508035926020909101359150565b5f60208284031215610a0a575f80fd5b81356001600160a01b0381168114610a20575f80fd5b9392505050565b634e487b7160e01b5f52604160045260245ffd5b5f60208284031215610a4b575f80fd5b813567ffffffffffffffff80821115610a62575f80fd5b818401915084601f830112610a75575f80fd5b813581811115610a8757610a87610a27565b604051601f8201601f19908116603f01168101908382118183101715610aaf57610aaf610a27565b81604052828152876020848701011115610ac7575f80fd5b826020860160208301375f928101602001929092525095945050505050565b60208082526017908201527f63616c6c6572206973206e6f7420746865206f776e6572000000000000000000604082015260600190565b5f60208284031215610b2d575f80fd5b81518015158114610a20575f80fd5b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176104d1576104d1610b3c565b808201808211156104d1576104d1610b3c565b5f82610b9457634e487b7160e01b5f52601260045260245ffd5b500490565b634e487b7160e01b5f52603260045260245ffdfea264697066735822122026efd5c02d1e8b77125546f0d1a9f9cf602e478f0243c4762564ad98d7047ecb64736f6c63430008180033
8 changes: 4 additions & 4 deletions bus-mapping/src/evm/opcodes/extcodesize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ impl Opcode for Extcodesize {
(
account.code_hash,
if cfg!(feature = "scroll") {
debug_assert_eq!(
account.code_size,
state.code(account.code_hash)?.len().into()
);
//debug_assert_eq!(
// account.code_size,
// state.code(account.code_hash)?.len().into()
//);
account.code_size
} else {
state.code(account.code_hash)?.len().into()
Expand Down
25 changes: 25 additions & 0 deletions bus-mapping/src/l2_predeployed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! l2 predeployed contract helpers

// Copied from https://github.com/scroll-tech/go-ethereum/blob/8dc419a70b94f5ca185dcf818a48a3bd2eefc392/rollup/rcfg/config.go#L42

use eth_types::Address;

/// helper for L2MessageQueue contract
Expand All @@ -16,6 +18,7 @@ pub mod message_queue {
}

/// Helper for L1GasPriceOracle contract
#[allow(missing_docs)]
pub mod l1_gas_price_oracle {
use eth_types::{Address, U256};
use std::{str::FromStr, sync::LazyLock};
Expand All @@ -25,8 +28,30 @@ pub mod l1_gas_price_oracle {
LazyLock::new(|| Address::from_str("0x5300000000000000000000000000000000000002").unwrap());
/// L1 base fee slot in L1GasPriceOracle
pub static BASE_FEE_SLOT: LazyLock<U256> = LazyLock::new(|| U256::from(1));

/// The following 2 slots will be depreciated after curie fork
/// L1 overhead slot in L1GasPriceOracle
pub static OVERHEAD_SLOT: LazyLock<U256> = LazyLock::new(|| U256::from(2));
/// L1 scalar slot in L1GasPriceOracle
pub static SCALAR_SLOT: LazyLock<U256> = LazyLock::new(|| U256::from(3));

/// THe following 3 slots plus `BASE_FEE_SLOT` will be used for l1 fee after curie fork
pub static L1_BLOB_BASEFEE_SLOT: LazyLock<U256> = LazyLock::new(|| U256::from(5));
pub static COMMIT_SCALAR_SLOT: LazyLock<U256> = LazyLock::new(|| U256::from(6));
pub static BLOB_SCALAR_SLOT: LazyLock<U256> = LazyLock::new(|| U256::from(7));
pub static IS_CURIE_SLOT: LazyLock<U256> = LazyLock::new(|| U256::from(8));
pub static INITIAL_COMMIT_SCALAR: LazyLock<U256> =
LazyLock::new(|| U256::from(230759955285u64));
pub static INITIAL_BLOB_SCALAR: LazyLock<U256> = LazyLock::new(|| U256::from(417565260));

/// Bytecode before curie hardfork
/// curl 127.0.0.1:8545 -X POST -H "Content-Type: application/json" --data
/// '{"method":"eth_getCode","params":["0x5300000000000000000000000000000000000002","latest"],"
/// id":1,"jsonrpc":"2.0"}'
pub static V1_BYTECODE: LazyLock<Vec<u8>> =
LazyLock::new(|| hex::decode(include_str!("./data/v1_l1_oracle_bytecode.txt")).unwrap());
/// Bytecode after curie hardfork
/// https://github.com/scroll-tech/go-ethereum/blob/8dc419a70b94f5ca185dcf818a48a3bd2eefc392/rollup/rcfg/config.go#L42
pub static V2_BYTECODE: LazyLock<Vec<u8>> =
LazyLock::new(|| hex::decode(include_str!("./data/v2_l1_oracle_bytecode.txt")).unwrap());
}
2 changes: 1 addition & 1 deletion prover/src/common/prover/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Prover {

let (params, pk) = self.params_and_pk(id, degree, &circuit)?;
log::info!(
"super_circuit vk transcript_repr {:?}",
"gen_evm_proof vk transcript_repr {:?}",
pk.get_vk().transcript_repr()
);
let instances = circuit.instances();
Expand Down
Loading