cl: integrate simple zone into CL data model

This commit is contained in:
David Rusu 2024-06-27 07:24:27 +00:00
parent 50d17ddc25
commit ac6f7279a6
4 changed files with 42 additions and 43 deletions

2
goas/.gitignore vendored
View File

@ -2,3 +2,5 @@
Cargo.lock
methods/guest/Cargo.lock
target/
output/
proof.stark

View File

@ -7,8 +7,9 @@ use common::*;
use cl::note::NoteWitness;
use cl::input::InputWitness;
use cl::output::OutputWitness;
use cl::nullifier::{NullifierCommitment, Nullifier
use cl::nullifier::NullifierSecret;
use cl::partial_tx::{PartialTx, PartialTxWitness};
use cl::merkle;
fn main() {
// Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run`
@ -26,42 +27,46 @@ fn main() {
amount: 10,
};
let in_state_cm = calculate_state_hash(&state),
let in_journal_cm = calculate_journal_hash(&journal),
let in_state_root = merkle::node(in_start_cm, in_journal_cm);
let in_state_cm = calculate_state_hash(&state);
let in_journal_cm = calculate_journal_hash(&journal);
let in_state_root = merkle::node(in_state_cm, in_journal_cm);
let in_note = NoteWitness::new(1, "ZONE", in_state_root, &mut rng);
let mut out_journal = journal.clone();
out_journal.push(zone_input);
let out_state_cm = calculate_state_hash(&stf(state.clone(), zone_input)),
let out_journal_cm = calculate_journal_hash(&out_journal),
let out_state_cm = calculate_state_hash(&stf(state.clone(), zone_input));
let out_journal_cm = calculate_journal_hash(&out_journal);
let out_state_root = merkle::node(out_state_cm, out_journal_cm);
let out_note = NoteWitness::new(1, "ZONE", out_state_root, &mut rng);
let out_note = NoteWitness::new(1, "ZONE", out_state_root, &mut rng);
let input = InputWitness::random(in_note, &mut rng);
let output = OutputWitness::random(out_note, NullifierSecret::random(&mut rng).commit(), &mut rng);
let ptx = PartialTx::from_witness(PartialTxWitness {
inputs: vec![InputWitness::random(in_note, &mut rng)],
outputs: vec![OutputWitness::random(out_note, NullifierCommitment::random(&mut rng), &mut rng)],
inputs: vec![input.clone()],
outputs: vec![output.clone()],
});
let ptx_root = ptx.root();
let ptx_root = ptx.root().0;
let in_ptx_path = ptx.input_merkle_path(0);
let out_ptx_path = ptx.output_merkle_path(0);
let env = ExecutorEnv::builder()
.write(&ptx_root)
.unwrap()
.write(&ptx.input_root)
.write(&ptx.input_root())
.unwrap()
.write(&ptx.output_root)
.write(&ptx.output_root())
.unwrap()
.write(&in_ptx_path)
.unwrap()
.write(&out_ptx_path)
.unwrap()
.write(&in_note)
.write(&input)
.unwrap()
.write(&out_note)
.write(&output)
.unwrap()
.write(&zone_input)
.unwrap()
.write(&state)
.unwrap()

View File

@ -10,4 +10,5 @@ risc0-zkvm = { version = "1.0.1", default-features = false, features = ['std'] }
blake2 = "0.10"
serde = { version = "1.0", features = ["derive"] }
bincode = "1"
common = { path = "../../common" }
common = { path = "../../common" }
cl = { path = "../../../cl" }

View File

@ -2,34 +2,23 @@ use blake2::{Blake2s256, Digest};
use risc0_zkvm::guest::env;
use common::*;
use cl::merkle;
use cl::note::NoteWitness
use cl::note::NoteWitness;
use cl::input::InputWitness;
use cl::output::OutputWitness;
/// Public Inputs:
/// * ptx_root: the root of the partial tx merkle tree of inputs/outputs
/// Private inputs:
/// TODO
/// Glue the zone and the cl together, specifically, it verifies the note requesting
/// a transfer is included as part of the same transaction in the cl
fn verify_ptx_inputs(ptx_root: [u8; 32], ptx_path: &[[u8; 32]], note: &Note) {
assert!(verify_path(&ptx_root, &ptx_path, &note));
}
/// Glue the zone and the cl together, specifically, it verifies an output note
/// containing the zone state is included as part of the same transaction in the cl
/// (this is done in the death condition to disallow burning)
fn verify_ptx_outputs(ptx_root: [u8; 32], ptx_path: &[[u8; 32]], note: &Note) {
assert!(verify_path(&ptx_root, &ptx_path, &note));
}
fn execute(
ptx_root: [u8; 32],
input_root: [u8; 32],
output_root: [u8; 32],
in_ptx_path: Vec<merkle::PathNode>,
out_ptx_path: Vec<merkle::PathNode>,
in_note: NoteWitness,
out_note: NotWitness,
in_note: InputWitness,
out_note: OutputWitness,
input: Input,
state: State,
mut journal: Journal,
@ -37,13 +26,16 @@ fn execute(
// verify ptx/cl preconditions
assert_eq!(ptx_root, merkle::node(input_root, output_root));
assert!(merkle::verify_path(in_note.commit().0, in_ptx_path, input_root));
// Glue the zone and the cl together, specifically, it verifies the note requesting
// a transfer is included as part of the same transaction in the cl
assert!(merkle::verify_path(merkle::leaf(&in_note.commit().to_bytes()), &in_ptx_path, input_root));
// check the commitments match the actual data
let state_cm = calculate_state_hash(&state);
let journal_cm = calculate_journal_hash(&journal);
let state_root = merkle::node(state_cm, journal_cm);
assert_eq!(state_root, in_note.state);
assert_eq!(state_root, in_note.note.state);
// then run the state transition function
let state = stf(state, input);
@ -55,8 +47,12 @@ fn execute(
let out_journal_cm = calculate_journal_hash(&journal);
let out_state_root = merkle::node(out_state_cm, out_journal_cm);
// TODO: verify death constraints are propagated
assert_eq!(out_state_root, out_note.state);
assert!(merkle::verify_path(out_note.commit().0, out_ptx_path, output_root));
assert_eq!(out_state_root, out_note.note.state);
// Glue the zone and the cl together, specifically, it verifies an output note
// containing the zone state is included as part of the same transaction in the cl
// (this is done in the death condition to disallow burning)
assert!(merkle::verify_path(merkle::leaf(&out_note.commit().to_bytes()), &out_ptx_path, output_root));
}
fn main() {
@ -68,9 +64,9 @@ fn main() {
let output_root: [u8; 32] = env::read();
let in_ptx_path: Vec<merkle::PathNode> = env::read();
let out_ptx_path: Vec<merkle::PathNode> = env::read();
let in_note: NoteWitness = env::read();
let out_note: NoteWitness = env::read();
let input: Input = env::read()
let in_note: InputWitness = env::read();
let out_note: OutputWitness = env::read();
let input: Input = env::read();
let state: State = env::read();
let journal: Journal = env::read();
@ -86,8 +82,3 @@ fn calculate_journal_hash(journal: &Journal) -> [u8; 32] {
let bytes = bincode::serialize(journal).unwrap();
Blake2s256::digest(&bytes).into()
}
fn verify_path(_ptx_root: &[u8; 32], _ptx_path: &[[u8; 32]], _note: &Note) -> bool {
// for now we just return true
true
}