mirror of
https://github.com/logos-blockchain/logos-blockchain-pocs.git
synced 2026-01-06 23:23:08 +00:00
clippy/get everything building
This commit is contained in:
parent
aa57295f4b
commit
84cb37240b
@ -29,13 +29,12 @@ impl Bundle {
|
||||
.collect()
|
||||
}
|
||||
|
||||
///
|
||||
pub fn id(&self) -> BundleId {
|
||||
// TODO: change to merkle root
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(b"NOMOS_CL_BUNDLE_ID");
|
||||
for ptx in &self.partials {
|
||||
hasher.update(&ptx.root().0);
|
||||
hasher.update(ptx.root().0);
|
||||
}
|
||||
|
||||
BundleId(hasher.finalize().into())
|
||||
|
||||
@ -2,7 +2,7 @@ use crate::cl::merkle;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||
pub struct MMR {
|
||||
pub roots: Vec<Root>,
|
||||
}
|
||||
@ -20,7 +20,7 @@ pub struct MMRProof {
|
||||
|
||||
impl MMR {
|
||||
pub fn new() -> Self {
|
||||
Self { roots: vec![] }
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn push(&mut self, elem: &[u8]) -> MMRProof {
|
||||
|
||||
@ -39,6 +39,7 @@ impl LedgerWitness {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct LedgerState {
|
||||
commitments: MMR,
|
||||
nullifiers: BTreeSet<[u8; 32]>,
|
||||
@ -52,6 +53,10 @@ impl LedgerState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cm_mmr(&self) -> MMR {
|
||||
self.commitments.clone()
|
||||
}
|
||||
|
||||
pub fn nf_root(&self) -> [u8; 32] {
|
||||
sparse_merkle::sparse_root(&self.nullifiers)
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
use ledger_proof_statements::{
|
||||
ledger::{LedgerProofPrivate, LedgerProofPublic},
|
||||
ptx::PtxPublic,
|
||||
use ledger_proof_statements::ledger::{
|
||||
LedgerBundleWitness, LedgerProofPrivate, LedgerProofPublic, LedgerPtxWitness,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@ -9,7 +8,7 @@ use crate::{
|
||||
error::{Error, Result},
|
||||
partial_tx::ProvedPartialTx,
|
||||
};
|
||||
use cl::zone_layer::{ledger::LedgerWitness, notes::ZoneId};
|
||||
use cl::zone_layer::{ledger::LedgerState, notes::ZoneId};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ProvedLedgerTransition {
|
||||
@ -25,10 +24,6 @@ pub struct ProvedBundle {
|
||||
}
|
||||
|
||||
impl ProvedBundle {
|
||||
fn to_public(&self) -> Vec<PtxPublic> {
|
||||
self.ptxs.iter().map(|p| p.public.clone()).collect()
|
||||
}
|
||||
|
||||
fn proofs(&self) -> Vec<risc0_zkvm::Receipt> {
|
||||
let mut proofs = vec![self.balance.risc0_receipt.clone()];
|
||||
proofs.extend(self.ptxs.iter().map(|p| p.risc0_receipt.clone()));
|
||||
@ -38,17 +33,38 @@ impl ProvedBundle {
|
||||
|
||||
impl ProvedLedgerTransition {
|
||||
pub fn prove(
|
||||
ledger: LedgerWitness,
|
||||
mut ledger: LedgerState,
|
||||
zone_id: ZoneId,
|
||||
bundles: Vec<ProvedBundle>,
|
||||
constraints: Vec<ConstraintProof>,
|
||||
) -> Result<Self> {
|
||||
let witness = LedgerProofPrivate {
|
||||
bundles: bundles.iter().map(|p| p.to_public()).collect(),
|
||||
ledger,
|
||||
let mut witness = LedgerProofPrivate {
|
||||
bundles: Vec::new(),
|
||||
ledger: ledger.to_witness(),
|
||||
id: zone_id,
|
||||
};
|
||||
|
||||
// prepare the sparse merkle tree nullifier proofs
|
||||
for bundle in &bundles {
|
||||
let mut partials = Vec::new();
|
||||
|
||||
for ptx in &bundle.ptxs {
|
||||
let mut nf_proofs = Vec::new();
|
||||
|
||||
for input in &ptx.public.ptx.inputs {
|
||||
let nf_proof = ledger.add_nullifier(input.nullifier);
|
||||
nf_proofs.push(nf_proof);
|
||||
}
|
||||
|
||||
partials.push(LedgerPtxWitness {
|
||||
ptx: ptx.public.clone(),
|
||||
nf_proofs,
|
||||
});
|
||||
}
|
||||
|
||||
witness.bundles.push(LedgerBundleWitness { partials })
|
||||
}
|
||||
|
||||
let mut env = risc0_zkvm::ExecutorEnv::builder();
|
||||
|
||||
for bundle in bundles {
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
use ledger_proof_statements::ptx::{PtxPrivate, PtxPublic};
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use cl::cl::{merkle, PartialTxWitness};
|
||||
use cl::cl::{
|
||||
mmr::{MMRProof, MMR},
|
||||
PartialTxWitness,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ProvedPartialTx {
|
||||
@ -12,13 +15,13 @@ pub struct ProvedPartialTx {
|
||||
impl ProvedPartialTx {
|
||||
pub fn prove(
|
||||
ptx_witness: PartialTxWitness,
|
||||
input_cm_paths: Vec<Vec<merkle::PathNode>>,
|
||||
cm_roots: Vec<[u8; 32]>,
|
||||
input_cm_paths: Vec<MMRProof>,
|
||||
cm_mmr: MMR,
|
||||
) -> Result<ProvedPartialTx> {
|
||||
let ptx_private = PtxPrivate {
|
||||
ptx: ptx_witness,
|
||||
input_cm_paths,
|
||||
cm_roots: cm_roots.clone(),
|
||||
cm_mmr: cm_mmr.clone(),
|
||||
};
|
||||
|
||||
let env = risc0_zkvm::ExecutorEnv::builder()
|
||||
|
||||
@ -22,7 +22,7 @@ impl ProvedUpdateBundle {
|
||||
expected_zones.insert(bundle.id, HashSet::from_iter(bundle.zones.clone()));
|
||||
actual_zones
|
||||
.entry(bundle.id)
|
||||
.or_insert_with(|| HashSet::new())
|
||||
.or_insert_with(HashSet::new)
|
||||
.insert(proof.public.id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
use cl::{
|
||||
cl::{
|
||||
balance::Unit, merkle, mmr::MMR, note::derive_unit, BalanceWitness, InputWitness,
|
||||
NoteWitness, NullifierCommitment, NullifierSecret, OutputWitness, PartialTxWitness,
|
||||
balance::Unit, mmr::MMRProof, note::derive_unit, BalanceWitness, InputWitness, NoteWitness,
|
||||
NullifierCommitment, NullifierSecret, OutputWitness, PartialTxWitness,
|
||||
},
|
||||
zone_layer::{
|
||||
ledger::LedgerWitness,
|
||||
ledger::LedgerState,
|
||||
notes::{ZoneId, ZoneNote},
|
||||
tx::{UpdateBundle, ZoneUpdate},
|
||||
},
|
||||
@ -21,9 +21,9 @@ use ledger_proof_statements::{balance::BalancePrivate, stf::StfPublic};
|
||||
use rand_core::CryptoRngCore;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
fn nmo() -> &'static Unit {
|
||||
fn nmo() -> Unit {
|
||||
static NMO: OnceLock<Unit> = OnceLock::new();
|
||||
NMO.get_or_init(|| derive_unit("NMO"))
|
||||
*NMO.get_or_init(|| derive_unit("NMO"))
|
||||
}
|
||||
|
||||
struct User(NullifierSecret);
|
||||
@ -48,24 +48,22 @@ fn receive_utxo(note: NoteWitness, nf_pk: NullifierCommitment, zone_id: ZoneId)
|
||||
|
||||
fn cross_transfer_transition(
|
||||
input: InputWitness,
|
||||
input_path: Vec<merkle::PathNode>,
|
||||
input_path: MMRProof,
|
||||
to: User,
|
||||
amount: u64,
|
||||
zone_a: ZoneId,
|
||||
zone_b: ZoneId,
|
||||
mut ledger_a: LedgerWitness,
|
||||
mut ledger_b: LedgerWitness,
|
||||
mut ledger_a: LedgerState,
|
||||
mut ledger_b: LedgerState,
|
||||
) -> (ProvedLedgerTransition, ProvedLedgerTransition) {
|
||||
let mut rng = rand::thread_rng();
|
||||
assert!(amount <= input.note.value);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let change = input.note.value - amount;
|
||||
let transfer = OutputWitness::new(
|
||||
NoteWitness::basic(amount, *nmo(), &mut rng),
|
||||
to.pk(),
|
||||
zone_b,
|
||||
);
|
||||
let transfer = OutputWitness::new(NoteWitness::basic(amount, nmo(), &mut rng), to.pk(), zone_b);
|
||||
let change = OutputWitness::new(
|
||||
NoteWitness::basic(change, *nmo(), &mut rng),
|
||||
NoteWitness::basic(change, nmo(), &mut rng),
|
||||
input.nf_sk.commit(),
|
||||
zone_a,
|
||||
);
|
||||
@ -76,12 +74,8 @@ fn cross_transfer_transition(
|
||||
outputs: vec![transfer, change],
|
||||
balance_blinding: BalanceWitness::random_blinding(&mut rng),
|
||||
};
|
||||
let proved_ptx = ProvedPartialTx::prove(
|
||||
ptx_witness.clone(),
|
||||
vec![input_path],
|
||||
vec![ledger_a.commitments.roots[0].root],
|
||||
)
|
||||
.unwrap();
|
||||
let proved_ptx =
|
||||
ProvedPartialTx::prove(ptx_witness.clone(), vec![input_path], ledger_a.cm_mmr()).unwrap();
|
||||
|
||||
let balance = ProvedBalance::prove(&BalancePrivate {
|
||||
balances: vec![ptx_witness.balance()],
|
||||
@ -108,13 +102,19 @@ fn cross_transfer_transition(
|
||||
let ledger_b_transition =
|
||||
ProvedLedgerTransition::prove(ledger_b.clone(), zone_b, vec![zone_tx], vec![]).unwrap();
|
||||
|
||||
ledger_a.commitments.push(&change.commit_note().0);
|
||||
ledger_a.nullifiers.push(input.nullifier());
|
||||
ledger_a.add_commitment(change.commit_note());
|
||||
ledger_a.add_nullifier(input.nullifier());
|
||||
|
||||
ledger_b.commitments.push(&transfer.commit_note().0);
|
||||
ledger_b.add_commitment(transfer.commit_note());
|
||||
|
||||
assert_eq!(ledger_a_transition.public.ledger, ledger_a.commit());
|
||||
assert_eq!(ledger_b_transition.public.ledger, ledger_b.commit());
|
||||
assert_eq!(
|
||||
ledger_a_transition.public.ledger,
|
||||
ledger_a.to_witness().commit()
|
||||
);
|
||||
assert_eq!(
|
||||
ledger_b_transition.public.ledger,
|
||||
ledger_b.to_witness().commit()
|
||||
);
|
||||
|
||||
(ledger_a_transition, ledger_b_transition)
|
||||
}
|
||||
@ -133,36 +133,28 @@ fn zone_update_cross() {
|
||||
|
||||
// Alice has an unspent note worth 10 NMO
|
||||
let utxo = receive_utxo(
|
||||
NoteWitness::stateless(10, *nmo(), ConstraintProof::nop_constraint(), &mut rng),
|
||||
NoteWitness::stateless(10, nmo(), ConstraintProof::nop_constraint(), &mut rng),
|
||||
alice.pk(),
|
||||
zone_a_id,
|
||||
);
|
||||
|
||||
let alice_input = InputWitness::from_output(utxo, alice.sk());
|
||||
|
||||
let mut mmr = MMR::new();
|
||||
let input_cm_path = mmr.push(&utxo.commit_note().0).path;
|
||||
let mut ledger_a = LedgerState::default();
|
||||
let input_cm_path = ledger_a.add_commitment(utxo.commit_note());
|
||||
|
||||
let ledger_a = LedgerWitness {
|
||||
commitments: mmr,
|
||||
nullifiers: vec![],
|
||||
};
|
||||
|
||||
let ledger_b = LedgerWitness {
|
||||
commitments: MMR::new(),
|
||||
nullifiers: vec![],
|
||||
};
|
||||
let ledger_b = LedgerState::default();
|
||||
|
||||
let zone_a_old = ZoneNote {
|
||||
id: zone_a_id,
|
||||
state: [0; 32],
|
||||
ledger: ledger_a.commit(),
|
||||
ledger: ledger_a.to_witness().commit(),
|
||||
stf: [0; 32],
|
||||
};
|
||||
let zone_b_old = ZoneNote {
|
||||
id: zone_b_id,
|
||||
state: [0; 32],
|
||||
ledger: ledger_b.commit(),
|
||||
ledger: ledger_b.to_witness().commit(),
|
||||
stf: [0; 32],
|
||||
};
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use cl::cl::{
|
||||
merkle,
|
||||
mmr::{MMRProof, MMR},
|
||||
PartialTx, PartialTxWitness,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user