Skip to content

Commit

Permalink
Merge pull request #265 from anoma/xuyang/variable_resources
Browse files Browse the repository at this point in the history
variable resources
  • Loading branch information
XuyangSong authored Sep 14, 2024
2 parents 7630827 + cc4366f commit de70468
Show file tree
Hide file tree
Showing 39 changed files with 1,505 additions and 2,700 deletions.
4 changes: 2 additions & 2 deletions taiga_halo2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ subtle = { version = "2.3", default-features = false }
dyn-clone = "1.0"
reddsa = { git = "https://github.com/heliaxdev/reddsa.git", branch = "taiga" }
vamp-ir = { git = "https://github.com/anoma/vamp-ir.git", rev = "6d401f8a479951727586ef0c44c42edab3139090" }
bincode = "2.0.0-rc.3"
bincode = "1.3.3"
byteorder = "1.4"
num-bigint = "0.4"

Expand Down Expand Up @@ -47,7 +47,7 @@ name = "tx_examples"
required-features = ["examples"]

[features]
default = []
default = ["serde"]
nif = ["dep:rustler", "borsh", "pasta_curves/repr-erlang"]
serde = ["dep:serde", "pasta_curves/serde"]
borsh = ["dep:borsh"]
Expand Down
62 changes: 2 additions & 60 deletions taiga_halo2/benches/resource_logic_proof.rs
Original file line number Diff line number Diff line change
@@ -1,77 +1,19 @@
use criterion::{criterion_group, criterion_main, Criterion};
use halo2_proofs::plonk::{keygen_pk, keygen_vk};

use halo2_proofs::arithmetic::Field;
use pasta_curves::pallas;
use rand::rngs::OsRng;
use rand::Rng;
use taiga_halo2::{
circuit::{
resource_logic_circuit::ResourceLogicCircuit,
resource_logic_examples::TrivialResourceLogicCircuit,
},
constant::{NUM_RESOURCE, RESOURCE_LOGIC_CIRCUIT_PARAMS_SIZE, SETUP_PARAMS_MAP},
nullifier::{Nullifier, NullifierKeyContainer},
constant::{RESOURCE_LOGIC_CIRCUIT_PARAMS_SIZE, SETUP_PARAMS_MAP},
proof::Proof,
resource::{Resource, ResourceKind},
};

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

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));
let kind = {
let logic = pallas::Base::random(&mut rng);
let label = pallas::Base::random(&mut rng);
ResourceKind::new(logic, label)
};
let value = pallas::Base::random(&mut rng);
let quantity: u64 = rng.gen();
let rseed = pallas::Base::random(&mut rng);
Resource {
kind,
value,
quantity,
nk_container: nk,
is_ephemeral: false,
nonce,
rseed,
}
});
let output_resources = input_resources
.iter()
.map(|input| {
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 value = pallas::Base::random(&mut rng);
let quantity: u64 = rng.gen();
let rseed = pallas::Base::random(&mut rng);
Resource {
kind,
value,
quantity,
nk_container: npk,
is_ephemeral: false,
nonce,
rseed,
}
})
.collect::<Vec<_>>();
let owned_resource_id = input_resources[0].get_nf().unwrap().inner();
TrivialResourceLogicCircuit::new(
owned_resource_id,
input_resources,
output_resources.try_into().unwrap(),
)
};
let resource_logic_circuit = TrivialResourceLogicCircuit::default();
let params = SETUP_PARAMS_MAP
.get(&RESOURCE_LOGIC_CIRCUIT_PARAMS_SIZE)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion taiga_halo2/deprecated/simple_sudoku/resource_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl ResourceLogicInfo for SudokuResourceLogic {
public_inputs.into()
}

