Skip to content

Commit

Permalink
rename note type to resource kind
Browse files Browse the repository at this point in the history
  • Loading branch information
XuyangSong committed Nov 21, 2023
1 parent b8dfea2 commit fd28a72
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 83 deletions.
14 changes: 7 additions & 7 deletions taiga_halo2/benches/action_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use taiga_halo2::{
},
merkle_tree::MerklePath,
nullifier::{Nullifier, NullifierKeyContainer},
resource::{NoteType, RandomSeed, Resource},
resource::{RandomSeed, Resource, ResourceKind},
};

fn bench_action_proof(name: &str, c: &mut Criterion) {
Expand All @@ -24,16 +24,16 @@ fn bench_action_proof(name: &str, c: &mut Criterion) {
let input_resource = {
let rho = Nullifier::from(pallas::Base::random(&mut rng));
let nk = NullifierKeyContainer::from_key(pallas::Base::random(&mut rng));
let note_type = {
let kind = {
let app_vk = pallas::Base::random(&mut rng);
let app_data_static = pallas::Base::random(&mut rng);
NoteType::new(app_vk, app_data_static)
ResourceKind::new(app_vk, app_data_static)
};
let app_data_dynamic = pallas::Base::random(&mut rng);
let value: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
Resource {
note_type,
kind,
app_data_dynamic,
value,
nk_container: nk,
Expand All @@ -46,16 +46,16 @@ fn bench_action_proof(name: &str, c: &mut Criterion) {
let mut output_resource = {
let rho = input_resource.get_nf().unwrap();
let nk_com = NullifierKeyContainer::from_commitment(pallas::Base::random(&mut rng));
let note_type = {
let kind = {
let app_vk = pallas::Base::random(&mut rng);
let app_data_static = pallas::Base::random(&mut rng);
NoteType::new(app_vk, app_data_static)
ResourceKind::new(app_vk, app_data_static)
};
let app_data_dynamic = pallas::Base::random(&mut rng);
let value: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
Resource {
note_type,
kind,
app_data_dynamic,
value,
nk_container: nk_com,
Expand Down
14 changes: 7 additions & 7 deletions taiga_halo2/benches/vp_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use taiga_halo2::{
constant::{NUM_RESOURCE, SETUP_PARAMS_MAP, VP_CIRCUIT_PARAMS_SIZE},
nullifier::{Nullifier, NullifierKeyContainer},
proof::Proof,
resource::{NoteType, RandomSeed, Resource},
resource::{RandomSeed, Resource, ResourceKind},
};

fn bench_vp_proof(name: &str, c: &mut Criterion) {
Expand All @@ -20,16 +20,16 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
let input_resources = [(); NUM_RESOURCE].map(|_| {
let rho = Nullifier::from(pallas::Base::random(&mut rng));
let nk = NullifierKeyContainer::from_key(pallas::Base::random(&mut rng));
let note_type = {
let kind = {
let app_vk = pallas::Base::random(&mut rng);
let app_data_static = pallas::Base::random(&mut rng);
NoteType::new(app_vk, app_data_static)
ResourceKind::new(app_vk, app_data_static)
};
let app_data_dynamic = pallas::Base::random(&mut rng);
let value: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
Resource {
note_type,
kind,
app_data_dynamic,
value,
nk_container: nk,
Expand All @@ -44,16 +44,16 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
.map(|input| {
let rho = input.get_nf().unwrap();
let nk_com = NullifierKeyContainer::from_commitment(pallas::Base::random(&mut rng));
let note_type = {
let kind = {
let app_vk = pallas::Base::random(&mut rng);
let app_data_static = pallas::Base::random(&mut rng);
NoteType::new(app_vk, app_data_static)
ResourceKind::new(app_vk, app_data_static)
};
let app_data_dynamic = pallas::Base::random(&mut rng);
let value: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
Resource {
note_type,
kind,
app_data_dynamic,
value,
nk_container: nk_com,
Expand Down
28 changes: 14 additions & 14 deletions taiga_halo2/deprecated/taiga_sudoku/app_vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,23 +597,23 @@ pub mod tests {
use pasta_curves::pallas;
use rand::{Rng, RngCore};
use taiga_halo2::{
resource::{Resource, NoteType, RandomSeed},
resource::{Resource, ResourceKind, RandomSeed},
nullifier::{Nullifier, NullifierKeyContainer},
};

pub fn random_input_resource<R: RngCore>(mut rng: R) -> Resource {
let rho = Nullifier::from(pallas::Base::random(&mut rng));
let nk = NullifierKeyContainer::from_key(pallas::Base::random(&mut rng));
let note_type = {
let kind = {
let app_vk = pallas::Base::random(&mut rng);
let app_data_static = pallas::Base::random(&mut rng);
NoteType::new(app_vk, app_data_static)
ResourceKind::new(app_vk, app_data_static)
};
let app_data_dynamic = pallas::Base::random(&mut rng);
let value: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
Resource {
note_type,
kind,
app_data_dynamic,
value,
nk_container: nk,
Expand All @@ -626,16 +626,16 @@ pub mod tests {

pub fn random_output_resource<R: RngCore>(mut rng: R, rho: Nullifier) -> Resource {
let nk_com = NullifierKeyContainer::from_commitment(pallas::Base::random(&mut rng));
let note_type = {
let kind = {
let app_vk = pallas::Base::random(&mut rng);
let app_data_static = pallas::Base::random(&mut rng);
NoteType::new(app_vk, app_data_static)
ResourceKind::new(app_vk, app_data_static)
};
let app_data_dynamic = pallas::Base::random(&mut rng);
let value: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
Resource {
note_type,
kind,
app_data_dynamic,
value,
nk_container: nk_com,
Expand Down Expand Up @@ -663,7 +663,7 @@ fn test_halo2_sudoku_app_vp_circuit_init() {
let encoded_init_state = SudokuState::default().encode();
let previous_state = SudokuState::default();
let current_state = SudokuState::default();
output_resources[0].note_type.app_data_static =
output_resources[0].kind.app_data_static =
poseidon_hash(encoded_init_state, current_state.encode());
output_resources[0].value = 1u64;
let owned_resource_id = output_resources[0].commitment().inner();
Expand Down Expand Up @@ -737,13 +737,13 @@ fn test_halo2_sudoku_app_vp_circuit_update() {
[6, 0, 7, 4, 3, 5, 1, 9, 8],
],
};
input_resources[0].note_type.app_data_static =
input_resources[0].kind.app_data_static =
poseidon_hash(encoded_init_state, previous_state.encode());
input_resources[0].value = 1u64;
output_resources[0].note_type.app_data_static =
output_resources[0].kind.app_data_static =
poseidon_hash(encoded_init_state, current_state.encode());
output_resources[0].value = 1u64;
output_resources[0].note_type.app_vk = input_resources[0].note_type.app_vk;
output_resources[0].kind.app_vk = input_resources[0].kind.app_vk;
SudokuAppValidityPredicateCircuit {
owned_resource_id: input_resources[0].get_nf().unwrap().inner(),
input_resources,
Expand Down Expand Up @@ -813,13 +813,13 @@ fn halo2_sudoku_app_vp_circuit_final() {
[6, 2, 7, 4, 3, 5, 1, 9, 8],
],
};
input_resources[0].note_type.app_data_static =
input_resources[0].kind.app_data_static =
poseidon_hash(encoded_init_state, previous_state.encode());
input_resources[0].value = 1u64;
output_resources[0].note_type.app_data_static =
output_resources[0].kind.app_data_static =
poseidon_hash(encoded_init_state, current_state.encode());
output_resources[0].value = 0u64;
output_resources[0].note_type.app_vk = input_resources[0].note_type.app_vk;
output_resources[0].kind.app_vk = input_resources[0].kind.app_vk;
SudokuAppValidityPredicateCircuit {
owned_resource_id: input_resources[0].get_nf().unwrap().inner(),
input_resources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ fn test_halo2_dealer_intent_vp_circuit() {
.collect::<Vec<_>>();
let encoded_puzzle = pallas::Base::random(&mut rng);
let sudoku_app_vk = pallas::Base::random(&mut rng);
output_resources[0].note_type.app_data_static =
output_resources[0].kind.app_data_static =
DealerIntentValidityPredicateCircuit::compute_app_data_static(
encoded_puzzle,
sudoku_app_vk,
Expand Down
24 changes: 12 additions & 12 deletions taiga_halo2/src/circuit/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ pub fn check_output_resource(
})
}

pub fn derive_note_type(
pub fn derive_kind(
mut layouter: impl Layouter<pallas::Base>,
hash_to_curve_config: HashToCurveConfig,
ecc_chip: EccChip<TaigaFixedBases>,
Expand All @@ -291,7 +291,7 @@ pub fn derive_note_type(
)?;

// Assign a new `NonIdentityPoint` and constran equal to hash_to_curve point since `Point` doesn't have mul operation
// IndentityPoint is an invalid resource type and it returns an error.
// IndentityPoint is an invalid resource kind and it returns an error.
let non_identity_point = app_vk
.value()
.zip(app_data_static.value())
Expand All @@ -300,11 +300,11 @@ pub fn derive_note_type(
});
let non_identity_point_var = NonIdentityPoint::new(
ecc_chip,
layouter.namespace(|| "non-identity resource type"),
layouter.namespace(|| "non-identity resource kind"),
non_identity_point,
)?;
point.constrain_equal(
layouter.namespace(|| "non-identity resource type"),
layouter.namespace(|| "non-identity resource kind"),
&non_identity_point_var,
)?;
Ok(non_identity_point_var)
Expand All @@ -323,9 +323,9 @@ pub fn compute_value_commitment(
v_output: AssignedCell<pallas::Base, pallas::Base>,
rcv: pallas::Scalar,
) -> Result<Point<pallas::Affine, EccChip<TaigaFixedBases>>, Error> {
// input value point
let note_type_input = derive_note_type(
layouter.namespace(|| "derive input resource type"),
// input value base point
let input_kind = derive_kind(
layouter.namespace(|| "derive input resource kind"),
hash_to_curve_config.clone(),
ecc_chip.clone(),
app_address_input,
Expand All @@ -337,11 +337,11 @@ pub fn compute_value_commitment(
&v_input,
)?;
let (value_point_input, _) =
note_type_input.mul(layouter.namespace(|| "input value point"), v_input_scalar)?;
input_kind.mul(layouter.namespace(|| "input value point"), v_input_scalar)?;

// output value point
let note_type_output = derive_note_type(
layouter.namespace(|| "derive output resource type"),
// output value base point
let output_kind = derive_kind(
layouter.namespace(|| "derive output resource kind"),
hash_to_curve_config,
ecc_chip.clone(),
app_address_output,
Expand All @@ -353,7 +353,7 @@ pub fn compute_value_commitment(
&v_output,
)?;
let (value_point_output, _) =
note_type_output.mul(layouter.namespace(|| "output value point"), v_output_scalar)?;
output_kind.mul(layouter.namespace(|| "output value point"), v_output_scalar)?;

// Get and constrain the negative output value point
let neg_v_point_output = Point::new(
Expand Down
4 changes: 2 additions & 2 deletions taiga_halo2/src/circuit/vp_examples/or_relation_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ fn test_halo2_or_relation_intent_vp_circuit() {
let mut output_resources = [(); NUM_RESOURCE].map(|_| random_resource(&mut rng));
let token_1 = Token::new("token1".to_string(), 1u64);
let token_2 = Token::new("token2".to_string(), 2u64);
output_resources[0].note_type.app_vk = *COMPRESSED_TOKEN_VK;
output_resources[0].note_type.app_data_static = token_1.encode_name();
output_resources[0].kind.app_vk = *COMPRESSED_TOKEN_VK;
output_resources[0].kind.app_data_static = token_1.encode_name();
output_resources[0].value = token_1.value();

let nk = pallas::Base::random(&mut rng);
Expand Down
4 changes: 2 additions & 2 deletions taiga_halo2/src/circuit/vp_examples/receiver_vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ impl ValidityPredicateCircuit for ReceiverValidityPredicateCircuit {
self.get_output_resources()[1]
};
let message = vec![
target_resource.note_type.app_vk,
target_resource.note_type.app_data_static,
target_resource.kind.app_vk,
target_resource.kind.app_data_static,
target_resource.app_data_dynamic,
pallas::Base::from(target_resource.value),
target_resource.rho.inner(),
Expand Down
2 changes: 1 addition & 1 deletion taiga_halo2/src/circuit/vp_examples/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ fn test_halo2_token_vp_circuit() {
let output_resources = [(); NUM_RESOURCE].map(|_| random_resource(&mut rng));
let token_name = TokenName("Token_name".to_string());
let auth = TokenAuthorization::random(&mut rng);
input_resources[0].note_type.app_data_static = token_name.encode();
input_resources[0].kind.app_data_static = token_name.encode();
input_resources[0].app_data_dynamic = auth.to_app_data_dynamic();
TokenValidityPredicateCircuit {
owned_resource_id: input_resources[0].get_nf().unwrap().inner(),
Expand Down
2 changes: 1 addition & 1 deletion taiga_halo2/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub const ACTION_OUTPUT_VP_CM_2_ROW_IDX: usize = 8;

pub const POSEIDON_TO_CURVE_INPUT_LEN: usize = 3;
pub const CURVE_ID: &str = "pallas";
pub const VALUE_BASE_DOMAIN_POSTFIX: &str = "Taiga-NoteType";
pub const VALUE_BASE_DOMAIN_POSTFIX: &str = "Taiga-ResourceKind";

pub const VP_CIRCUIT_PUBLIC_INPUT_NUM: usize = VP_CIRCUIT_MANDATORY_PUBLIC_INPUT_NUM
+ VP_CIRCUIT_CUSTOM_PUBLIC_INPUT_NUM
Expand Down
Loading

0 comments on commit fd28a72

Please sign in to comment.