refactor: make programs privacy-agnostic in the privacy circuit

This commit is contained in:
Moudy
2026-04-17 07:29:40 +02:00
parent 48478ca21e
commit f9a5a7635e
51 changed files with 309 additions and 269 deletions
@@ -41,7 +41,6 @@ fn main() {
instruction_data: instruction_data.clone(),
pre_states: vec![running_sender_pre.clone(), running_recipient_pre.clone()], /* <- Account order permutation here */
pda_seeds: pda_seed.iter().copied().collect(),
private_pda_seeds: vec![],
};
chained_calls.push(new_chained_call);
@@ -32,7 +32,6 @@ fn main() {
instruction_data: to_vec(&timestamp).unwrap(),
pre_states: pre_states.clone(),
pda_seeds: vec![],
private_pda_seeds: vec![],
};
ProgramOutput::new(
@@ -71,7 +71,6 @@ fn main() {
pre_states: vec![receiver_authorized, vault_pre.clone()],
instruction_data: transfer_instruction,
pda_seeds: vec![PdaSeed::new([1_u8; 32])],
private_pda_seeds: vec![],
});
}
// Malicious path (return_funds = false): emit no chained calls.
@@ -129,7 +129,6 @@ fn main() {
pre_states: vec![vault_authorized, receiver_pre.clone()],
instruction_data: transfer_instruction,
pda_seeds: vec![PdaSeed::new([0_u8; 32])],
private_pda_seeds: vec![],
};
// Chained call 2: User callback.
@@ -140,7 +139,6 @@ fn main() {
pre_states: vec![vault_after_transfer, receiver_after_transfer],
instruction_data: callback_instruction_data,
pda_seeds: vec![],
private_pda_seeds: vec![],
};
// Chained call 3: Self-call to enforce the invariant.
@@ -159,7 +157,6 @@ fn main() {
pre_states: vec![vault_after_callback],
instruction_data: invariant_instruction,
pda_seeds: vec![],
private_pda_seeds: vec![],
};
// The initiator itself makes no direct state changes.
@@ -39,7 +39,6 @@ fn main() {
instruction_data,
pre_states: vec![authorised_sender, receiver.clone()],
pda_seeds: vec![],
private_pda_seeds: vec![],
};
ProgramOutput::new(
@@ -1,34 +0,0 @@
use nssa_core::{
NullifierPublicKey,
program::{AccountPostState, Claim, PdaSeed, ProgramInput, ProgramOutput, read_nssa_inputs},
};
type Instruction = (PdaSeed, NullifierPublicKey);
fn main() {
let (
ProgramInput {
self_program_id,
caller_program_id,
pre_states,
instruction: (seed, npk),
},
instruction_words,
) = read_nssa_inputs::<Instruction>();
let Ok([pre]) = <[_; 1]>::try_from(pre_states) else {
return;
};
let account_post =
AccountPostState::new_claimed(pre.account.clone(), Claim::PrivatePda { seed, npk });
ProgramOutput::new(
self_program_id,
caller_program_id,
instruction_words,
vec![pre],
vec![account_post],
)
.write();
}
@@ -0,0 +1,51 @@
use nssa_core::program::{
AccountPostState, ChainedCall, Claim, PdaSeed, ProgramId, ProgramInput, ProgramOutput,
read_nssa_inputs,
};
use risc0_zkvm::serde::to_vec;
/// Claims the sole `pre_state` as a PDA with `claim_seed`, then chains to `callee_program_id`
/// delegating authorization with `delegated_seed` in `pda_seeds`. When `claim_seed ==
/// delegated_seed` this exercises the happy caller-seeds authorization path for mask-3 private
/// PDAs in `validate_and_sync_states`; when they differ, the callee's mask-3 `pre_state` has
/// no matching authorization source and the circuit must reject.
type Instruction = (PdaSeed, PdaSeed, ProgramId);
fn main() {
let (
ProgramInput {
self_program_id,
caller_program_id,
pre_states,
instruction: (claim_seed, delegated_seed, callee_program_id),
},
instruction_words,
) = read_nssa_inputs::<Instruction>();
let Ok([pre]) = <[_; 1]>::try_from(pre_states) else {
return;
};
let claimed = AccountPostState::new_claimed(pre.account.clone(), Claim::Pda(claim_seed));
let mut pre_for_callee = pre.clone();
pre_for_callee.is_authorized = true;
pre_for_callee.account.program_owner = self_program_id;
let chained_call = ChainedCall {
program_id: callee_program_id,
instruction_data: to_vec(&()).unwrap(),
pre_states: vec![pre_for_callee],
pda_seeds: vec![delegated_seed],
};
ProgramOutput::new(
self_program_id,
caller_program_id,
instruction_words,
vec![pre],
vec![claimed],
)
.with_chained_calls(vec![chained_call])
.write();
}
@@ -37,7 +37,6 @@ fn main() {
instruction_data: chained_instruction,
pre_states,
pda_seeds: vec![],
private_pda_seeds: vec![],
};
ProgramOutput::new(