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