Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Support eip-1559 and Evm-circuit in aggregation #136

Merged
merged 61 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4da9a36
feat: BeginTx and EndTx support taiko's 1559
johntaiko Jul 31, 2023
a7d04c3
chore: update gitignore
johntaiko Jul 31, 2023
9485602
chore: mark TODO
johntaiko Jul 31, 2023
5c23399
feat: support effective gas price
johntaiko Jul 31, 2023
07b6c22
docs: solve TODO
johntaiko Jul 31, 2023
9752cdb
feat: mock with 1559 support and anchor support
johntaiko Aug 3, 2023
c973c78
fix: add l2 contract address into mock data
johntaiko Aug 3, 2023
61798cd
feat: use taiko-geth for evm execution
johntaiko Aug 7, 2023
d8800ab
fix: duplicate symbol
johntaiko Aug 7, 2023
5e9573c
fix: use taiko-geth
johntaiko Aug 7, 2023
4bc10f8
fix: anchor without updating balance
johntaiko Aug 7, 2023
68052dc
fix: update treasury with base_fee
johntaiko Aug 7, 2023
182c5e5
fix: use anchor flag in context
johntaiko Aug 8, 2023
03c2047
feat: treat anchor specially
johntaiko Aug 8, 2023
aff5000
feat: treat anchor's gas_price as zero
johntaiko Aug 8, 2023
917d836
fix: testcases
johntaiko Aug 8, 2023
ebe34f7
Update zkevm-circuits/src/evm_circuit/execution/end_tx.rs
johntaiko Aug 10, 2023
848f896
Update zkevm-circuits/src/evm_circuit/execution/end_tx.rs
johntaiko Aug 10, 2023
42e25ae
Update zkevm-circuits/src/evm_circuit/execution/end_tx.rs
johntaiko Aug 10, 2023
4c208e6
fix: comments in pr
johntaiko Aug 10, 2023
993d6da
chore: add FIXME
johntaiko Aug 10, 2023
740e655
fix: mock tx's signature with eip-1559
johntaiko Aug 10, 2023
9b64614
fix: increase the step hight instead of width
johntaiko Aug 10, 2023
8c33dc1
feat: add treasury account in the block table
johntaiko Aug 10, 2023
11cdc1b
fix: taiko-mock's feature
johntaiko Aug 10, 2023
c6243e0
fix: need lookup the treasury
johntaiko Aug 10, 2023
218bd67
feat: support dummy PUSH0
johntaiko Aug 11, 2023
7175f7e
chore: remove TODO, support 1559 now
johntaiko Aug 12, 2023
564fc1d
fix: anchor circuit in eip-1559
johntaiko Aug 14, 2023
822c2b7
Merge pull request #2 from johntaiko/feat/anchort_support_1559
johntaiko Aug 14, 2023
bea7a94
Merge pull request #1 from johntaiko/feat/shanghai_fork
johntaiko Aug 14, 2023
48fe046
feat: bus-mapping support 1559
johntaiko Aug 14, 2023
9331a39
Merge pull request #3 from johntaiko/feat/bus_mapping_1559
johntaiko Aug 14, 2023
68fd2d6
feat: add evm_circuit into super_circuit
johntaiko Aug 14, 2023
04dd86e
Merge pull request #4 from johntaiko/feat/evm_circuit_aggregation
johntaiko Aug 14, 2023
0c244c8
feat(mock): add indicator for anchor usage
johntaiko Aug 16, 2023
6f960a5
feat: let mock fit both with taiko and normal
johntaiko Aug 17, 2023
64e5b6a
feat: add taiko flag for tests
johntaiko Aug 18, 2023
f820a0e
fix: some break tests
johntaiko Aug 18, 2023
8b1d0a1
fix: use eip1559 signature
johntaiko Aug 19, 2023
3428db0
fix: tests
johntaiko Aug 20, 2023
873da0a
fix: all tests
johntaiko Aug 20, 2023
4322b32
fix: only support gas_tip_cap and gas_fee_cap
johntaiko Aug 20, 2023
10f4077
chore: ignore unhelpful tests
johntaiko Aug 20, 2023
fb15f16
fix: taiko_super tests
johntaiko Aug 20, 2023
c6ff751
Merge pull request #7 from johntaiko/feat/mock_1559_planb
johntaiko Aug 20, 2023
1c8cb90
fix: naming style
johntaiko Aug 20, 2023
46c5125
feat: add `shanghai` feature and make CI pass with Shanghai geth trac…
silathdiir Jun 2, 2023
83027a2
fix: remove legacy tx signature
johntaiko Aug 20, 2023
be39d56
fix: taiko super circuit benchmarks
johntaiko Aug 21, 2023
0b21c04
emm: need more than degree 24 to run aggregation
johntaiko Aug 21, 2023
fb475b2
fix: add treasury into state db
johntaiko Aug 21, 2023
ada675d
feat: add CircuitExt for zkchain
johntaiko Aug 21, 2023
f11d6fc
fix: eip-4399 use mix_hash instead of difficulty
johntaiko Aug 21, 2023
1eb138f
fix: endian
johntaiko Aug 21, 2023
fdc2898
fix: update anchor method signature
johntaiko Aug 21, 2023
2b91ea2
fix: add evm sha3
johntaiko Aug 21, 2023
5c3d641
fix(comment): typo or mistake
johntaiko Aug 22, 2023
4fdac73
feat: remove difficulty after eip-4399 aka POS
johntaiko Aug 22, 2023
c1af675
fix: opcode state print
johntaiko Aug 28, 2023
536165e
Merge branch 'feat/for-a6-release' of gh_work:taikoxyz/zkevm-circuits…
johntaiko Sep 21, 2023
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
.vscode
.idea
/generated
*.srs
*.log
*.json
*.yul
*.sol
6 changes: 6 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
"eth-types",
"external-tracer",
"mock",
"testool"
"testool",
]

