From c0039a3aa61759bbcbbedc4d00495983582c65b0 Mon Sep 17 00:00:00 2001
From: CeciliaZ030 <45245961+CeciliaZ030@users.noreply.github.com>
Date: Mon, 11 Dec 2023 13:28:26 +0300
Subject: [PATCH] A6 pi (#173)
* new ProtocolInstance
* refactored done
* debug
* fixed
* fix & clippy
---
.../protocol_instance.rs | 252 ++++++++----------
.../src/integration_public_data_circuits.rs | 18 +-
zkevm-circuits/src/table/keccak_table.rs | 1 -
zkevm-circuits/src/taiko_pi_circuit.rs | 133 +++++----
zkevm-circuits/src/taiko_pi_circuit/dev.rs | 14 +-
zkevm-circuits/src/taiko_pi_circuit/param.rs | 16 +-
zkevm-circuits/src/taiko_pi_circuit/test.rs | 12 +-
zkevm-circuits/src/taiko_super_circuit.rs | 21 +-
zkevm-circuits/src/witness/block.rs | 10 +-
9 files changed, 224 insertions(+), 253 deletions(-)
diff --git a/bus-mapping/src/circuit_input_builder/protocol_instance.rs b/bus-mapping/src/circuit_input_builder/protocol_instance.rs
index 846b31bafe..2973a5e487 100644
--- a/bus-mapping/src/circuit_input_builder/protocol_instance.rs
+++ b/bus-mapping/src/circuit_input_builder/protocol_instance.rs
@@ -1,13 +1,13 @@
#![allow(missing_docs)]
-use alloy_dyn_abi::DynSolValue;
-use alloy_primitives::{B256, U160, U256};
+use alloy_primitives::{B256, U256};
+
use alloy_sol_types::{sol, SolValue};
-use eth_types::{Address, Bytes, ToBigEndian, ToWord};
+use eth_types::Address;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use sha3::{Digest, Keccak256};
-use std::{iter, str::FromStr};
+use std::str::FromStr;
/// L1 signal service
pub static L1_SIGNAL_SERVICE: Lazy
= Lazy::new(|| {
@@ -28,170 +28,136 @@ pub static TREASURY: Lazy = Lazy::new(|| {
.expect("invalid treasury account")
});
-sol! {
- #[derive(Debug, Default, Deserialize, Serialize)]
- struct EthDeposit {
- address recipient;
- uint96 amount;
- uint64 id;
- }
-}
+pub const ANCHOR_METHOD_SIGNATURE: u32 = 0xda69d3db;
sol! {
#[derive(Debug, Default, Deserialize, Serialize)]
struct BlockMetadata {
- bytes32 l1Hash; // constrain: anchor call
- bytes32 difficulty; // constrain: l2 block's difficulty
- bytes32 txListHash; // constrain: l2 txlist
- bytes32 extraData; // constrain: l2 block's extra data
- uint64 id; // constrain: l2 block's number
- uint64 timestamp; // constrain: l2 block's timestamp
- uint64 l1Height; // constrain: anchor
- uint32 gasLimit; // constrain: l2 block's gas limit - anchor gas limit
- address coinbase; // constrain: L2 coinbase
- EthDeposit[] depositsProcessed; // constrain: l2 withdraw root
- }
-}
-
-#[inline]
-pub fn keccak(data: impl AsRef<[u8]>) -> [u8; 32] {
- // TODO: Remove this benchmarking code once performance testing is complete.
- // std::hint::black_box(sha2::Sha256::digest(&data));
- Keccak256::digest(data).into()
-}
-
-impl BlockMetadata {
- pub fn withdraws_root(&self) -> B256 {
- // FIXME: mpt root
- keccak(self.depositsProcessed.abi_encode()).into()
+ bytes32 l1Hash; // slot 1
+ bytes32 difficulty; // slot 2
+ bytes32 blobHash; //or txListHash (if Blob not yet supported), // slot 3
+ bytes32 extraData; // slot 4
+ bytes32 depositsHash; // slot 5
+ address coinbase; // L2 coinbase, // slot 6
+ uint64 id;
+ uint32 gasLimit;
+ uint64 timestamp; // slot 7
+ uint64 l1Height;
+ uint24 txListByteOffset;
+ uint24 txListByteSize;
+ uint16 minTier;
+ bool blobUsed;
+ bytes32 parentMetaHash; // slot 8
}
- // function hashMetadata(TaikoData.BlockMetadata memory meta)
- // internal
- // pure
- // returns (bytes32 hash)
- // {
- // uint256[7] memory inputs;
- // inputs[0] = uint256(meta.l1Hash);
- // inputs[1] = uint256(meta.difficulty);
- // inputs[2] = uint256(meta.txListHash);
- // inputs[3] = uint256(meta.extraData);
- // inputs[4] = (uint256(meta.id)) | (uint256(meta.timestamp) << 64)
- // | (uint256(meta.l1Height) << 128) | (uint256(meta.gasLimit) << 192);
- // inputs[5] = uint256(uint160(meta.coinbase));
- // inputs[6] = uint256(keccak256(abi.encode(meta.depositsProcessed)));
-
- // assembly {
- // hash := keccak256(inputs, 224 /*mul(7, 32)*/ )
- // }
- // }
-
- pub fn hash(&self) -> B256 {
- let field0 = self.l1Hash;
- let field1 = self.difficulty;
- let field2 = self.txListHash;
- let field3 = self.extraData;
- let field4: U256 = U256::from(self.id)
- | U256::from(self.timestamp) << 64
- | U256::from(self.l1Height) << 128
- | U256::from(self.gasLimit) << 192;
- let coinbase: U160 = self.coinbase.into();
- let field5 = U256::from(coinbase);
- let field6 = keccak(self.depositsProcessed.abi_encode());
- let input: Vec = iter::empty()
- .chain(field0)
- .chain(field1)
- .chain(field2)
- .chain(field3)
- .chain(field4.to_be_bytes_vec())
- .chain(field5.to_be_bytes_vec())
- .chain(field6)
- .collect();
- keccak(input).into()
+ #[derive(Debug, Default, Deserialize, Serialize)]
+ struct Transition {
+ bytes32 parentHash;
+ bytes32 blockHash;
+ bytes32 signalRoot;
+ bytes32 graffiti;
}
-}
-sol! {
#[derive(Debug, Default, Deserialize, Serialize)]
- struct BlockEvidence {
- BlockMetadata blockMetadata;
- bytes32 parentHash; // constrain: l2 parent hash
- bytes32 blockHash; // constrain: l2 block hash
- bytes32 signalRoot; // constrain: ??l2 service account storage root??
- bytes32 graffiti; // constrain: l2 block's graffiti
+ struct PseZkVerifierCalcInstance {
+ bytes32 parentHash;
+ bytes32 blockHash;
+ bytes32 signalRoot;
+ bytes32 graffiti;
+ bytes32 metaHash;
+ address prover;
+ bytes32 txListHash;
+ uint256 pointValue;
}
+
}
+#[derive(Debug)]
pub enum EvidenceType {
Sgx {
- prover: Address,
new_pubkey: Address, // the evidence signature public key
},
- PseZk {
- prover: Address,
- },
+ PseZk,
}
-impl BlockEvidence {
- // keccak256(
- // abi.encode(
- // evidence.metaHash,
- // evidence.parentHash,
- // evidence.blockHash,
- // evidence.signalRoot,
- // evidence.graffiti,
- // assignedProver,
- // newPubKey
- // )
- // );
- pub fn abi_encode(&self, evidence_type: EvidenceType) -> Vec {
- use DynSolValue::*;
- let mut abi_encode_tuple = vec![
- FixedBytes(self.blockMetadata.hash(), 32),
- FixedBytes(self.parentHash, 32),
- FixedBytes(self.blockHash, 32),
- FixedBytes(self.signalRoot, 32),
- FixedBytes(self.graffiti, 32),
- ];
+#[derive(Debug, Clone, Default, Deserialize, Serialize)]
+pub struct ProtocolInstance {
+ pub transition: Transition,
+ pub block_metadata: BlockMetadata,
+ pub prover: Address,
+}
+
+impl ProtocolInstance {
+ /// PseZkVerifier.sol
+ // function calcInstance(
+ // TaikoData.Transition memory tran,
+ // address prover,
+ // bytes32 metaHash,
+ // bytes32 txListHash,
+ // uint256 pointValue
+ // )
+ // return keccak256(abi.encode(tran, prover, metaHash, txListHash, pointValue));
+ pub fn hash(&self, evidence_type: EvidenceType) -> B256 {
match evidence_type {
- EvidenceType::Sgx { prover, new_pubkey } => {
- abi_encode_tuple.extend(vec![
- Address(prover.to_fixed_bytes().into()),
- Address(new_pubkey.to_fixed_bytes().into()),
- ]);
- }
- EvidenceType::PseZk { prover } => {
- abi_encode_tuple.push(Address(prover.to_fixed_bytes().into()));
+ EvidenceType::Sgx { new_pubkey: _ } => todo!(),
+ EvidenceType::PseZk => {
+ // keccak256(abi.encode(tran, prover, metaHash, txListHash, pointValue));
+ keccak(self.abi_encode()).into()
}
- };
- // println!("BlockEvidence abi_encode_tuple: {:?}", abi_encode_tuple);
- Tuple(abi_encode_tuple).abi_encode()
+ }
}
- pub fn hash(&self, evidence_type: EvidenceType) -> B256 {
- keccak(self.abi_encode(evidence_type)).into()
+ pub fn abi_encode(&self) -> Vec {
+ let meta_hash = keccak(self.block_metadata.abi_encode());
+ PseZkVerifierCalcInstance {
+ parentHash: self.transition.parentHash,
+ blockHash: self.transition.blockHash,
+ signalRoot: self.transition.signalRoot,
+ graffiti: self.transition.graffiti,
+ metaHash: meta_hash.into(),
+ prover: self.prover.as_fixed_bytes().into(),
+ txListHash: self.block_metadata.blobHash,
+ pointValue: U256::from(0),
+ }
+ .abi_encode()
}
-}
-#[derive(Debug, Clone, Default, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct ProtocolInstance {
- pub block_evidence: BlockEvidence,
- pub prover: Address,
-}
+ pub fn parentHash(&self) -> Vec {
+ self.transition.parentHash.abi_encode()
+ }
-pub const ANCHOR_METHOD_SIGNATURE: u32 = 0xda69d3db;
+ pub fn blockHash(&self) -> Vec {
+ self.transition.blockHash.abi_encode()
+ }
-impl ProtocolInstance {
- /// gen anchor call
- // anchor(l1_hash,signal_root,l1_height,parent_gas_used)
- pub fn anchor_call(&self, parent_gas_used: u32) -> Bytes {
- let mut result = Vec::new();
- result.extend_from_slice(&ANCHOR_METHOD_SIGNATURE.to_be_bytes());
- result.extend_from_slice(self.block_evidence.blockMetadata.l1Hash.as_slice());
- result.extend_from_slice(self.block_evidence.signalRoot.as_slice());
- result.extend_from_slice(self.block_evidence.blockMetadata.l1Hash.as_slice());
- result.extend_from_slice(&(parent_gas_used as u64).to_word().to_be_bytes());
- result.into()
+ pub fn signalRoot(&self) -> Vec {
+ self.transition.signalRoot.abi_encode()
}
+
+ pub fn graffiti(&self) -> Vec {
+ self.transition.graffiti.abi_encode()
+ }
+
+ pub fn prover(&self) -> Vec {
+ self.prover.as_fixed_bytes().abi_encode()
+ }
+
+ pub fn meta_hash(&self) -> Vec {
+ keccak(self.block_metadata.abi_encode()).into()
+ }
+
+ pub fn tx_list_hash(&self) -> Vec {
+ self.block_metadata.blobHash.abi_encode()
+ }
+
+ pub fn point_value(&self) -> Vec {
+ U256::from(0).abi_encode()
+ }
+}
+
+#[inline]
+pub fn keccak(data: impl AsRef<[u8]>) -> [u8; 32] {
+ // TODO: Remove this benchmarking code once performance testing is complete.
+ // std::hint::black_box(sha2::Sha256::digest(&data));
+ Keccak256::digest(data).into()
}
diff --git a/integration-tests/src/integration_public_data_circuits.rs b/integration-tests/src/integration_public_data_circuits.rs
index 7d07b3977d..dd339b1945 100644
--- a/integration-tests/src/integration_public_data_circuits.rs
+++ b/integration-tests/src/integration_public_data_circuits.rs
@@ -7,7 +7,7 @@ mod public_data_test {
use crate::get_client;
use bus_mapping::{
circuit_input_builder::{
- protocol_instance::{BlockEvidence, BlockMetadata},
+ protocol_instance::{BlockMetadata, Transition},
BuilderClient, CircuitsParams, ProtocolInstance,
},
rpc::BlockNumber,
@@ -336,13 +336,13 @@ mod public_data_test {
}
fn gen_requests() -> Vec {
- let metadata = BlockMetadata {
- l1Hash: parse_hash("8374d2fde2f3e5640f0ce4f6bb557e988336c2dae71e55cb3734c5c6be450820")
+ let block_metadata = BlockMetadata {
+ l1Hash: parse_hash("6e3b781b2d9a04e21ecba49e67dc3fb0a8242408cc07fa6fed5d8bd0eca2c985")
.unwrap()
.as_fixed_bytes()
.into(),
- txListHash: parse_hash(
- "b3de7eaf38c3c84a34d7d80100c1b133bd7734f03b5c8e86cb806d684b718d85",
+ blobHash: parse_hash(
+ "569e75fc77c1a856f6daaf9e69d8a9566ca34aa47f9133711ce065a571af0cfd",
)
.unwrap()
.as_fixed_bytes()
@@ -357,8 +357,7 @@ mod public_data_test {
..Default::default()
};
- let block_evidence = BlockEvidence {
- blockMetadata: metadata,
+ let transition = Transition {
parentHash: parse_hash(
"beb327617555bd45c05ac7e33d2c509c77192eb8c372873483696b1a7367750a",
)
@@ -381,7 +380,8 @@ mod public_data_test {
};
let protocol_instance = ProtocolInstance {
- block_evidence,
+ transition,
+ block_metadata,
..Default::default()
};
vec![protocol_instance]
@@ -391,7 +391,7 @@ mod public_data_test {
circuits_params: CircuitsParams,
protocol_instance: ProtocolInstance,
) -> Block {
- let block_num = protocol_instance.block_evidence.blockMetadata.id;
+ let block_num = protocol_instance.block_metadata.id;
let cli = get_client();
let cli = BuilderClient::new(cli, circuits_params, Some(protocol_instance.clone()))
diff --git a/zkevm-circuits/src/table/keccak_table.rs b/zkevm-circuits/src/table/keccak_table.rs
index 5eaff3f30d..ab64a9c3a7 100644
--- a/zkevm-circuits/src/table/keccak_table.rs
+++ b/zkevm-circuits/src/table/keccak_table.rs
@@ -62,7 +62,6 @@ impl KeccakTable {
challenge,
)
});
-
vec![[
Value::known(F::ONE),
input_rlc,
diff --git a/zkevm-circuits/src/taiko_pi_circuit.rs b/zkevm-circuits/src/taiko_pi_circuit.rs
index 3dd1c9ab44..4b24c16c70 100644
--- a/zkevm-circuits/src/taiko_pi_circuit.rs
+++ b/zkevm-circuits/src/taiko_pi_circuit.rs
@@ -4,12 +4,12 @@ mod dev;
mod param;
#[cfg(any(test))]
mod test;
-use bus_mapping::circuit_input_builder::{protocol_instance::EvidenceType, ProtocolInstance};
+use bus_mapping::circuit_input_builder::ProtocolInstance;
use param::*;
// use bus_mapping::circuit_input_builder::ProtocolInstance;
-use eth_types::{Field, ToBigEndian, ToWord, U256};
+use eth_types::{Field, U256};
use ethers_core::utils::keccak256;
use halo2_proofs::circuit::{AssignedCell, Layouter, SimpleFloorPlanner, Value};
@@ -30,7 +30,7 @@ use crate::{
util::{Challenges, SubCircuit, SubCircuitConfig},
witness::{self, BlockContext},
};
-use alloy_dyn_abi::DynSolValue::FixedBytes;
+
use core::result::Result;
use halo2_proofs::plonk::Error;
@@ -127,8 +127,8 @@ impl Default for PiCellType {
/// Public Inputs data known by the verifier
#[derive(Debug, Clone)]
pub struct PublicData {
- protocol_instance: ProtocolInstance,
- block_context: BlockContext,
+ pub(crate) protocol_instance: ProtocolInstance,
+ pub(crate) block_context: BlockContext,
_phantom: PhantomData,
}
@@ -154,41 +154,24 @@ impl PublicData {
}
}
- /// Returns the keccak hash of the public inputs
- pub fn encode_raw(&self) -> Vec {
- self.protocol_instance
- .block_evidence
- .abi_encode(
- // TODO(Cecilia): who's the prover?
- EvidenceType::PseZk {
- prover: self.protocol_instance.prover,
- },
- )
- .to_vec()
- }
-
fn encode_field(&self, idx: usize) -> Vec {
- let fields = vec![
- FixedBytes(
- self.protocol_instance.block_evidence.blockMetadata.hash(),
- 32,
- ),
- FixedBytes(self.protocol_instance.block_evidence.parentHash, 32),
- FixedBytes(self.protocol_instance.block_evidence.blockHash, 32),
- FixedBytes(self.protocol_instance.block_evidence.signalRoot, 32),
- FixedBytes(self.protocol_instance.block_evidence.graffiti, 32),
- FixedBytes(
- self.protocol_instance.prover.to_word().to_be_bytes().into(),
- 32,
- ),
- ];
- fields[idx].abi_encode()
+ match idx {
+ 0 => self.protocol_instance.parentHash(),
+ 1 => self.protocol_instance.blockHash(),
+ 2 => self.protocol_instance.signalRoot(),
+ 3 => self.protocol_instance.graffiti(),
+ 4 => self.protocol_instance.meta_hash(),
+ 5 => self.protocol_instance.prover(),
+ 6 => self.protocol_instance.tx_list_hash(),
+ 7 => self.protocol_instance.point_value(),
+ _ => unreachable!(),
+ }
}
fn total_acc(&self, r: Value) -> F {
let mut rand = F::ZERO;
r.map(|r| rand = r);
- rlc::value(self.encode_raw().iter().rev(), rand)
+ rlc::value(self.protocol_instance.abi_encode().iter().rev(), rand)
}
fn assignment(&self, idx: usize) -> Vec {
@@ -205,7 +188,7 @@ impl PublicData {
}
fn keccak_hi_low(&self) -> [F; 2] {
- let keccaked_pi = keccak256(self.encode_raw());
+ let keccaked_pi = keccak256(self.protocol_instance.abi_encode());
[
rlc::value(keccaked_pi[0..16].iter().rev(), BYTE_POW_BASE.scalar()),
rlc::value(keccaked_pi[16..].iter().rev(), BYTE_POW_BASE.scalar()),
@@ -213,7 +196,7 @@ impl PublicData {
}
fn keccak(&self) -> Vec {
- keccak256(self.encode_raw()).to_vec()
+ keccak256(self.protocol_instance.abi_encode()).to_vec()
}
fn keccak_assignment(&self) -> Vec {
@@ -221,7 +204,7 @@ impl PublicData {
}
fn total_len(&self) -> usize {
- self.encode_raw().len()
+ self.protocol_instance.abi_encode().len()
}
fn field_len(&self, idx: usize) -> usize {
@@ -236,26 +219,28 @@ pub struct TaikoPiCircuitConfig {
keccak_instance: Column, // equality
columns: Vec>,
- meta_data: FieldGadget,
parent_hash: (Cell, FieldGadget, Cell),
block_hash: (Cell, FieldGadget, Cell),
signal_root: FieldGadget,
graffiti: FieldGadget,
+ meta_hash: FieldGadget,
prover: FieldGadget,
+ tx_list_hash: FieldGadget,
+ point_value: FieldGadget,
- total_acc: Cell,
keccak_bytes: FieldGadget,
keccak_hi_lo: [Cell; 2],
+ total_acc: Cell,
block_table: BlockTable,
keccak_table: KeccakTable,
byte_table: ByteTable,
}
/// PiCircuitConfigArgs
-pub struct TaikoPiCircuitConfigArgs {
+pub struct TaikoPiConfigArgs {
///
- pub evidence: PublicData,
+ pub public_data: PublicData,
/// BlockTable
pub block_table: BlockTable,
/// KeccakTable
@@ -267,18 +252,19 @@ pub struct TaikoPiCircuitConfigArgs {
}
impl SubCircuitConfig for TaikoPiCircuitConfig {
- type ConfigArgs = TaikoPiCircuitConfigArgs;
+ type ConfigArgs = TaikoPiConfigArgs;
/// Return a new TaikoPiCircuitConfig
fn new(
meta: &mut ConstraintSystem,
Self::ConfigArgs {
- evidence,
+ public_data,
block_table,
keccak_table,
byte_table,
challenges,
}: Self::ConfigArgs,
) -> Self {
+ let pi = &public_data.protocol_instance;
let keccak_r = challenges.keccak_input();
let evm_word = challenges.evm_word();
let mut cm = CellManager::new(CM_HEIGHT, 0);
@@ -297,20 +283,22 @@ impl SubCircuitConfig for TaikoPiCircuitConfig {
let keccak_instance = meta.instance_column();
meta.enable_equality(keccak_instance);
- let meta_data = FieldGadget::config(&mut cb, evidence.field_len(META_DATA));
let parent_hash = (
cb.query_one(S1),
- FieldGadget::config(&mut cb, evidence.field_len(PARENT_HASH)),
+ FieldGadget::config(&mut cb, pi.parentHash().len()),
cb.query_one(S2),
);
let block_hash = (
cb.query_one(S1),
- FieldGadget::config(&mut cb, evidence.field_len(BLOCK_HASH)),
+ FieldGadget::config(&mut cb, pi.blockHash().len()),
cb.query_one(S2),
);
- let signal_root = FieldGadget::config(&mut cb, evidence.field_len(SIGNAL_ROOT));
- let graffiti = FieldGadget::config(&mut cb, evidence.field_len(GRAFFITI));
- let prover = FieldGadget::config(&mut cb, evidence.field_len(PROVER));
+ let signal_root = FieldGadget::config(&mut cb, pi.signalRoot().len());
+ let graffiti = FieldGadget::config(&mut cb, pi.graffiti().len());
+ let meta_hash = FieldGadget::config(&mut cb, pi.meta_hash().len());
+ let prover = FieldGadget::config(&mut cb, pi.prover().len());
+ let tx_list_hash = FieldGadget::config(&mut cb, pi.tx_list_hash().len());
+ let point_value = FieldGadget::config(&mut cb, pi.point_value().len());
let total_acc = cb.query_one(S2);
let keccak_bytes = FieldGadget::config(&mut cb, DEFAULT_LEN);
@@ -329,12 +317,14 @@ impl SubCircuitConfig for TaikoPiCircuitConfig {
);
}
let acc_val = [
- meta_data.clone(),
parent_hash.1.clone(),
block_hash.1.clone(),
signal_root.clone(),
graffiti.clone(),
+ meta_hash.clone(),
prover.clone(),
+ tx_list_hash.clone(),
+ point_value.clone(),
]
.iter()
.fold(0.expr(), |acc, gadget| {
@@ -346,7 +336,7 @@ impl SubCircuitConfig for TaikoPiCircuitConfig {
(
1.expr(),
total_acc.expr(),
- evidence.total_len().expr(),
+ public_data.total_len().expr(),
keccak_bytes.rlc_acc(evm_word.expr())
)
=> @cb.table(Table::Keccak)
@@ -369,12 +359,16 @@ impl SubCircuitConfig for TaikoPiCircuitConfig {
q_enable,
keccak_instance,
columns,
- meta_data,
+
parent_hash,
block_hash,
signal_root,
graffiti,
+ meta_hash,
prover,
+ tx_list_hash,
+ point_value,
+
total_acc,
keccak_bytes,
keccak_hi_lo,
@@ -390,7 +384,7 @@ impl TaikoPiCircuitConfig {
&self,
layouter: &mut impl Layouter,
challenge: &Challenges>,
- evidence: &PublicData,
+ public_data: &PublicData,
) -> Result<(), Error> {
let evm_word = challenge.evm_word();
let keccak_r = challenge.keccak_input();
@@ -401,28 +395,31 @@ impl TaikoPiCircuitConfig {
let mut region = CachedRegion::new(&mut region);
region.annotate_columns(&self.columns);
- assign!(region, self.parent_hash.0, 0 => (evidence.block_context.number - 1).as_u64().scalar())?;
- assign!(region, self.parent_hash.2, 0 => evidence.assignment_acc(PARENT_HASH, evm_word))?;
- assign!(region, self.block_hash.0, 0 => (evidence.block_context.number).as_u64().scalar())?;
- assign!(region, self.block_hash.2, 0 => evidence.assignment_acc(BLOCK_HASH, evm_word))?;
+ assign!(region, self.parent_hash.0, 0 => (public_data.block_context.number - 1).as_u64().scalar())?;
+ assign!(region, self.parent_hash.2, 0 => public_data.assignment_acc(PARENT_HASH, evm_word))?;
+ assign!(region, self.block_hash.0, 0 => (public_data.block_context.number).as_u64().scalar())?;
+ assign!(region, self.block_hash.2, 0 => public_data.assignment_acc(BLOCK_HASH, evm_word))?;
let mut idx = 0;
[
- &self.meta_data,
&self.parent_hash.1,
&self.block_hash.1,
&self.signal_root,
&self.graffiti,
+ &self.meta_hash,
&self.prover,
+ &self.tx_list_hash,
+ &self.point_value,
].iter().for_each(|gadget| {
- gadget.assign(&mut region, 0, &evidence.assignment(idx))
+ gadget.assign(&mut region, 0, &public_data.assignment(idx))
.expect(&format!("FieldGadget assignment failed at {:?}", idx));
idx += 1;
});
- self.keccak_bytes.assign(&mut region, 0, &evidence.keccak_assignment())
- .expect("Keccak bytes assignment failed");
- assign!(region, self.total_acc, 0 => evidence.total_acc(keccak_r))?;
- let hi_low_assignment = evidence.keccak_hi_low();
+
+ self.keccak_bytes.assign(&mut region, 0, &public_data.keccak_assignment())
+ .expect("Keccak bytes assignment failed");
+ assign!(region, self.total_acc, 0 => public_data.total_acc(keccak_r))?;
+ let hi_low_assignment = public_data.keccak_hi_low();
let hi = assign!(region, self.keccak_hi_lo[0], 0 => hi_low_assignment[0])?;
let lo = assign!(region, self.keccak_hi_lo[1], 0 => hi_low_assignment[1])?;
@@ -438,13 +435,13 @@ impl TaikoPiCircuitConfig {
#[derive(Clone, Debug, Default)]
pub struct TaikoPiCircuit {
/// PublicInputs data known by the verifier
- pub evidence: PublicData,
+ pub public_data: PublicData,
}
impl TaikoPiCircuit {
/// Creates a new TaikoPiCircuit
- pub fn new(evidence: PublicData) -> Self {
- Self { evidence }
+ pub fn new(public_data: PublicData) -> Self {
+ Self { public_data }
}
}
@@ -467,7 +464,7 @@ impl SubCircuit for TaikoPiCircuit {
/// Compute the public inputs for this circuit.
fn instance(&self) -> Vec> {
- vec![self.evidence.keccak_hi_low().to_vec()]
+ vec![self.public_data.keccak_hi_low().to_vec()]
}
/// Make the assignments to the PiCircuit
@@ -477,6 +474,6 @@ impl SubCircuit for TaikoPiCircuit {
challenges: &Challenges>,
layouter: &mut impl Layouter,
) -> Result<(), Error> {
- config.assign(layouter, challenges, &self.evidence)
+ config.assign(layouter, challenges, &self.public_data)
}
}
diff --git a/zkevm-circuits/src/taiko_pi_circuit/dev.rs b/zkevm-circuits/src/taiko_pi_circuit/dev.rs
index 66533ae08a..d483f1ec2b 100644
--- a/zkevm-circuits/src/taiko_pi_circuit/dev.rs
+++ b/zkevm-circuits/src/taiko_pi_circuit/dev.rs
@@ -11,7 +11,7 @@ impl Circuit for TaikoPiCircuit {
}
fn params(&self) -> Self::Params {
- self.evidence.clone()
+ self.public_data.clone()
}
fn configure(meta: &mut ConstraintSystem) -> Self::Config {
@@ -27,8 +27,8 @@ impl Circuit for TaikoPiCircuit {
(
TaikoPiCircuitConfig::new(
meta,
- TaikoPiCircuitConfigArgs {
- evidence: params,
+ TaikoPiConfigArgs {
+ public_data: params,
block_table,
keccak_table,
byte_table,
@@ -52,9 +52,11 @@ impl Circuit for TaikoPiCircuit {
.block_table
.load(&mut layouter, &evidance.block_context, randomness)?;
// assign keccak table
- config
- .keccak_table
- .dev_load(&mut layouter, vec![&evidance.encode_raw()], &challenges)?;
+ config.keccak_table.dev_load(
+ &mut layouter,
+ vec![&evidance.protocol_instance.abi_encode()],
+ &challenges,
+ )?;
config.byte_table.load(&mut layouter)?;
self.synthesize_sub(&config, &challenges, &mut layouter)
diff --git a/zkevm-circuits/src/taiko_pi_circuit/param.rs b/zkevm-circuits/src/taiko_pi_circuit/param.rs
index 2e97377ec5..dd7027be97 100644
--- a/zkevm-circuits/src/taiko_pi_circuit/param.rs
+++ b/zkevm-circuits/src/taiko_pi_circuit/param.rs
@@ -2,10 +2,14 @@
pub const BYTE_POW_BASE: u64 = 1 << 8;
pub const DEFAULT_LEN: usize = 32;
-pub const META_DATA: usize = 0;
-pub const PARENT_HASH: usize = 1;
-pub const BLOCK_HASH: usize = 2;
-pub const SIGNAL_ROOT: usize = 3;
-pub const GRAFFITI: usize = 4;
+
+pub const PARENT_HASH: usize = 0;
+pub const BLOCK_HASH: usize = 1;
+pub const SIGNAL_ROOT: usize = 2;
+pub const GRAFFITI: usize = 3;
+pub const META_HASH: usize = 4;
pub const PROVER: usize = 5;
-pub const CM_HEIGHT: usize = 15;
+pub const TX_LIST_HASH: usize = 6;
+pub const POINT_VALUE: usize = 7;
+
+pub const CM_HEIGHT: usize = 20;
diff --git a/zkevm-circuits/src/taiko_pi_circuit/test.rs b/zkevm-circuits/src/taiko_pi_circuit/test.rs
index d275091f72..24cc52895c 100644
--- a/zkevm-circuits/src/taiko_pi_circuit/test.rs
+++ b/zkevm-circuits/src/taiko_pi_circuit/test.rs
@@ -3,9 +3,11 @@ use super::{dev::*, param::*, *};
use std::vec;
use alloy_primitives::FixedBytes;
-use bus_mapping::circuit_input_builder::protocol_instance::{self, BlockEvidence};
+use bus_mapping::circuit_input_builder::{
+ protocol_instance::Transition, BlockMetadata, Transaction,
+};
use core::result::Result;
-use eth_types::{H160, H256};
+use eth_types::{ToWord, H160, H256};
use halo2_proofs::{
dev::{MockProver, VerifyFailure},
halo2curves::bn256::Fr,
@@ -13,7 +15,6 @@ use halo2_proofs::{
};
use lazy_static::lazy_static;
use snark_verifier_sdk::halo2::gen_srs;
-
lazy_static! {
static ref LAST_HASH: H256 = H256::from_slice(
&hex::decode("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").unwrap(),
@@ -41,11 +42,12 @@ fn run(
fn mock_public_data() -> PublicData {
let protocol_instance = ProtocolInstance {
- block_evidence: BlockEvidence {
+ transition: Transition {
parentHash: LAST_HASH.as_fixed_bytes().into(),
blockHash: THIS_HASH.as_fixed_bytes().into(),
..Default::default()
},
+ block_metadata: BlockMetadata::default(),
prover: *PROVER_ADDR,
};
let block_context = BlockContext {
@@ -80,7 +82,7 @@ fn mock(
..Default::default()
};
let protocol_instance = ProtocolInstance {
- block_evidence: BlockEvidence {
+ transition: Transition {
parentHash: last_hash.as_fixed_bytes().into(),
blockHash: this_hash.as_fixed_bytes().into(),
..Default::default()
diff --git a/zkevm-circuits/src/taiko_super_circuit.rs b/zkevm-circuits/src/taiko_super_circuit.rs
index d1166ba48e..dccb88b4cc 100644
--- a/zkevm-circuits/src/taiko_super_circuit.rs
+++ b/zkevm-circuits/src/taiko_super_circuit.rs
@@ -26,10 +26,13 @@ use crate::table::{ByteTable, BytecodeTable, CopyTable, ExpTable};
use crate::{table::MptTable, witness::MptUpdates};
use crate::{
- table::{BlockTable, ByteTable, KeccakTable},
- taiko_pi_circuit::{
- PublicData, TaikoPiCircuit, TaikoPiCircuitConfig, TaikoPiCircuitConfigArgs,
+ anchor_tx_circuit::{AnchorTxCircuit, AnchorTxCircuitConfig, AnchorTxCircuitConfigArgs},
+ evm_circuit::{EvmCircuit, EvmCircuitConfig, EvmCircuitConfigArgs},
+ table::{
+ BlockTable, ByteTable, BytecodeTable, CopyTable, ExpTable, KeccakTable, PiTable, RwTable,
+ TxTable,
},
+ taiko_pi_circuit::{PublicData, TaikoPiCircuit, TaikoPiCircuitConfig, TaikoPiConfigArgs},
util::{log2_ceil, Challenges, SubCircuit, SubCircuitConfig},
witness::{block_convert, Block},
};
@@ -119,8 +122,8 @@ impl SubCircuitConfig for SuperCircuitConfig {
let pi_circuit = TaikoPiCircuitConfig::new(
meta,
- TaikoPiCircuitConfigArgs {
- evidence: PublicData::default(),
+ TaikoPiConfigArgs {
+ public_data: PublicData::default(),
block_table: block_table.clone(),
keccak_table: keccak_table.clone(),
byte_table: byte_table.clone(),
@@ -449,7 +452,9 @@ impl Circuit for SuperCircuit {
self.block
.sha3_inputs
.iter()
- .chain(std::iter::once(&self.pi_circuit.evidence.encode_raw()))
+ .chain(std::iter::once(
+ &self.pi_circuit.public_data.protocol_instance.abi_encode(),
+ ))
.chain(
&self
.block
@@ -518,9 +523,9 @@ impl SuperCircuit {
let block_data =
BlockData::new_from_geth_data_with_params(geth_data.clone(), circuits_params);
let mut builder = block_data.new_circuit_input_builder();
- protocol_instance.block_evidence.blockHash =
+ protocol_instance.transition.blockHash =
geth_data.eth_block.hash.unwrap().as_fixed_bytes().into();
- protocol_instance.block_evidence.parentHash =
+ protocol_instance.transition.parentHash =
geth_data.eth_block.parent_hash.as_fixed_bytes().into();
builder.block.protocol_instance = Some(protocol_instance);
builder
diff --git a/zkevm-circuits/src/witness/block.rs b/zkevm-circuits/src/witness/block.rs
index 0d766a5638..af6c24d3de 100644
--- a/zkevm-circuits/src/witness/block.rs
+++ b/zkevm-circuits/src/witness/block.rs
@@ -75,25 +75,21 @@ pub fn protocol_instancetable_assignments(
[
Value::known(F::from(PiFieldTag::L1Hash as u64)),
rlc_be_bytes(
- protocol_instance
- .block_evidence
- .blockMetadata
- .l1Hash
- .as_slice(),
+ protocol_instance.block_metadata.l1Hash.as_slice(),
randomness,
),
],
[
Value::known(F::from(PiFieldTag::L1SignalRoot as u64)),
rlc_be_bytes(
- protocol_instance.block_evidence.signalRoot.as_slice(),
+ protocol_instance.transition.signalRoot.as_slice(),
randomness,
),
],
[
Value::known(F::from(PiFieldTag::L1Height as u64)),
rlc_be_bytes(
- &Word::from(protocol_instance.block_evidence.blockMetadata.l1Height).to_be_bytes(),
+ &Word::from(protocol_instance.block_metadata.l1Hash.0).to_be_bytes(),
randomness,
),
],