fn get_owned_resource_id(&self) -> pallas::Base {
fn get_self_resource_id(&self) -> pallas::Base {
pallas::Base::zero()
}
}
Expand Down
18 changes: 9 additions & 9 deletions taiga_halo2/deprecated/taiga_sudoku/app_resource_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Default for SudokuState {

#[derive(Clone, Debug, Default)]
struct SudokuAppResourceLogicCircuit {
owned_resource_id: pallas::Base,
self_resource_id: pallas::Base,
input_resources: [Resource; NUM_RESOURCE],
output_resources: [Resource; NUM_RESOURCE],
// Initial puzzle encoded in a single field
Expand Down Expand Up @@ -453,8 +453,8 @@ impl ResourceLogicInfo for SudokuAppResourceLogicCircuit {
public_inputs.into()
}

fn get_owned_resource_id(&self) -> pallas::Base {
self.owned_resource_id
fn get_self_resource_id(&self) -> pallas::Base {
self.self_resource_id
}
}

Expand All @@ -467,11 +467,11 @@ impl ResourceLogicCircuit for SudokuAppResourceLogicCircuit {
mut layouter: impl Layouter<pallas::Base>,
basic_variables: BasicResourceLogicVariables,
) -> Result<(), Error> {
let owned_resource_id = basic_variables.get_owned_resource_id();
let self_resource_id = basic_variables.get_self_resource_id();
let is_input_resource = get_is_input_resource_flag(
config.get_is_input_resource_flag_config,
layouter.namespace(|| "get is_input_resource_flag"),
&owned_resource_id,
&self_resource_id,
&basic_variables.get_input_resource_nfs(),
&basic_variables.get_output_resource_cms(),
)?;
Expand Down Expand Up @@ -666,9 +666,9 @@ fn test_halo2_sudoku_app_resource_logic_circuit_init() {
output_resources[0].kind.app_data_static =
poseidon_hash(encoded_init_state, current_state.encode());
output_resources[0].quantity = 1u64;
let owned_resource_id = output_resources[0].commitment().inner();
let self_resource_id = output_resources[0].commitment().inner();
SudokuAppResourceLogicCircuit {
owned_resource_id,
self_resource_id,
input_resources,
output_resources: output_resources.try_into().unwrap(),
encoded_init_state,
Expand Down Expand Up @@ -745,7 +745,7 @@ fn test_halo2_sudoku_app_resource_logic_circuit_update() {
output_resources[0].quantity = 1u64;
output_resources[0].kind.app_vk = input_resources[0].kind.app_vk;
SudokuAppResourceLogicCircuit {
owned_resource_id: input_resources[0].get_nf().unwrap().inner(),
self_resource_id: input_resources[0].get_nf().unwrap().inner(),
input_resources,
output_resources: output_resources.try_into().unwrap(),
encoded_init_state,
Expand Down Expand Up @@ -821,7 +821,7 @@ fn halo2_sudoku_app_resource_logic_circuit_final() {
output_resources[0].quantity = 0u64;
output_resources[0].kind.app_vk = input_resources[0].kind.app_vk;
SudokuAppResourceLogicCircuit {
owned_resource_id: input_resources[0].get_nf().unwrap().inner(),
self_resource_id: input_resources[0].get_nf().unwrap().inner(),
input_resources,
output_resources: output_resources.try_into().unwrap(),
encoded_init_state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use taiga_halo2::{

#[derive(Clone, Debug, Default)]
struct DealerIntentResourceLogicCircuit {
owned_resource_id: pallas::Base,
self_resource_id: pallas::Base,
input_resources: [Resource; NUM_RESOURCE],
output_resources: [Resource; NUM_RESOURCE],
encoded_puzzle: pallas::Base,
Expand Down Expand Up @@ -153,8 +153,8 @@ impl ResourceLogicInfo for DealerIntentResourceLogicCircuit {
public_inputs.into()
}

fn get_owned_resource_id(&self) -> pallas::Base {
self.owned_resource_id
fn get_self_resource_id(&self) -> pallas::Base {
self.self_resource_id
}
}

Expand All @@ -167,11 +167,11 @@ impl ResourceLogicCircuit for DealerIntentResourceLogicCircuit {
mut layouter: impl Layouter<pallas::Base>,
basic_variables: BasicResourceLogicVariables,
) -> Result<(), Error> {
let owned_resource_id = basic_variables.get_owned_resource_id();
let self_resource_id = basic_variables.get_self_resource_id();
let is_input_resource = get_is_input_resource_flag(
config.get_is_input_resource_flag_config,
layouter.namespace(|| "get is_input_resource_flag"),
&owned_resource_id,
&self_resource_id,
&basic_variables.get_input_resource_nfs(),
&basic_variables.get_output_resource_cms(),
)?;
Expand All @@ -180,7 +180,7 @@ impl ResourceLogicCircuit for DealerIntentResourceLogicCircuit {
let app_data_static = get_owned_resource_variable(
config.get_owned_resource_variable_config,
layouter.namespace(|| "get owned resource app_static_data"),
&owned_resource_id,
&self_resource_id,
&basic_variables.get_app_data_static_searchable_pairs(),
)?;

Expand Down Expand Up @@ -372,9 +372,9 @@ fn test_halo2_dealer_intent_resource_logic_circuit() {
sudoku_app_vk,
);
let encoded_solution = pallas::Base::random(&mut rng);
let owned_resource_id = output_resources[0].commitment().inner();
let self_resource_id = output_resources[0].commitment().inner();
DealerIntentResourceLogicCircuit {
owned_resource_id,
self_resource_id,
input_resources,
output_resources: output_resources.try_into().unwrap(),
encoded_puzzle,
Expand Down
Loading

0 comments on commit de70468

Please sign in to comment.