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

Add a SP1 proving server. #187

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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.
Loading
Loading