Skip to content

Commit

Permalink
Merge pull request #251 from anoma/xuyang/resource_machine_renames
Browse files Browse the repository at this point in the history
Sync with resource machine
  • Loading branch information
XuyangSong authored Nov 24, 2023
2 parents bbeff78 + ad23872 commit fd9d365
Show file tree
Hide file tree
Showing 51 changed files with 2,995 additions and 2,951 deletions.
66 changes: 33 additions & 33 deletions taiga_halo2/benches/action_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,63 @@ use taiga_halo2::{
TAIGA_COMMITMENT_TREE_DEPTH,
},
merkle_tree::MerklePath,
note::{Note, NoteType, RandomSeed},
nullifier::{Nullifier, NullifierKeyContainer},
resource::{RandomSeed, Resource, ResourceKind},
};

fn bench_action_proof(name: &str, c: &mut Criterion) {
let mut rng = OsRng;
let action_info = {
let input_note = {
let rho = Nullifier::from(pallas::Base::random(&mut rng));
let input_resource = {
let nonce = Nullifier::from(pallas::Base::random(&mut rng));
let nk = NullifierKeyContainer::from_key(pallas::Base::random(&mut rng));
let note_type = {
let app_vk = pallas::Base::random(&mut rng);
let app_data_static = pallas::Base::random(&mut rng);
NoteType::new(app_vk, app_data_static)
let kind = {
let logic = pallas::Base::random(&mut rng);
let label = pallas::Base::random(&mut rng);
ResourceKind::new(logic, label)
};
let app_data_dynamic = pallas::Base::random(&mut rng);
let value: u64 = rng.gen();
let value = pallas::Base::random(&mut rng);
let quantity: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
Note {
note_type,
app_data_dynamic,
Resource {
kind,
value,
quantity,
nk_container: nk,
is_merkle_checked: true,
psi: rseed.get_psi(&rho),
rcm: rseed.get_rcm(&rho),
rho,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
}
};
let mut output_note = {
let rho = input_note.get_nf().unwrap();
let nk_com = NullifierKeyContainer::from_commitment(pallas::Base::random(&mut rng));
let note_type = {
let app_vk = pallas::Base::random(&mut rng);
let app_data_static = pallas::Base::random(&mut rng);
NoteType::new(app_vk, app_data_static)
let mut output_resource = {
let nonce = input_resource.get_nf().unwrap();
let npk = NullifierKeyContainer::from_npk(pallas::Base::random(&mut rng));
let kind = {
let logic = pallas::Base::random(&mut rng);
let label = pallas::Base::random(&mut rng);
ResourceKind::new(logic, label)
};
let app_data_dynamic = pallas::Base::random(&mut rng);
let value: u64 = rng.gen();
let value = pallas::Base::random(&mut rng);
let quantity: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
Note {
note_type,
app_data_dynamic,
Resource {
kind,
value,
nk_container: nk_com,
quantity,
nk_container: npk,
is_merkle_checked: true,
psi: rseed.get_psi(&rho),
rcm: rseed.get_rcm(&rho),
rho,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
}
};
let input_merkle_path = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH);
ActionInfo::new(
input_note,
input_resource,
input_merkle_path,
None,
&mut output_note,
&mut output_resource,
&mut rng,
)
};
Expand Down
72 changes: 36 additions & 36 deletions taiga_halo2/benches/vp_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,68 @@ use rand::rngs::OsRng;
use rand::Rng;
use taiga_halo2::{
circuit::{vp_circuit::ValidityPredicateCircuit, vp_examples::TrivialValidityPredicateCircuit},
constant::{NUM_NOTE, SETUP_PARAMS_MAP, VP_CIRCUIT_PARAMS_SIZE},
note::{Note, NoteType, RandomSeed},
constant::{NUM_RESOURCE, SETUP_PARAMS_MAP, VP_CIRCUIT_PARAMS_SIZE},
nullifier::{Nullifier, NullifierKeyContainer},
proof::Proof,
resource::{RandomSeed, Resource, ResourceKind},
};

fn bench_vp_proof(name: &str, c: &mut Criterion) {
let mut rng = OsRng;

let vp_circuit = {
let input_notes = [(); NUM_NOTE].map(|_| {
let rho = Nullifier::from(pallas::Base::random(&mut rng));
let input_resources = [(); NUM_RESOURCE].map(|_| {
let nonce = Nullifier::from(pallas::Base::random(&mut rng));
let nk = NullifierKeyContainer::from_key(pallas::Base::random(&mut rng));
let note_type = {
let app_vk = pallas::Base::random(&mut rng);
let app_data_static = pallas::Base::random(&mut rng);
NoteType::new(app_vk, app_data_static)
let kind = {
let logic = pallas::Base::random(&mut rng);
let label = pallas::Base::random(&mut rng);
ResourceKind::new(logic, label)
};
let app_data_dynamic = pallas::Base::random(&mut rng);
let value: u64 = rng.gen();
let value = pallas::Base::random(&mut rng);
let quantity: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
Note {
note_type,
app_data_dynamic,
Resource {
kind,
value,
quantity,
nk_container: nk,
is_merkle_checked: true,
psi: rseed.get_psi(&rho),
rcm: rseed.get_rcm(&rho),
rho,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
}
});
let output_notes = input_notes
let output_resources = input_resources
.iter()
.map(|input| {
let rho = input.get_nf().unwrap();
let nk_com = NullifierKeyContainer::from_commitment(pallas::Base::random(&mut rng));
let note_type = {
let app_vk = pallas::Base::random(&mut rng);
let app_data_static = pallas::Base::random(&mut rng);
NoteType::new(app_vk, app_data_static)
let nonce = input.get_nf().unwrap();
let npk = NullifierKeyContainer::from_npk(pallas::Base::random(&mut rng));
let kind = {
let logic = pallas::Base::random(&mut rng);
let label = pallas::Base::random(&mut rng);
ResourceKind::new(logic, label)
};
let app_data_dynamic = pallas::Base::random(&mut rng);
let value: u64 = rng.gen();
let value = pallas::Base::random(&mut rng);
let quantity: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
Note {
note_type,
app_data_dynamic,
Resource {
kind,
value,
nk_container: nk_com,
quantity,
nk_container: npk,
is_merkle_checked: true,
psi: rseed.get_psi(&rho),
rcm: rseed.get_rcm(&rho),
rho,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
}
})
.collect::<Vec<_>>();
let owned_note_pub_id = input_notes[0].get_nf().unwrap().inner();
let owned_resource_id = input_resources[0].get_nf().unwrap().inner();
TrivialValidityPredicateCircuit::new(
owned_note_pub_id,
input_notes,
output_notes.try_into().unwrap(),
owned_resource_id,
input_resources,
output_resources.try_into().unwrap(),
)
};
let params = SETUP_PARAMS_MAP.get(&VP_CIRCUIT_PARAMS_SIZE).unwrap();
Expand Down
46 changes: 23 additions & 23 deletions taiga_halo2/deprecated/simple_sudoku/vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use pasta_curves::pallas;
extern crate taiga_halo2;
use taiga_halo2::{
circuit::{
note_circuit::NoteConfig,
resource_circuit::ResourceConfig,
vp_circuit::{
BasicValidityPredicateVariables, VPVerifyingInfo, ValidityPredicateCircuit,
ValidityPredicateConfig, ValidityPredicateInfo, ValidityPredicatePublicInputs,
ValidityPredicateVerifyingInfo,
},
},
constant::{NUM_NOTE, SETUP_PARAMS_MAP},
note::{Note, RandomSeed},
constant::{NUM_RESOURCE, SETUP_PARAMS_MAP},
resource::{Resource, RandomSeed},
proof::Proof,
vp_circuit_impl,
vp_vk::ValidityPredicateVerifyingKey,
Expand All @@ -26,15 +26,15 @@ use rand::{rngs::OsRng, RngCore};

#[derive(Clone, Debug)]
pub struct SudokuVPConfig {
note_config: NoteConfig,
resource_config: ResourceConfig,
sudoku_config: SudokuConfig,
}

#[derive(Clone, Debug, Default)]
pub struct SudokuVP {
pub sudoku: SudokuCircuit,
input_notes: [Note; NUM_NOTE],
output_notes: [Note; NUM_NOTE],
input_resources: [Resource; NUM_RESOURCE],
output_resources: [Resource; NUM_RESOURCE],
}

impl ValidityPredicateCircuit for SudokuVP {
Expand All @@ -49,12 +49,12 @@ impl ValidityPredicateCircuit for SudokuVP {
}

impl ValidityPredicateInfo for SudokuVP {
fn get_input_notes(&self) -> &[Note; NUM_NOTE] {
&self.input_notes
fn get_input_resources(&self) -> &[Resource; NUM_RESOURCE] {
&self.input_resources
}

fn get_output_notes(&self) -> &[Note; NUM_NOTE] {
&self.output_notes
fn get_output_resources(&self) -> &[Resource; NUM_RESOURCE] {
&self.output_resources
}

fn get_public_inputs(&self, mut rng: impl RngCore) -> ValidityPredicatePublicInputs {
Expand All @@ -67,21 +67,21 @@ impl ValidityPredicateInfo for SudokuVP {
public_inputs.into()
}

fn get_owned_note_pub_id(&self) -> pallas::Base {
fn get_owned_resource_id(&self) -> pallas::Base {
pallas::Base::zero()
}
}

impl SudokuVP {
pub fn new(
sudoku: SudokuCircuit,
input_notes: [Note; NUM_NOTE],
output_notes: [Note; NUM_NOTE],
input_resources: [Resource; NUM_RESOURCE],
output_resources: [Resource; NUM_RESOURCE],
) -> Self {
Self {
sudoku,
input_notes,
output_notes,
input_resources,
output_resources,
}
}
}
Expand All @@ -91,8 +91,8 @@ vp_circuit_impl!(SudokuVP);
#[cfg(test)]
mod tests {
use taiga_halo2::{
constant::NUM_NOTE,
note::{Note, RandomSeed},
constant::NUM_RESOURCE,
resource::{Resource, RandomSeed},
nullifier::{Nullifier, NullifierKeyContainer},
vp_vk::ValidityPredicateVerifyingKey,
};
Expand All @@ -108,8 +108,8 @@ mod tests {
#[test]
fn test_vp() {
let mut rng = OsRng;
let input_notes = [(); NUM_NOTE].map(|_| Note::dummy(&mut rng));
let output_notes = [(); NUM_NOTE].map(|_| Note::dummy(&mut rng));
let input_resources = [(); NUM_RESOURCE].map(|_| Resource::dummy(&mut rng));
let output_resources = [(); NUM_RESOURCE].map(|_| Resource::dummy(&mut rng));

const K: u32 = 13;
let sudoku = SudokuCircuit {
Expand All @@ -129,22 +129,22 @@ mod tests {

let vk = plonk::keygen_vk(&params, &sudoku).unwrap();

let mut _vp = SudokuVP::new(sudoku, input_notes, output_notes);
let mut _vp = SudokuVP::new(sudoku, input_resources, output_resources);

let vp_vk = ValidityPredicateVerifyingKey::from_vk(vk);

let app_data_static = pallas::Base::zero();
let app_data_dynamic = pallas::Base::zero();

let value: u64 = 0;
let quantity: u64 = 0;
let nk = NullifierKeyContainer::random_key(&mut rng);
let rseed = RandomSeed::random(&mut rng);
let rho = Nullifier::from(pallas::Base::random(&mut rng));
Note::new(
Resource::new(
vp_vk,
app_data_static,
app_data_dynamic,
value,
quantity,
nk,
rho,
true,
Expand Down
Loading

0 comments on commit fd9d365

Please sign in to comment.