mirror of
https://github.com/logos-blockchain/logos-blockchain-pocs.git
synced 2026-01-08 08:03:06 +00:00
move to zone_layer
This commit is contained in:
parent
ec5cd13d46
commit
afd9bafb79
@ -2,7 +2,7 @@ use rand_core::CryptoRngCore;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::PartialTxWitness;
|
||||
use crate::cl::PartialTxWitness;
|
||||
|
||||
pub type Value = u64;
|
||||
pub type Unit = [u8; 32];
|
||||
@ -1,6 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{partial_tx::PartialTx, BalanceWitness, PartialTxWitness};
|
||||
use crate::cl::{partial_tx::PartialTx, BalanceWitness, PartialTxWitness};
|
||||
|
||||
/// The transaction bundle is a collection of partial transactions.
|
||||
/// The goal in bundling transactions is to produce a set of partial transactions
|
||||
@ -2,10 +2,10 @@
|
||||
///
|
||||
/// Partial transactions, as the name suggests, are transactions
|
||||
/// which on their own may not balance (i.e. \sum inputs != \sum outputs)
|
||||
use crate::{
|
||||
use crate::cl::{
|
||||
note::{Constraint, NoteWitness},
|
||||
nullifier::{Nullifier, NullifierSecret},
|
||||
Nonce,
|
||||
Nonce, NoteCommitment, OutputWitness,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
@ -27,12 +27,12 @@ impl InputWitness {
|
||||
Self { note, nf_sk }
|
||||
}
|
||||
|
||||
pub fn from_output(output: crate::OutputWitness, nf_sk: NullifierSecret) -> Self {
|
||||
pub fn from_output(output: OutputWitness, nf_sk: NullifierSecret) -> Self {
|
||||
assert_eq!(nf_sk.commit(), output.nf_pk);
|
||||
Self::new(output.note, nf_sk)
|
||||
}
|
||||
|
||||
pub fn public(output: crate::OutputWitness) -> Self {
|
||||
pub fn public(output: OutputWitness) -> Self {
|
||||
let nf_sk = NullifierSecret::zero();
|
||||
assert_eq!(nf_sk.commit(), output.nf_pk); // ensure the output was a public UTXO
|
||||
Self::new(output.note, nf_sk)
|
||||
@ -49,8 +49,8 @@ impl InputWitness {
|
||||
Nonce::from_bytes(nonce_bytes)
|
||||
}
|
||||
|
||||
pub fn evolve_output(&self, tag: &dyn AsRef<[u8]>, domain: &[u8]) -> crate::OutputWitness {
|
||||
crate::OutputWitness {
|
||||
pub fn evolve_output(&self, tag: &dyn AsRef<[u8]>, domain: &[u8]) -> OutputWitness {
|
||||
OutputWitness {
|
||||
note: NoteWitness {
|
||||
nonce: self.evolved_nonce(tag, domain),
|
||||
..self.note
|
||||
@ -70,7 +70,7 @@ impl InputWitness {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn note_commitment(&self, tag: &dyn AsRef<[u8]>) -> crate::NoteCommitment {
|
||||
pub fn note_commitment(&self, tag: &dyn AsRef<[u8]>) -> NoteCommitment {
|
||||
self.note.commit(tag, self.nf_sk.commit())
|
||||
}
|
||||
}
|
||||
21
emmarin/cl/cl/src/cl/mod.rs
Normal file
21
emmarin/cl/cl/src/cl/mod.rs
Normal file
@ -0,0 +1,21 @@
|
||||
pub mod balance;
|
||||
pub mod bundle;
|
||||
pub mod crypto;
|
||||
pub mod error;
|
||||
pub mod input;
|
||||
pub mod merkle;
|
||||
pub mod note;
|
||||
pub mod nullifier;
|
||||
pub mod output;
|
||||
pub mod pact;
|
||||
pub mod partial_tx;
|
||||
|
||||
pub use balance::{Balance, BalanceWitness};
|
||||
pub use bundle::{Bundle, BundleWitness};
|
||||
pub use input::{Input, InputWitness};
|
||||
pub use note::{Constraint, Nonce, NoteCommitment, NoteWitness};
|
||||
pub use nullifier::{Nullifier, NullifierCommitment, NullifierSecret};
|
||||
pub use output::{Output, OutputWitness};
|
||||
pub use partial_tx::{
|
||||
PartialTx, PartialTxInputWitness, PartialTxOutputWitness, PartialTxWitness, PtxRoot,
|
||||
};
|
||||
@ -2,7 +2,7 @@ use rand::RngCore;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::{balance::Unit, nullifier::NullifierCommitment};
|
||||
use crate::cl::{balance::Unit, nullifier::NullifierCommitment};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
pub struct Constraint(pub [u8; 32]);
|
||||
@ -10,7 +10,7 @@ use rand_core::RngCore;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::NoteCommitment;
|
||||
use crate::cl::NoteCommitment;
|
||||
|
||||
// Maintained privately by note holder
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@ -1,6 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
use crate::cl::{
|
||||
note::{NoteCommitment, NoteWitness},
|
||||
nullifier::NullifierCommitment,
|
||||
NullifierSecret,
|
||||
37
emmarin/cl/cl/src/cl/pact.rs
Normal file
37
emmarin/cl/cl/src/cl/pact.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use crate::zone_layer::ZoneId;
|
||||
use crate::cl::{PartialTx, PartialTxWitness};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Pact {
|
||||
pub tx: PartialTx,
|
||||
pub to: Vec<ZoneId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct PactWitness {
|
||||
pub tx: PartialTxWitness,
|
||||
pub from: ZoneId,
|
||||
pub to: Vec<ZoneId>,
|
||||
}
|
||||
|
||||
impl PactWitness {
|
||||
pub fn commit(&self) -> Pact {
|
||||
assert_eq!(self.tx.outputs.len(), self.to.len());
|
||||
let ptx = PartialTx {
|
||||
inputs: Vec::from_iter(self.tx.inputs.iter().map(|i| i.commit(&self.from))),
|
||||
outputs: Vec::from_iter(
|
||||
self.tx
|
||||
.outputs
|
||||
.iter()
|
||||
.zip(&self.to)
|
||||
.map(|(o, z)| o.commit(z)),
|
||||
),
|
||||
balance: self.tx.balance().commit(),
|
||||
};
|
||||
Pact {
|
||||
tx: ptx,
|
||||
to: self.to.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,12 @@
|
||||
use rand_core::{CryptoRngCore, RngCore};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::balance::{Balance, BalanceWitness};
|
||||
use crate::input::{Input, InputWitness};
|
||||
use crate::merkle;
|
||||
use crate::output::{Output, OutputWitness};
|
||||
use crate::cl::{
|
||||
balance::{Balance, BalanceWitness},
|
||||
input::{Input, InputWitness},
|
||||
merkle,
|
||||
output::{Output, OutputWitness},
|
||||
};
|
||||
|
||||
pub const MAX_INPUTS: usize = 8;
|
||||
pub const MAX_OUTPUTS: usize = 8;
|
||||
@ -1,21 +1,2 @@
|
||||
pub mod balance;
|
||||
pub mod bundle;
|
||||
pub mod crypto;
|
||||
pub mod error;
|
||||
pub mod input;
|
||||
pub mod merkle;
|
||||
pub mod note;
|
||||
pub mod nullifier;
|
||||
pub mod output;
|
||||
pub mod partial_tx;
|
||||
pub mod zones;
|
||||
|
||||
pub use balance::{Balance, BalanceWitness};
|
||||
pub use bundle::{Bundle, BundleWitness};
|
||||
pub use input::{Input, InputWitness};
|
||||
pub use note::{Constraint, Nonce, NoteCommitment, NoteWitness};
|
||||
pub use nullifier::{Nullifier, NullifierCommitment, NullifierSecret};
|
||||
pub use output::{Output, OutputWitness};
|
||||
pub use partial_tx::{
|
||||
PartialTx, PartialTxInputWitness, PartialTxOutputWitness, PartialTxWitness, PtxRoot,
|
||||
};
|
||||
pub mod cl;
|
||||
pub mod zone_layer;
|
||||
|
||||
@ -1,40 +1,6 @@
|
||||
use crate::{merkle, Constraint, NoteCommitment, Nullifier, PartialTx, PartialTxWitness};
|
||||
use crate::cl::{merkle, Constraint, NoteCommitment, Nullifier};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Pact {
|
||||
pub tx: PartialTx,
|
||||
pub to: Vec<ZoneId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct PactWitness {
|
||||
pub tx: PartialTxWitness,
|
||||
pub from: ZoneId,
|
||||
pub to: Vec<ZoneId>,
|
||||
}
|
||||
|
||||
impl PactWitness {
|
||||
pub fn commit(&self) -> Pact {
|
||||
assert_eq!(self.tx.outputs.len(), self.to.len());
|
||||
let ptx = PartialTx {
|
||||
inputs: Vec::from_iter(self.tx.inputs.iter().map(|i| i.commit(&self.from))),
|
||||
outputs: Vec::from_iter(
|
||||
self.tx
|
||||
.outputs
|
||||
.iter()
|
||||
.zip(&self.to)
|
||||
.map(|(o, z)| o.commit(z)),
|
||||
),
|
||||
balance: self.tx.balance().commit(),
|
||||
};
|
||||
Pact {
|
||||
tx: ptx,
|
||||
to: self.to.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ZoneNote {
|
||||
pub stf: Constraint,
|
||||
pub state: State,
|
||||
@ -1,6 +1,6 @@
|
||||
use ledger_proof_statements::bundle::{BundlePrivate, BundlePublic};
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use cl::cl::BundleWitness;
|
||||
use ledger_proof_statements::bundle::{BundlePrivate, BundlePublic};
|
||||
|
||||
pub struct ProvedBundle {
|
||||
pub bundle: BundlePublic,
|
||||
@ -8,7 +8,7 @@ pub struct ProvedBundle {
|
||||
}
|
||||
|
||||
impl ProvedBundle {
|
||||
pub fn prove(bundle_witness: &cl::BundleWitness) -> Result<Self> {
|
||||
pub fn prove(bundle_witness: &BundleWitness) -> Result<Self> {
|
||||
// need to show that bundle is balanced.
|
||||
// i.e. the sum of ptx balances is 0
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use cl::Constraint;
|
||||
use cl::cl::{Constraint, Nullifier, PtxRoot};
|
||||
use ledger_proof_statements::constraint::ConstraintPublic;
|
||||
|
||||
use crate::error::Result;
|
||||
@ -41,7 +41,7 @@ impl ConstraintProof {
|
||||
risc0_constraint(nomos_cl_risc0_proofs::CONSTRAINT_NOP_ID)
|
||||
}
|
||||
|
||||
pub fn prove_nop(nf: cl::Nullifier, ptx_root: cl::PtxRoot) -> Self {
|
||||
pub fn prove_nop(nf: Nullifier, ptx_root: PtxRoot) -> Self {
|
||||
let constraint_public = ConstraintPublic { nf, ptx_root };
|
||||
let env = risc0_zkvm::ExecutorEnv::builder()
|
||||
.write(&constraint_public)
|
||||
|
||||
@ -7,7 +7,7 @@ use crate::{
|
||||
pact::ProvedPact,
|
||||
partial_tx::ProvedPartialTx,
|
||||
};
|
||||
use cl::zones::{LedgerWitness, ZoneId};
|
||||
use cl::zone_layer::{LedgerWitness, ZoneId};
|
||||
|
||||
pub struct ProvedLedgerTransition {
|
||||
pub public: LedgerProofPublic,
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
use crate::error::{Error, Result};
|
||||
use cl::zones::*;
|
||||
use cl::cl::{
|
||||
merkle,
|
||||
pact::{Pact, PactWitness},
|
||||
};
|
||||
use ledger_proof_statements::pact::{PactPrivate, PactPublic};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -11,8 +14,8 @@ pub struct ProvedPact {
|
||||
|
||||
impl ProvedPact {
|
||||
pub fn prove(
|
||||
pact: cl::zones::PactWitness,
|
||||
input_cm_paths: Vec<Vec<cl::merkle::PathNode>>,
|
||||
pact: PactWitness,
|
||||
input_cm_paths: Vec<Vec<merkle::PathNode>>,
|
||||
cm_root: [u8; 32],
|
||||
) -> Result<ProvedPact> {
|
||||
let pact_private = PactPrivate {
|
||||
|
||||
@ -1,18 +1,19 @@
|
||||
use ledger_proof_statements::ptx::{PtxPrivate, PtxPublic};
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use cl::zones::*;
|
||||
use cl::cl::{merkle, PartialTx, PartialTxWitness};
|
||||
use cl::zone_layer::ZoneId;
|
||||
|
||||
pub struct ProvedPartialTx {
|
||||
pub ptx: cl::PartialTx,
|
||||
pub ptx: PartialTx,
|
||||
pub cm_root: [u8; 32],
|
||||
pub risc0_receipt: risc0_zkvm::Receipt,
|
||||
}
|
||||
|
||||
impl ProvedPartialTx {
|
||||
pub fn prove(
|
||||
ptx: &cl::PartialTxWitness,
|
||||
input_cm_paths: Vec<Vec<cl::merkle::PathNode>>,
|
||||
ptx: &PartialTxWitness,
|
||||
input_cm_paths: Vec<Vec<merkle::PathNode>>,
|
||||
cm_root: [u8; 32],
|
||||
id: ZoneId,
|
||||
) -> Result<ProvedPartialTx> {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use cl::{Balance, BalanceWitness};
|
||||
use cl::cl::{Balance, BalanceWitness};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use cl::{Nullifier, PtxRoot};
|
||||
use cl::cl::{Nullifier, PtxRoot};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
use crate::bundle::BundlePublic;
|
||||
use crate::pact::PactPublic;
|
||||
use crate::ptx::PtxPublic;
|
||||
use cl::zones::*;
|
||||
use cl::Output;
|
||||
use cl::cl::Output;
|
||||
use cl::zone_layer::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
use cl::zones::*;
|
||||
use cl::cl::{
|
||||
merkle,
|
||||
pact::{Pact, PactWitness},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@ -10,6 +13,6 @@ pub struct PactPublic {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct PactPrivate {
|
||||
pub pact: PactWitness,
|
||||
pub input_cm_paths: Vec<Vec<cl::merkle::PathNode>>,
|
||||
pub input_cm_paths: Vec<Vec<merkle::PathNode>>,
|
||||
pub cm_root: [u8; 32],
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use cl::{PartialTx, PartialTxWitness};
|
||||
use cl::cl::{merkle, PartialTx, PartialTxWitness};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@ -10,7 +10,7 @@ pub struct PtxPublic {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct PtxPrivate {
|
||||
pub ptx: PartialTxWitness,
|
||||
pub input_cm_paths: Vec<Vec<cl::merkle::PathNode>>,
|
||||
pub input_cm_paths: Vec<Vec<merkle::PathNode>>,
|
||||
pub cm_root: [u8; 32],
|
||||
pub from: [u8; 32],
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use cl::cl::BalanceWitness;
|
||||
/// Bundle Proof
|
||||
///
|
||||
/// The bundle proof demonstrates that the set of partial transactions
|
||||
@ -17,7 +18,7 @@ fn main() {
|
||||
balances: Vec::from_iter(bundle_private.balances.iter().map(|b| b.commit())),
|
||||
};
|
||||
|
||||
assert!(cl::BalanceWitness::combine(bundle_private.balances, [0u8; 16]).is_zero());
|
||||
assert!(BalanceWitness::combine(bundle_private.balances, [0u8; 16]).is_zero());
|
||||
|
||||
env::commit(&bundle_public);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/// Input Proof
|
||||
use cl::merkle;
|
||||
use cl::cl::merkle;
|
||||
use ledger_proof_statements::pact::{PactPrivate, PactPublic};
|
||||
use risc0_zkvm::guest::env;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/// Input Proof
|
||||
use cl::merkle;
|
||||
use cl::cl::merkle;
|
||||
use ledger_proof_statements::ptx::{PtxPrivate, PtxPublic};
|
||||
use risc0_zkvm::guest::env;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user