Skip to content

Commit

Permalink
Update kairos-trie
Browse files Browse the repository at this point in the history
  • Loading branch information
Avi-D-coder committed Sep 24, 2024
1 parent 590d72a commit 6305c25
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion 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 kairos-contracts/Cargo.lock

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

4 changes: 2 additions & 2 deletions kairos-prover/Cargo.lock

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

30 changes: 11 additions & 19 deletions kairos-prover/kairos-circuit-logic/src/account_trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ use sha2::{digest::FixedOutputReset, Digest, Sha256};
use crate::transactions::{KairosTransaction, L1Deposit, PublicKey, Signed, Transfer, Withdraw};
use kairos_trie::{
stored::{
merkle::{Snapshot, SnapshotBuilder},
merkle::{Snapshot, SnapshotBuilder, VerifiedSnapshot},
DatabaseGet, Store,
},
KeyHash, NodeHash, PortableHash, PortableUpdate, TrieRoot,
};

/// The state of the batch transaction against the trie.
pub struct AccountTrie<S: Store<Account>> {
pub struct AccountTrie<S: Store<Value = Account>> {
pub txn: AccountTrieTxn<S>,
}
pub type AccountTrieTxn<S> = kairos_trie::Transaction<S, Account>;
pub type AccountTrieTxn<S> = kairos_trie::Transaction<S>;

/// TODO panic on error should be behind a feature flag
type TxnErr = String;

impl<'s> TryFrom<&'s Snapshot<Account>> for AccountTrie<&'s Snapshot<Account>> {
type Error = TxnErr;

fn try_from(snapshot: &'s Snapshot<Account>) -> Result<Self, Self::Error> {
Ok(Self {
txn: kairos_trie::Transaction::from_snapshot(snapshot)?,
})
impl<S: Store<Value = Account> + AsRef<Snapshot<Account>>> From<VerifiedSnapshot<S>>
for AccountTrie<VerifiedSnapshot<S>>
{
fn from(snapshot: VerifiedSnapshot<S>) -> Self {
Self {
txn: kairos_trie::Transaction::from_verified_snapshot(snapshot),
}
}
}

Expand All @@ -41,14 +41,6 @@ impl<Db: 'static + DatabaseGet<Account>> TryFrom<SnapshotBuilder<Db, Account>>
}
}

impl<'s> AccountTrie<&'s Snapshot<Account>> {
pub fn new_try_from_snapshot(snapshot: &'s Snapshot<Account>) -> Result<Self, TxnErr> {
Ok(Self {
txn: kairos_trie::Transaction::from_snapshot(snapshot)?,
})
}
}

impl<Db: 'static + DatabaseGet<Account>> AccountTrie<SnapshotBuilder<Db, Account>> {
pub fn new_try_from_db(db: Db, root_hash: TrieRoot<NodeHash>) -> Self {
Self {
Expand All @@ -59,7 +51,7 @@ impl<Db: 'static + DatabaseGet<Account>> AccountTrie<SnapshotBuilder<Db, Account
}
}

impl<S: Store<Account>> AccountTrie<S> {
impl<S: Store<Value = Account>> AccountTrie<S> {
#[allow(clippy::type_complexity)]
pub fn apply_batch(
&mut self,
Expand Down
5 changes: 3 additions & 2 deletions kairos-prover/kairos-circuit-logic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ impl ProofInputs {

let hasher = &mut DigestHasher::<Sha256>::default();

let mut trie = AccountTrie::new_try_from_snapshot(&trie_snapshot)?;
let pre_batch_trie_root = trie.txn.calc_root_hash(hasher)?.into();
let verified_snapshot = trie_snapshot.verify(hasher)?;
let pre_batch_trie_root = verified_snapshot.trie_root_hash().into();
let mut trie = AccountTrie::from(verified_snapshot);

let (deposits, withdrawals) = trie.apply_batch(
// TODO Replace with Box<[T]>: IntoIterator once Rust 2024 is stable
Expand Down
3 changes: 2 additions & 1 deletion kairos-prover/kairos-verifier-risc0-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#![no_std]

#[allow(clippy::too_long_first_doc_paragraph)]
/// The risc0 image_id of the batch update circuit program.
/// To update this you must rebuild the circuit with `cargo risczero build`, which will use docker
/// to reproducibly build the circuit.
/// Then you must copy the output ELF to `kairos-prover/methods/prove_batch_bin`
/// and run `cargo build` which will output the new hash.
pub const BATCH_CIRCUIT_PROGRAM_HASH: [u32; 8] = [
2249819926, 1807275128, 879420467, 753150136, 3885109892, 1252737579, 1362575552, 43533945,
162636669, 3420136214, 482235019, 1624934074, 1024623463, 972941903, 3671681564, 1824242109,
];

#[cfg(feature = "verifier")]
Expand Down
2 changes: 1 addition & 1 deletion kairos-prover/methods/prove-batch/Cargo.lock

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

Binary file modified kairos-prover/methods/prove_batch_bin
Binary file not shown.

0 comments on commit 6305c25

Please sign in to comment.