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

feat: BeginTx and EndTx support taiko's 1559 #18

Closed
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 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
7175f7e
chore: remove TODO, support 1559 now
johntaiko Aug 12, 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
20 changes: 20 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"
"mock-taiko",
"testool",
]

[patch.crates-io]
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
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
19 changes: 19 additions & 0 deletions bus-mapping/src/evm/opcodes/begin_end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,25 @@ 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 + state.block.base_fee * (state.tx.gas() - exec_step.gas_left.0);
state.account_write(
&mut exec_step,
state.block.coinbase,
johntaiko marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 3 additions & 1 deletion integration-tests/src/integration_test_circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ async fn gen_inputs(
eth_types::Block<eth_types::Transaction>,
) {
let cli = get_client();
let cli = BuilderClient::new(cli, CIRCUITS_PARAMS).await.unwrap();
let cli = BuilderClient::new(cli, CIRCUITS_PARAMS, Default::default())
.await
.unwrap();

cli.gen_inputs(block_num).await.unwrap()
}
1 change: 1 addition & 0 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub async fn build_circuit_input_builder_block(block_num: u64) {
max_exp_steps: 1000,
max_keccak_rows: 0,
},
Default::default(),
)
.await
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions mock-taiko/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
24 changes: 24 additions & 0 deletions mock-taiko/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "mock-taiko"
version = "0.1.0"
edition = "2021"
authors = ["The appliedzkp team"]
license = "MIT OR Apache-2.0"

[dependencies]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", features = [
"circuit-params",
], tag = "v2023_04_20" }
eth-types = { path = "../eth-types" }
external-tracer = { path = "../external-tracer" }
lazy_static = "1.4"
itertools = "0.10.3"
ethers-signers = "=2.0.0"
ethers-core = "=2.0.0"
rand_chacha = "0.3"
rand = "0.8"
sha3 = "0.10"
num-bigint = { version = "0.4" }
num = "0.4"
libsecp256k1 = "0.7"
once_cell = "1.17.1"
84 changes: 84 additions & 0 deletions mock-taiko/src/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//! Mock Account definition and builder related methods.

use eth_types::{geth_types::Account, Address, Bytes, Word};
use std::collections::HashMap;

#[derive(Debug, Clone, Default)]
/// Mock structure which represents an Account and can be used for tests.
/// It contains all the builder-pattern methods required to be able to specify
/// any of its details.
pub struct MockAccount {
/// Address
pub address: Address,
/// nonce
pub nonce: u64,
/// Balance
pub balance: Word,
/// EVM Code
pub code: Bytes,
/// Storage
pub storage: HashMap<Word, Word>,
}

impl From<MockAccount> for Account {
fn from(mock: MockAccount) -> Self {
Account {
address: mock.address,
nonce: mock.nonce.into(),
balance: mock.balance,
code: mock.code,
storage: mock.storage,
}
}
}

impl MockAccount {
/// Set address field for the MockAccount.
pub fn address(&mut self, address: Address) -> &mut Self {
self.address = address;
self
}

/// Set nonce field for the MockAccount.
pub fn nonce(&mut self, nonce: u64) -> &mut Self {
self.nonce = nonce;
self
}

/// Set balance field for the MockAccount.
pub fn balance(&mut self, balance: Word) -> &mut Self {
self.balance = balance;
self
}

/// Set code field for the MockAccount.
pub fn code<T: Into<Bytes>>(&mut self, code: T) -> &mut Self {
self.code = code.into();
self
}

/// Add storage field for the MockAccount by passing an iterator over the
/// key-value tuples of type [(`Word`, `Word`)].
pub fn storage<I: Iterator<Item = (Word, Word)>>(&mut self, storage: I) -> &mut Self {
storage.for_each(|pair| {
assert!(self.storage.insert(pair.0, pair.1).is_none());
});
self
}

/// Set all fields for the MockAccount based on their values in `account`.
pub fn account(&mut self, account: &Account) -> &mut Self {
self.address(account.address);
self.nonce(account.nonce.as_u64());
self.balance(account.balance);
self.code(account.code.clone());
self.storage(account.storage.iter().map(|(k, v)| (*k, *v)));
self
}

/// Finalizes the current MockAccount under construction returning a new
/// instance to it.
pub fn build(&mut self) -> Self {
self.to_owned()
}
}
Loading