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 26 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
22 changes: 22 additions & 0 deletions Cargo.lock

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

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

[patch.crates-io]
Expand Down
1 change: 1 addition & 0 deletions bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ eth-types = { path = "../eth-types" }
gadgets = { path = "../gadgets" }
keccak256 = { path = "../keccak256" }
mock = { path = "../mock", optional = true }
taiko-mock = { path = "../taiko-mock", optional = true }

ethers-core = "=2.0.0"
ethers-providers = "=2.0.0"
Expand Down
6 changes: 6 additions & 0 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 @@ -409,6 +411,7 @@ pub struct BuilderClient<P: JsonRpcClient> {
cli: GethClient<P>,
chain_id: Word,
circuits_params: CircuitsParams,
protocol_instance: ProtocolInstance,
}

/// Get State Accesses from TxExecTraces
Expand Down Expand Up @@ -468,13 +471,15 @@ impl<P: JsonRpcClient> BuilderClient<P> {
pub async fn new(
client: GethClient<P>,
circuits_params: CircuitsParams,
protocol_instance: 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 @@ -615,6 +620,7 @@ impl<P: JsonRpcClient> BuilderClient<P> {
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)?;
Expand Down
5 changes: 5 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,8 @@ pub struct Block {
pub circuits_params: CircuitsParams,
/// Original block from geth
pub eth_block: eth_types::Block<eth_types::Transaction>,
/// Protocol instance from protocol
pub protocol_instance: ProtocolInstance,
}

impl Block {
Expand All @@ -100,6 +103,7 @@ impl Block {
prev_state_root: Word,
eth_block: &eth_types::Block<eth_types::Transaction>,
circuits_params: CircuitsParams,
protocol_instance: 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 +145,7 @@ impl Block {
sha3_inputs: Vec::new(),
circuits_params,
eth_block: eth_block.clone(),
protocol_instance,
})
}

Expand Down
36 changes: 15 additions & 21 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,13 @@ impl<'a> CircuitInputStateRef<'a> {
&& (matches!(rw, RW::READ) || (op.value_prev.is_zero() && op.value.is_zero())))
&& account.is_empty()
{
panic!(
"RWTable Account field {:?} lookup to non-existing account rwc: {}, op: {:?}",
rw, self.block_ctx.rwc.0, op
);
// FIXME: This is a temporary workaround for the above issue, which allows empty
// accounts to read for taiko's 1559

// panic!(
// "RWTable Account field {:?} lookup to non-existing account rwc: {}, op: {:?}",
// rw, self.block_ctx.rwc.0, op
// );
}
// -- sanity check end --
// Perform the write to the account in the StateDB
Expand Down Expand Up @@ -474,29 +477,21 @@ impl<'a> CircuitInputStateRef<'a> {
must_create: bool,
value: Word,
fee: Option<Word>,
is_anchor_tx: bool,
) -> Result<(), Error> {
let (found, sender_account) = self.sdb.get_account(&sender);
if !found {
return Err(Error::AccountNotFound(sender));
}
let mut sender_balance_prev = sender_account.balance;
if !is_anchor_tx {
debug_assert!(
sender_account.balance >= value + fee.unwrap_or_default(),
"invalid amount balance {:?} value {:?} fee {:?}",
sender_balance_prev,
value,
fee
);
}
debug_assert!(
sender_account.balance >= value + fee.unwrap_or_default(),
"invalid amount balance {:?} value {:?} fee {:?}",
sender_balance_prev,
value,
fee
);
if let Some(fee) = fee {
let sender_balance = if is_anchor_tx {
// anchor tx doesn't need fee
sender_balance_prev
} else {
sender_balance_prev - fee
};
let sender_balance = sender_balance_prev - fee;
log::trace!(
"sender balance update with fee (not reversible): {:?} {:?}->{:?}",
sender,
Expand Down Expand Up @@ -583,7 +578,6 @@ impl<'a> CircuitInputStateRef<'a> {
must_create,
value,
None,
false,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

use std::iter;

use crate::{table::PiFieldTag, util::rlc_be_bytes};
use eth_types::{Address, Bytes, Field, Hash, ToBigEndian, ToWord, Word, H256};
use halo2_proofs::circuit::Value;
use eth_types::{Address, Bytes, Hash, ToBigEndian, ToWord, Word, H256};
use keccak256::plain::Keccak;

// hash(anchor)
const ANCHOR_TX_METHOD_SIGNATURE: u32 = 0xda69d3db;
/// hash(anchor)
pub const ANCHOR_TX_METHOD_SIGNATURE: u32 = 0xda69d3db;

/// Taiko witness
#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -129,42 +127,6 @@ impl ProtocolInstance {
result.extend_from_slice(&(self.parent_gas_used as u64).to_word().to_be_bytes());
result.into()
}

/// Assignments for pi table
pub fn table_assignments<F: Field>(&self, randomness: Value<F>) -> [[Value<F>; 2]; 6] {
[
[
Value::known(F::from(PiFieldTag::Null as u64)),
Value::known(F::ZERO),
],
[
Value::known(F::from(PiFieldTag::MethodSign as u64)),
Value::known(F::from(ANCHOR_TX_METHOD_SIGNATURE as u64)),
],
[
Value::known(F::from(PiFieldTag::L1Hash as u64)),
rlc_be_bytes(&self.meta_hash.l1_hash.to_fixed_bytes(), randomness),
],
[
Value::known(F::from(PiFieldTag::L1SignalRoot as u64)),
rlc_be_bytes(&self.signal_root.to_fixed_bytes(), randomness),
],
[
Value::known(F::from(PiFieldTag::L1Height as u64)),
rlc_be_bytes(
&self.meta_hash.l1_height.to_word().to_be_bytes(),
randomness,
),
],
[
Value::known(F::from(PiFieldTag::ParentGasUsed as u64)),
rlc_be_bytes(
&(self.parent_gas_used as u64).to_word().to_be_bytes(),
randomness,
),
],
]
}
}

#[cfg(test)]
Expand Down
29 changes: 27 additions & 2 deletions bus-mapping/src/evm/opcodes/begin_end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ fn gen_begin_tx_steps(state: &mut CircuitInputStateRef) -> Result<ExecStep, Erro
call.is_create(),
call.value,
Some(state.tx.tx.gas_price * state.tx.gas()),
state.tx_ctx.is_anchor_tx(),
)?;

// In case of contract creation we wish to verify the correctness of the
Expand Down Expand Up @@ -265,7 +264,13 @@ fn gen_end_tx_steps(state: &mut CircuitInputStateRef) -> Result<ExecStep, Error>
caller_balance_prev,
)?;

let effective_tip = state.tx.tx.gas_price - state.block.base_fee;
let base_fee = if state.tx_ctx.is_anchor_tx() {
0.into()
} else {
state.block.base_fee
};

let effective_tip = state.tx.tx.gas_price - base_fee;
let (found, coinbase_account) = state.sdb.get_account(&state.block.coinbase);
if !found {
return Err(Error::AccountNotFound(state.block.coinbase));
Expand All @@ -281,6 +286,26 @@ fn gen_end_tx_steps(state: &mut CircuitInputStateRef) -> Result<ExecStep, Error>
coinbase_balance_prev,
)?;

// add treasury account
let (found, treasury_account) = state
.sdb
.get_account(&state.block.protocol_instance.meta_hash.treasury);
if !found {
return Err(Error::AccountNotFound(
state.block.protocol_instance.meta_hash.treasury,
));
}
let treasury_balance_prev = treasury_account.balance;
let treasury_balance =
treasury_balance_prev + base_fee * (state.tx.gas() - exec_step.gas_left.0);
state.account_write(
&mut exec_step,
state.block.protocol_instance.meta_hash.treasury,
AccountField::Balance,
treasury_balance,
treasury_balance_prev,
)?;

// handle tx receipt tag
state.tx_receipt_write(
&mut exec_step,
Expand Down
1 change: 1 addition & 0 deletions bus-mapping/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl BlockData {
Word::default(),
&self.eth_block,
self.circuits_params,
Default::default(),
)
.unwrap(),
)
Expand Down
3 changes: 1 addition & 2 deletions circuit-benchmarks/src/taiko_super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use zkevm_circuits::{
taiko_aggregation::AccumulationSchemeType, KzgDk, KzgSvk, TaikoAggregationCircuit,
},
taiko_super_circuit::{test::block_1tx, SuperCircuit},
witness::ProtocolInstance,
};

use bus_mapping::circuit_input_builder::CircuitsParams;
use bus_mapping::circuit_input_builder::{CircuitsParams, ProtocolInstance};

use rand::SeedableRng;

Expand Down
26 changes: 21 additions & 5 deletions eth-types/src/geth_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
ToWord, Word, U64,
};
use ethers_core::{
types::{transaction::response, NameOrAddress, TransactionRequest},
types::{transaction::response, Eip1559TransactionRequest, NameOrAddress, TransactionRequest},
utils::get_contract_address,
};
use ethers_signers::{LocalWallet, Signer};
Expand Down Expand Up @@ -158,8 +158,8 @@ impl From<&Transaction> for crate::Transaction {
gas: tx.gas_limit.to_word(),
value: tx.value,
gas_price: Some(tx.gas_price),
max_priority_fee_per_gas: Some(tx.gas_fee_cap),
max_fee_per_gas: Some(tx.gas_tip_cap),
max_priority_fee_per_gas: Some(tx.gas_tip_cap),
max_fee_per_gas: Some(tx.gas_fee_cap),
input: tx.call_data.clone(),
access_list: tx.access_list.clone(),
v: tx.v.into(),
Expand All @@ -179,8 +179,8 @@ impl From<&crate::Transaction> for Transaction {
gas_limit: tx.gas.as_u64().into(),
value: tx.value,
gas_price: tx.gas_price.unwrap_or_default(),
gas_fee_cap: tx.max_priority_fee_per_gas.unwrap_or_default(),
gas_tip_cap: tx.max_fee_per_gas.unwrap_or_default(),
gas_tip_cap: tx.max_priority_fee_per_gas.unwrap_or_default(),
gas_fee_cap: tx.max_fee_per_gas.unwrap_or_default(),
call_data: tx.input.clone(),
access_list: tx.access_list.clone(),
v: tx.v.as_u64(),
Expand All @@ -205,6 +205,22 @@ impl From<&Transaction> for TransactionRequest {
}
}

impl From<&Transaction> for Eip1559TransactionRequest {
fn from(tx: &Transaction) -> Eip1559TransactionRequest {
Eip1559TransactionRequest {
from: Some(tx.from),
to: tx.to.map(NameOrAddress::Address),
gas: Some(tx.gas_limit.to_word()),
max_priority_fee_per_gas: Some(tx.gas_tip_cap),
max_fee_per_gas: Some(tx.gas_fee_cap),
value: Some(tx.value),
data: Some(tx.call_data.clone()),
nonce: Some(tx.nonce.to_word()),
..Default::default()
}
}
}

fn recover_v(v: u64, chain_id: u64) -> u64 {
let addition = chain_id * 2 + 35;
if v >= addition {
Expand Down
Loading