[patch.crates-io]
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ fmt: ## Check whether the code is formated correctly

test: ## Run tests for all the workspace members
# Run light tests
@cargo test --release --all --all-features --exclude integration-tests --exclude circuit-benchmarks
@cargo test --release --all --all-features --exclude integration-tests --exclude circuit-benchmarks --exclude testool
# Run heavy tests serially to avoid OOM
@cargo test --release --all --all-features --exclude integration-tests --exclude circuit-benchmarks serial_ -- --ignored --test-threads 1
@cargo test --release --all --all-features --exclude integration-tests --exclude circuit-benchmarks --exclude testool serial_ -- --ignored # --test-threads 1


test_doc: ## Test the docs
Expand Down
98 changes: 37 additions & 61 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod block;
mod call;
mod execution;
mod input_state_ref;
mod protocol_instance;
#[cfg(test)]
mod tracer_tests;
mod transaction;
Expand Down Expand Up @@ -34,6 +35,7 @@ pub use execution::{
pub use input_state_ref::CircuitInputStateRef;
use itertools::Itertools;
use log::warn;
pub use protocol_instance::{left_shift, MetaHash, ProtocolInstance, ANCHOR_TX_METHOD_SIGNATURE};
use std::collections::HashMap;
pub use transaction::{Transaction, TransactionContext};

Expand Down Expand Up @@ -75,7 +77,7 @@ impl Default for CircuitsParams {
fn default() -> Self {
CircuitsParams {
max_rws: 1000,
max_txs: 1,
max_txs: 2, // more one for anchor
max_calldata: 256,
// TODO: Check whether this value is correct or we should increase/decrease based on
// this lib tests
Expand Down Expand Up @@ -151,6 +153,7 @@ impl<'a> CircuitInputBuilder {
/// Create a new Transaction from a [`eth_types::Transaction`].
pub fn new_tx(
&mut self,
eth_block: &EthBlock,
eth_tx: &eth_types::Transaction,
is_success: bool,
) -> Result<Transaction, Error> {
Expand All @@ -167,7 +170,15 @@ impl<'a> CircuitInputBuilder {
),
);

Transaction::new(call_id, &self.sdb, &mut self.code_db, eth_tx, is_success)
Transaction::new(
call_id,
&self.sdb,
&mut self.code_db,
eth_block,
eth_tx,
is_success,
self.block.is_taiko(),
)
}

/// Iterate over all generated CallContext RwCounterEndOfReversion
Expand Down Expand Up @@ -197,25 +208,14 @@ impl<'a> CircuitInputBuilder {
&mut self,
eth_block: &EthBlock,
geth_traces: &[eth_types::GethExecTrace],
) -> Result<(), Error> {
self.handle_block_with_anchor(eth_block, geth_traces, false)
}

/// Handle a block by handling each transaction to generate all the
/// associated operations.
pub fn handle_block_with_anchor(
&mut self,
eth_block: &EthBlock,
geth_traces: &[eth_types::GethExecTrace],
has_anchor_tx: bool,
) -> Result<(), Error> {
// accumulates gas across all txs in the block
for (tx_index, tx) in eth_block.transactions.iter().enumerate() {
let geth_trace = &geth_traces[tx_index];
self.handle_tx(
eth_block,
tx,
geth_trace,
has_anchor_tx && tx_index == 0,
tx_index + 1 == eth_block.transactions.len(),
)?;
}
Expand Down Expand Up @@ -279,13 +279,13 @@ impl<'a> CircuitInputBuilder {
/// generated operations.
fn handle_tx(
&mut self,
eth_block: &EthBlock,
eth_tx: &eth_types::Transaction,
geth_trace: &GethExecTrace,
is_anchor_tx: bool,
is_last_tx: bool,
) -> Result<(), Error> {
let mut tx = self.new_tx(eth_tx, !geth_trace.failed)?;
let mut tx_ctx = TransactionContext::new(eth_tx, geth_trace, is_anchor_tx, is_last_tx)?;
let mut tx = self.new_tx(eth_block, eth_tx, !geth_trace.failed)?;
let mut tx_ctx = TransactionContext::new(eth_tx, geth_trace, is_last_tx)?;

// Generate BeginTx step
let begin_tx_step = gen_associated_steps(
Expand Down Expand Up @@ -409,12 +409,14 @@ pub struct BuilderClient<P: JsonRpcClient> {
cli: GethClient<P>,
chain_id: Word,
circuits_params: CircuitsParams,
protocol_instance: Option<ProtocolInstance>,
}

/// Get State Accesses from TxExecTraces
pub fn get_state_accesses(
eth_block: &EthBlock,
geth_traces: &[eth_types::GethExecTrace],
protocol_instance: &Option<ProtocolInstance>,
) -> Result<AccessSet, Error> {
let mut block_access_trace = vec![Access::new(
None,
Expand All @@ -430,6 +432,15 @@ pub fn get_state_accesses(
let tx_access_trace = gen_state_access_trace(eth_block, tx, geth_trace)?;
block_access_trace.extend(tx_access_trace);
}
if let Some(pi) = protocol_instance {
block_access_trace.push(Access::new(
None,
RW::WRITE,
AccessValue::Account {
address: pi.meta_hash.treasury,
},
));
}

Ok(AccessSet::from(block_access_trace))
}
Expand Down Expand Up @@ -468,13 +479,15 @@ impl<P: JsonRpcClient> BuilderClient<P> {
pub async fn new(
client: GethClient<P>,
circuits_params: CircuitsParams,
protocol_instance: Option<ProtocolInstance>,
) -> Result<Self, Error> {
let chain_id = client.get_chain_id().await?;

Ok(Self {
cli: client,
chain_id: chain_id.into(),
circuits_params,
protocol_instance,
})
}

Expand Down Expand Up @@ -526,8 +539,9 @@ impl<P: JsonRpcClient> BuilderClient<P> {
pub fn get_state_accesses(
eth_block: &EthBlock,
geth_traces: &[eth_types::GethExecTrace],
protocol_instance: &Option<ProtocolInstance>,
) -> Result<AccessSet, Error> {
get_state_accesses(eth_block, geth_traces)
get_state_accesses(eth_block, geth_traces, protocol_instance)
}

/// Step 3. Query geth for all accounts, storage keys, and codes from
Expand Down Expand Up @@ -584,40 +598,17 @@ impl<P: JsonRpcClient> BuilderClient<P> {
geth_traces: &[eth_types::GethExecTrace],
history_hashes: Vec<Word>,
prev_state_root: Word,
) -> Result<CircuitInputBuilder, Error> {
self.gen_inputs_from_state_with_anchor(
sdb,
code_db,
eth_block,
geth_traces,
history_hashes,
prev_state_root,
false,
)
}

/// Step 5. For each step in TxExecTraces, gen the associated ops and state
/// circuit inputs
#[allow(clippy::too_many_arguments)]
pub fn gen_inputs_from_state_with_anchor(
&self,
sdb: StateDB,
code_db: CodeDB,
eth_block: &EthBlock,
geth_traces: &[eth_types::GethExecTrace],
history_hashes: Vec<Word>,
prev_state_root: Word,
has_anchor_tx: bool,
) -> Result<CircuitInputBuilder, Error> {
let block = Block::new(
self.chain_id,
history_hashes,
prev_state_root,
eth_block,
self.circuits_params,
self.protocol_instance.clone(),
)?;
let mut builder = CircuitInputBuilder::new(sdb, code_db, block);
builder.handle_block_with_anchor(eth_block, geth_traces, has_anchor_tx)?;
builder.handle_block(eth_block, geth_traces)?;
Ok(builder)
}

Expand All @@ -631,35 +622,20 @@ impl<P: JsonRpcClient> BuilderClient<P> {
eth_types::Block<eth_types::Transaction>,
),
Error,
> {
self.gen_inputs_with_anchor(block_num, false).await
}

/// Perform all the steps to generate the circuit inputs
pub async fn gen_inputs_with_anchor(
&self,
block_num: u64,
has_anchor_tx: bool,
) -> Result<
(
CircuitInputBuilder,
eth_types::Block<eth_types::Transaction>,
),
Error,
> {
let (eth_block, geth_traces, history_hashes, prev_state_root) =
self.get_block(block_num).await?;
let access_set = Self::get_state_accesses(&eth_block, &geth_traces)?;
let access_set =
Self::get_state_accesses(&eth_block, &geth_traces, &self.protocol_instance)?;
let (proofs, codes) = self.get_state(block_num, access_set).await?;
let (state_db, code_db) = Self::build_state_code_db(proofs, codes);
let builder = self.gen_inputs_from_state_with_anchor(
let builder = self.gen_inputs_from_state(
state_db,
code_db,
&eth_block,
&geth_traces,
history_hashes,
prev_state_root,
has_anchor_tx,
)?;
Ok((builder, eth_block))
}
Expand Down
11 changes: 11 additions & 0 deletions bus-mapping/src/circuit_input_builder/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use super::{
execution::ExecState, transaction::Transaction, CircuitsParams, CopyEvent, ExecStep, ExpEvent,
ProtocolInstance,
};
use crate::{
operation::{OperationContainer, RWCounter},
Expand Down Expand Up @@ -90,6 +91,9 @@ pub struct Block {
pub circuits_params: CircuitsParams,
/// Original block from geth
pub eth_block: eth_types::Block<eth_types::Transaction>,
/// Protocol instance from protocol
/// If this is set, means we are in the taiko context
pub protocol_instance: Option<ProtocolInstance>,
}

impl Block {
Expand All @@ -100,6 +104,7 @@ impl Block {
prev_state_root: Word,
eth_block: &eth_types::Block<eth_types::Transaction>,
circuits_params: CircuitsParams,
protocol_instance: Option<ProtocolInstance>,
) -> Result<Self, Error> {
if eth_block.base_fee_per_gas.is_none() {
// FIXME: resolve this once we have proper EIP-1559 support
Expand Down Expand Up @@ -141,6 +146,7 @@ impl Block {
sha3_inputs: Vec::new(),
circuits_params,
eth_block: eth_block.clone(),
protocol_instance,
})
}

Expand All @@ -149,6 +155,11 @@ impl Block {
&self.txs
}

/// Check if in the taiko context.
pub fn is_taiko(&self) -> bool {
self.protocol_instance.is_some()
}

#[cfg(test)]
pub fn txs_mut(&mut self) -> &mut Vec<Transaction> {
&mut self.txs
Expand Down
Loading
Loading