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

Commit

Permalink
feat: tx_leaf gadget created (copied from storage_leaf)
Browse files Browse the repository at this point in the history
  • Loading branch information
KimiWu123 committed Apr 29, 2024
1 parent 916f369 commit 8051045
Show file tree
Hide file tree
Showing 5 changed files with 530 additions and 7 deletions.
1 change: 1 addition & 0 deletions zkevm-circuits/src/mpt_circuit/account_leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ impl<F: Field> AccountLeafConfig<F> {
main_data.proof_type,
true,
address_item.word().compress_f(),
F::ZERO,
main_data.new_root,
main_data.old_root,
)?;
Expand Down
20 changes: 14 additions & 6 deletions zkevm-circuits/src/mpt_circuit/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ pub(crate) struct MainData<F> {
pub(crate) proof_type: Cell<F>,
pub(crate) is_below_account: Cell<F>,
pub(crate) address: Cell<F>,
pub(crate) transaction_index: Cell<F>,
pub(crate) new_root: WordLoHiCell<F>,
pub(crate) old_root: WordLoHiCell<F>,
}
Expand All @@ -695,6 +696,7 @@ pub(crate) struct MainDataWitness<F> {
pub(crate) proof_type: usize,
pub(crate) is_below_account: bool,
pub(crate) address: F,
pub(crate) transaction_index: F,
pub(crate) new_root: WordLoHi<F>,
pub(crate) old_root: WordLoHi<F>,
}
Expand All @@ -709,6 +711,7 @@ impl<F: Field> MainData<F> {
proof_type: cb.query_cell(),
is_below_account: cb.query_cell(),
address: cb.query_cell(),
transaction_index: cb.query_cell(),
new_root: cb.query_word_unchecked(),
old_root: cb.query_word_unchecked(),
};
Expand All @@ -720,6 +723,7 @@ impl<F: Field> MainData<F> {
main_data.proof_type.expr(),
main_data.is_below_account.expr(),
main_data.address.expr(),
main_data.transaction_index.expr(),
main_data.new_root.lo().expr(),
main_data.new_root.hi().expr(),
main_data.old_root.lo().expr(),
Expand All @@ -746,13 +750,15 @@ impl<F: Field> MainData<F> {
proof_type: usize,
is_below_account: bool,
address: F,
transaction_index: F,
new_root: WordLoHi<F>,
old_root: WordLoHi<F>,
) -> Result<(), Error> {
let values = [
proof_type.scalar(),
is_below_account.scalar(),
address,
transaction_index,
new_root.lo(),
new_root.hi(),
old_root.lo(),
Expand All @@ -775,17 +781,19 @@ impl<F: Field> MainData<F> {
self.proof_type.assign(region, offset, values[0])?;
self.is_below_account.assign(region, offset, values[1])?;
self.address.assign(region, offset, values[2])?;
self.new_root.lo().assign(region, offset, values[3])?;
self.new_root.hi().assign(region, offset, values[4])?;
self.old_root.lo().assign(region, offset, values[5])?;
self.old_root.hi().assign(region, offset, values[6])?;
self.transaction_index.assign(region, offset, values[3])?;
self.new_root.lo().assign(region, offset, values[4])?;
self.new_root.hi().assign(region, offset, values[5])?;
self.old_root.lo().assign(region, offset, values[6])?;
self.old_root.hi().assign(region, offset, values[7])?;

Ok(MainDataWitness {
proof_type: values[0].get_lower_32() as usize,
is_below_account: values[1] == 1.scalar(),
address: values[2],
new_root: WordLoHi::new([values[3], values[4]]),
old_root: WordLoHi::new([values[5], values[6]]),
transaction_index: values[3],
new_root: WordLoHi::new([values[4], values[5]]),
old_root: WordLoHi::new([values[6], values[7]]),
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/mpt_circuit/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ impl<F: Field> StartConfig<F> {
&mut memory[main_memory()],
start.proof_type as usize,
false,
0.scalar(),
F::ZERO,
F::ZERO,
root[true.idx()],
root[false.idx()],
)?;
Expand Down
1 change: 1 addition & 0 deletions zkevm-circuits/src/mpt_circuit/storage_leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ impl<F: Field> StorageLeafConfig<F> {
MPTProofType::Disabled as usize,
false,
F::ZERO,
F::ZERO,
WordLoHi::new([F::ZERO, F::ZERO]),
WordLoHi::new([F::ZERO, F::ZERO]),
)?;
Expand Down
Loading

0 comments on commit 8051045

Please sign in to comment.