Skip to content

Commit

Permalink
Merge pull request #264 from anoma/xuyang/resource_logic
Browse files Browse the repository at this point in the history
rename the vp(validity predicate) as resource logic
  • Loading branch information
XuyangSong authored Aug 21, 2024
2 parents 7b60eae + 26da66f commit 7630827
Show file tree
Hide file tree
Showing 43 changed files with 1,728 additions and 1,508 deletions.
2 changes: 1 addition & 1 deletion taiga_halo2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ name = "compliance_proof"
harness = false

[[bench]]
name = "vp_proof"
name = "resource_logic_proof"
harness = false

# [[example]]
Expand Down
6 changes: 3 additions & 3 deletions taiga_halo2/benches/Perfromance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ compliance-proof-prover time: [3.6500 s 3.1445 s 3.7210 s]
compliance-proof-verifier time: [35.858 ms 36.359 ms 36.873 ms]
```

# VP proof performance
# ResourceLogic proof performance
```
vp-proof-prover time: [2.2098 s 2.2328 s 2.2579 s]
vp-proof-verifier time: [34.580 ms 35.075 ms 35.585 ms]
resource-logic-proof-prover time: [2.2098 s 2.2328 s 2.2579 s]
resource-logic-proof-verifier time: [34.580 ms 35.075 ms 35.585 ms]
```

# Verifier proof performance
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ use pasta_curves::pallas;
use rand::rngs::OsRng;
use rand::Rng;
use taiga_halo2::{
circuit::{vp_circuit::ValidityPredicateCircuit, vp_examples::TrivialValidityPredicateCircuit},
constant::{NUM_RESOURCE, SETUP_PARAMS_MAP, VP_CIRCUIT_PARAMS_SIZE},
circuit::{
resource_logic_circuit::ResourceLogicCircuit,
resource_logic_examples::TrivialResourceLogicCircuit,
},
constant::{NUM_RESOURCE, RESOURCE_LOGIC_CIRCUIT_PARAMS_SIZE, SETUP_PARAMS_MAP},
nullifier::{Nullifier, NullifierKeyContainer},
proof::Proof,
resource::{Resource, ResourceKind},
};

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

let vp_circuit = {
let resource_logic_circuit = {
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));
Expand Down Expand Up @@ -63,17 +66,19 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
})
.collect::<Vec<_>>();
let owned_resource_id = input_resources[0].get_nf().unwrap().inner();
TrivialValidityPredicateCircuit::new(
TrivialResourceLogicCircuit::new(
owned_resource_id,
input_resources,
output_resources.try_into().unwrap(),
)
};
let params = SETUP_PARAMS_MAP.get(&VP_CIRCUIT_PARAMS_SIZE).unwrap();
let empty_circuit: TrivialValidityPredicateCircuit = Default::default();
let params = SETUP_PARAMS_MAP
.get(&RESOURCE_LOGIC_CIRCUIT_PARAMS_SIZE)
.unwrap();
let empty_circuit: TrivialResourceLogicCircuit = Default::default();
let vk = keygen_vk(params, &empty_circuit).expect("keygen_vk should not fail");
let pk = keygen_pk(params, vk, &empty_circuit).expect("keygen_pk should not fail");
let public_inputs = vp_circuit.get_public_inputs(&mut rng);
let public_inputs = resource_logic_circuit.get_public_inputs(&mut rng);

// Prover bench
let prover_name = name.to_string() + "-prover";
Expand All @@ -82,7 +87,7 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
Proof::create(
&pk,
&params,
vp_circuit.clone(),
resource_logic_circuit.clone(),
&[public_inputs.inner()],
&mut rng,
)
Expand All @@ -95,7 +100,7 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
let proof = Proof::create(
&pk,
&params,
vp_circuit.clone(),
resource_logic_circuit.clone(),
&[public_inputs.inner()],
&mut rng,
)
Expand All @@ -111,7 +116,7 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
});
}
fn criterion_benchmark(c: &mut Criterion) {
bench_vp_proof("halo2-vp-proof", c);
bench_resource_logic_proof("halo2-resource-logic-proof", c);
}

criterion_group!(benches, criterion_benchmark);
Expand Down
2 changes: 1 addition & 1 deletion taiga_halo2/deprecated/simple_sudoku/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod circuit;
pub mod vp;
pub mod resource_logic;

pub fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,47 @@ extern crate taiga_halo2;
use taiga_halo2::{
circuit::{
resource_circuit::ResourceConfig,
vp_circuit::{
BasicValidityPredicateVariables, VPVerifyingInfo, ValidityPredicateCircuit,
ValidityPredicateConfig, ValidityPredicateInfo, ValidityPredicatePublicInputs,
ValidityPredicateVerifyingInfo,
resource_logic_circuit::{
BasicResourceLogicVariables, ResourceLogicVerifyingInfoTrait, ResourceLogicCircuit,
ResourceLogicConfig, ResourceLogicInfo, ResourceLogicPublicInputs,
ResourceLogicVerifyingInfo,
},
},
constant::{NUM_RESOURCE, SETUP_PARAMS_MAP},
resource::{Resource, RandomSeed},
proof::Proof,
vp_circuit_impl,
vp_vk::ValidityPredicateVerifyingKey,
resource_logic_circuit_impl,
resource_logic_vk::ResourceLogicVerifyingKey,
};

use crate::circuit::{SudokuCircuit, SudokuConfig};
use rand::{rngs::OsRng, RngCore};

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

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

impl ValidityPredicateCircuit for SudokuVP {
impl ResourceLogicCircuit for SudokuResourceLogic {
fn custom_constraints(
&self,
config: ValidityPredicateConfig,
config: ResourceLogicConfig,
layouter: impl Layouter<pallas::Base>,
_basic_variables: BasicValidityPredicateVariables,
_basic_variables: BasicResourceLogicVariables,
) -> Result<(), plonk::Error> {
self.sudoku.synthesize(config.sudoku_config, layouter)
}
}

impl ValidityPredicateInfo for SudokuVP {
impl ResourceLogicInfo for SudokuResourceLogic {
fn get_input_resources(&self) -> &[Resource; NUM_RESOURCE] {
&self.input_resources
}
Expand All @@ -57,9 +57,9 @@ impl ValidityPredicateInfo for SudokuVP {
&self.output_resources
}

fn get_public_inputs(&self, mut rng: impl RngCore) -> ValidityPredicatePublicInputs {
fn get_public_inputs(&self, mut rng: impl RngCore) -> ResourceLogicPublicInputs {
let mut public_inputs = self.get_mandatory_public_inputs();
let padding = ValidityPredicatePublicInputs::get_public_input_padding(
let padding = ResourceLogicPublicInputs::get_public_input_padding(
public_inputs.len(),
&RandomSeed::random(&mut rng),
);
Expand All @@ -72,7 +72,7 @@ impl ValidityPredicateInfo for SudokuVP {
}
}

impl SudokuVP {
impl SudokuResourceLogic {
pub fn new(
sudoku: SudokuCircuit,
input_resources: [Resource; NUM_RESOURCE],
Expand All @@ -86,15 +86,15 @@ impl SudokuVP {
}
}

vp_circuit_impl!(SudokuVP);
resource_logic_circuit_impl!(SudokuResourceLogic);

#[cfg(test)]
mod tests {
use taiga_halo2::{
constant::NUM_RESOURCE,
resource::{Resource, RandomSeed},
nullifier::{Nullifier, NullifierKeyContainer},
vp_vk::ValidityPredicateVerifyingKey,
resource_logic_vk::ResourceLogicVerifyingKey,
};

use ff::Field;
Expand All @@ -103,10 +103,10 @@ mod tests {

use halo2_proofs::{plonk, poly::commitment::Params};

use crate::{circuit::SudokuCircuit, vp::SudokuVP};
use crate::{circuit::SudokuCircuit, resource_logic::SudokuResourceLogic};

#[test]
fn test_vp() {
fn test_resource_logic() {
let mut rng = OsRng;
let input_resources = [(); NUM_RESOURCE].map(|_| Resource::dummy(&mut rng));
let output_resources = [(); NUM_RESOURCE].map(|_| Resource::dummy(&mut rng));
Expand All @@ -129,9 +129,9 @@ mod tests {

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

let mut _vp = SudokuVP::new(sudoku, input_resources, output_resources);
let mut _resource_logic = SudokuResourceLogic::new(sudoku, input_resources, output_resources);

let vp_vk = ValidityPredicateVerifyingKey::from_vk(vk);
let resource_logic_vk = ResourceLogicVerifyingKey::from_vk(vk);

let app_data_static = pallas::Base::zero();
let app_data_dynamic = pallas::Base::zero();
Expand All @@ -141,7 +141,7 @@ mod tests {
let rseed = RandomSeed::random(&mut rng);
let rho = Nullifier::from(pallas::Base::random(&mut rng));
Resource::new(
vp_vk,
resource_logic_vk,
app_data_static,
app_data_dynamic,
quantity,
Expand Down
Loading

0 comments on commit 7630827

Please sign in to comment.