From 201c3810d32f89faff4bf7cf05d5b1bb6e54b68a Mon Sep 17 00:00:00 2001 From: Giacomo Pasini Date: Tue, 16 Jul 2024 16:56:28 +0200 Subject: [PATCH] Add zone funds spending logic First iteration of the death constraint for spending zone funds --- goas/cl/cl/src/nullifier.rs | 10 +++++++++- goas/cl/cl/src/partial_tx.rs | 8 +++++++- goas/cl/proof_statements/src/lib.rs | 1 + goas/cl/risc0_proofs/Cargo.toml | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/goas/cl/cl/src/nullifier.rs b/goas/cl/cl/src/nullifier.rs index 76c3b06..9d55378 100644 --- a/goas/cl/cl/src/nullifier.rs +++ b/goas/cl/cl/src/nullifier.rs @@ -51,6 +51,10 @@ impl NullifierSecret { let commit_bytes: [u8; 32] = hasher.finalize().into(); NullifierCommitment(commit_bytes) } + + pub fn from_bytes(bytes: [u8; 16]) -> Self { + Self(bytes) + } } impl NullifierCommitment { @@ -73,6 +77,10 @@ impl NullifierNonce { pub fn as_bytes(&self) -> &[u8; 16] { &self.0 } + + pub fn from_bytes(bytes: [u8; 16]) -> Self { + Self(bytes) + } } impl Nullifier { @@ -86,7 +94,7 @@ impl Nullifier { Self(nf_bytes) } - pub(crate) fn as_bytes(&self) -> &[u8; 32] { + pub fn as_bytes(&self) -> &[u8; 32] { &self.0 } } diff --git a/goas/cl/cl/src/partial_tx.rs b/goas/cl/cl/src/partial_tx.rs index 7b3abbd..814a70f 100644 --- a/goas/cl/cl/src/partial_tx.rs +++ b/goas/cl/cl/src/partial_tx.rs @@ -12,9 +12,15 @@ const MAX_OUTPUTS: usize = 8; /// The partial transaction commitment couples an input to a partial transaction. /// Prevents partial tx unbundling. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct PtxRoot(pub [u8; 32]); +impl From<[u8; 32]> for PtxRoot { + fn from(bytes: [u8; 32]) -> Self { + Self(bytes) + } +} + impl PtxRoot { pub fn random(mut rng: impl RngCore) -> Self { let mut sk = [0u8; 32]; diff --git a/goas/cl/proof_statements/src/lib.rs b/goas/cl/proof_statements/src/lib.rs index 7839bc5..a9849fd 100644 --- a/goas/cl/proof_statements/src/lib.rs +++ b/goas/cl/proof_statements/src/lib.rs @@ -1 +1,2 @@ pub mod input; +pub mod zone_funds; diff --git a/goas/cl/risc0_proofs/Cargo.toml b/goas/cl/risc0_proofs/Cargo.toml index 198a3c0..3a79569 100644 --- a/goas/cl/risc0_proofs/Cargo.toml +++ b/goas/cl/risc0_proofs/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" risc0-build = { version = "1.0" } [package.metadata.risc0] -methods = ["input"] +methods = ["input", "withdraw"]