use NullifierNonce::evolve

This commit is contained in:
Giacomo Pasini 2024-08-02 17:44:03 +02:00
parent ca42d3ed4f
commit ca2c141d91
No known key found for this signature in database
GPG Key ID: FC08489D2D895D4B
2 changed files with 17 additions and 12 deletions

View File

@ -2,11 +2,10 @@
///
/// Our goal: prove the zone authorized spending of funds
use cl::merkle;
use cl::nullifier::{Nullifier, NullifierNonce, NullifierSecret};
use cl::nullifier::{Nullifier, NullifierSecret};
use goas_proof_statements::zone_funds::SpendFundsPrivate;
use proof_statements::death_constraint::DeathConstraintPublic;
use risc0_zkvm::guest::env;
use sha2::{Digest, Sha256};
fn main() {
let SpendFundsPrivate {
@ -41,10 +40,10 @@ fn main() {
let spend_event_leaf = merkle::leaf(&spend_event.to_bytes());
let event_root = merkle::path_root(spend_event_leaf, &spend_event_state_path);
let io_root = merkle::node(event_root, txs_root);
let state_root = merkle::node(zone_id, balances_root);
let root = merkle::node(io_root, state_root);
assert_eq!(root, zone_note.output.note.state);
assert_eq!(
merkle::root([event_root, txs_root, zone_id, balances_root]),
zone_note.output.note.state
);
assert_eq!(ptx_root, out_zone_funds.ptx_root());
@ -76,7 +75,10 @@ fn main() {
);
assert_eq!(
out_zone_funds.output.nonce,
NullifierNonce::from_bytes(Sha256::digest(&out_zone_funds.output.nonce.as_bytes()).into())
in_zone_funds
.input
.nonce
.evolve(&NullifierSecret::from_bytes([0; 16]))
);
// the state is propagated
assert_eq!(

View File

@ -1,7 +1,7 @@
use cl::{
input::InputWitness,
merkle,
nullifier::{Nullifier, NullifierNonce, NullifierSecret},
nullifier::{Nullifier, NullifierSecret},
partial_tx::{MAX_INPUTS, MAX_OUTPUTS},
PtxRoot,
};
@ -13,7 +13,6 @@ use proof_statements::{
ptx::{PartialTxInputPrivate, PartialTxOutputPrivate},
};
use risc0_zkvm::guest::env;
use sha2::{Digest, Sha256};
fn withdraw(mut state: StateWitness, withdraw: Withdraw) -> StateWitness {
state.included_txs.push(Input::Withdraw(withdraw));
@ -100,7 +99,9 @@ fn deposit(
// nonce is correctly evolved
assert_eq!(
zone_funds_out.nonce,
NullifierNonce::from_bytes(Sha256::digest(&zone_funds_in.nonce.as_bytes()).into())
zone_funds_in
.nonce
.evolve(&NullifierSecret::from_bytes([0; 16]))
);
// 5) Check zone state notes are correctly created
@ -115,7 +116,9 @@ fn deposit(
// nonce is correctly evolved
assert_eq!(
zone_note_out.nonce,
NullifierNonce::from_bytes(Sha256::digest(&zone_note_in.nonce.as_bytes()).into())
zone_note_in
.nonce
.evolve(&NullifierSecret::from_bytes([0; 16]))
);
let nullifier = Nullifier::new(zone_note_in.nf_sk, zone_note_in.nonce);
assert_eq!(nullifier, pub_inputs.nf);
@ -166,7 +169,7 @@ fn validate_zone_output(
// the nonce is correctly evolved
assert_eq!(
output.nonce,
NullifierNonce::from_bytes(Sha256::digest(&input.nonce.as_bytes()).into())
input.nonce.evolve(&NullifierSecret::from_bytes([0; 16]))
);
}