From ad23872c399f2aba0c6ef2b1086fab25b2bf82f3 Mon Sep 17 00:00:00 2001 From: Song Xuyang Date: Thu, 23 Nov 2023 22:29:36 +0800 Subject: [PATCH] rename nullifier key commitment to nullifier public key --- taiga_halo2/benches/action_proof.rs | 4 +-- taiga_halo2/benches/vp_proof.rs | 4 +-- .../cascaded_partial_transactions.rs | 8 ++--- .../partial_fulfillment_token_swap.rs | 2 +- taiga_halo2/examples/tx_examples/token.rs | 4 +-- .../tx_examples/token_swap_with_intent.rs | 24 +++++++------- .../tx_examples/token_swap_without_intent.rs | 6 ++-- taiga_halo2/src/circuit/integrity.rs | 22 ++++++------- .../src/circuit/resource_commitment.rs | 4 +-- taiga_halo2/src/circuit/vp_circuit.rs | 10 +++--- .../circuit/vp_examples/or_relation_intent.rs | 32 +++++++++---------- .../partial_fulfillment_intent/label.rs | 18 +++++------ .../partial_fulfillment_intent/swap.rs | 14 ++++---- .../src/circuit/vp_examples/receiver_vp.rs | 15 ++++----- taiga_halo2/src/circuit/vp_examples/token.rs | 4 +-- taiga_halo2/src/nullifier.rs | 28 ++++++++-------- taiga_halo2/src/resource.rs | 16 +++++----- taiga_halo2/src/shielded_ptx.rs | 8 ++--- taiga_halo2/src/taiga_api.rs | 6 ++-- 19 files changed, 111 insertions(+), 118 deletions(-) diff --git a/taiga_halo2/benches/action_proof.rs b/taiga_halo2/benches/action_proof.rs index a847a75d..1613177c 100644 --- a/taiga_halo2/benches/action_proof.rs +++ b/taiga_halo2/benches/action_proof.rs @@ -45,7 +45,7 @@ fn bench_action_proof(name: &str, c: &mut Criterion) { }; let mut output_resource = { let nonce = input_resource.get_nf().unwrap(); - let nk_com = NullifierKeyContainer::from_commitment(pallas::Base::random(&mut rng)); + 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); @@ -58,7 +58,7 @@ fn bench_action_proof(name: &str, c: &mut Criterion) { kind, value, quantity, - nk_container: nk_com, + nk_container: npk, is_merkle_checked: true, psi: rseed.get_psi(&nonce), rcm: rseed.get_rcm(&nonce), diff --git a/taiga_halo2/benches/vp_proof.rs b/taiga_halo2/benches/vp_proof.rs index 6be05f63..09bc51c6 100644 --- a/taiga_halo2/benches/vp_proof.rs +++ b/taiga_halo2/benches/vp_proof.rs @@ -43,7 +43,7 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) { .iter() .map(|input| { let nonce = input.get_nf().unwrap(); - let nk_com = NullifierKeyContainer::from_commitment(pallas::Base::random(&mut rng)); + 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); @@ -56,7 +56,7 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) { kind, value, quantity, - nk_container: nk_com, + nk_container: npk, is_merkle_checked: true, psi: rseed.get_psi(&nonce), rcm: rseed.get_rcm(&nonce), diff --git a/taiga_halo2/examples/tx_examples/cascaded_partial_transactions.rs b/taiga_halo2/examples/tx_examples/cascaded_partial_transactions.rs index e8be03b3..37140218 100644 --- a/taiga_halo2/examples/tx_examples/cascaded_partial_transactions.rs +++ b/taiga_halo2/examples/tx_examples/cascaded_partial_transactions.rs @@ -24,14 +24,14 @@ pub fn create_transaction(mut rng: R) -> Transaction { let alice_nk = pallas::Base::random(&mut rng); let bob_auth = TokenAuthorization::random(&mut rng); - let bob_nk_com = pallas::Base::random(&mut rng); + let bob_npk = pallas::Base::random(&mut rng); let input_token_1 = Token::new("btc".to_string(), 1u64); let input_resource_1 = input_token_1.create_random_input_token_resource(&mut rng, alice_nk, &alice_auth); let output_token_1 = Token::new("btc".to_string(), 1u64); let mut output_resource_1 = - output_token_1.create_random_output_token_resource(bob_nk_com, &bob_auth); + output_token_1.create_random_output_token_resource(bob_npk, &bob_auth); let input_token_2 = Token::new("eth".to_string(), 2u64); let input_resource_2 = input_token_2.create_random_input_token_resource(&mut rng, alice_nk, &alice_auth); @@ -43,10 +43,10 @@ pub fn create_transaction(mut rng: R) -> Transaction { create_intent_resource(&mut rng, input_resource_3.commitment().inner(), alice_nk); let output_token_2 = Token::new("eth".to_string(), 2u64); let mut output_resource_2 = - output_token_2.create_random_output_token_resource(bob_nk_com, &bob_auth); + output_token_2.create_random_output_token_resource(bob_npk, &bob_auth); let output_token_3 = Token::new("xan".to_string(), 3u64); let mut output_resource_3 = - output_token_3.create_random_output_token_resource(bob_nk_com, &bob_auth); + output_token_3.create_random_output_token_resource(bob_npk, &bob_auth); let merkle_path = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH); diff --git a/taiga_halo2/examples/tx_examples/partial_fulfillment_token_swap.rs b/taiga_halo2/examples/tx_examples/partial_fulfillment_token_swap.rs index 118969d5..91a89408 100644 --- a/taiga_halo2/examples/tx_examples/partial_fulfillment_token_swap.rs +++ b/taiga_halo2/examples/tx_examples/partial_fulfillment_token_swap.rs @@ -234,7 +234,7 @@ pub fn create_token_swap_transaction(mut rng: R) -> Tran bob_nk.get_nk().unwrap(), returned, bob_auth_pk, - bob_nk.get_commitment(), + bob_nk.get_npk(), ); // Solver/Bob creates the partial transaction to consume the intent resource diff --git a/taiga_halo2/examples/tx_examples/token.rs b/taiga_halo2/examples/tx_examples/token.rs index 6caebe2a..9d9aec9a 100644 --- a/taiga_halo2/examples/tx_examples/token.rs +++ b/taiga_halo2/examples/tx_examples/token.rs @@ -23,7 +23,7 @@ pub fn create_token_swap_ptx( input_nk: pallas::Base, output_token: Token, output_auth_pk: pallas::Point, - output_nk_com: pallas::Base, + output_npk: pallas::Base, ) -> ShieldedPartialTransaction { let input_auth = TokenAuthorization::from_sk_vk(&input_auth_sk, &COMPRESSED_TOKEN_AUTH_VK); @@ -34,7 +34,7 @@ pub fn create_token_swap_ptx( // output resource let output_auth = TokenAuthorization::new(output_auth_pk, *COMPRESSED_TOKEN_AUTH_VK); let mut output_resource = - output_token.create_random_output_token_resource(output_nk_com, &output_auth); + output_token.create_random_output_token_resource(output_npk, &output_auth); // padding the zero resources let padding_input_resource = Resource::random_padding_resource(&mut rng); diff --git a/taiga_halo2/examples/tx_examples/token_swap_with_intent.rs b/taiga_halo2/examples/tx_examples/token_swap_with_intent.rs index b535c415..3a6928ab 100644 --- a/taiga_halo2/examples/tx_examples/token_swap_with_intent.rs +++ b/taiga_halo2/examples/tx_examples/token_swap_with_intent.rs @@ -43,12 +43,12 @@ pub fn create_token_intent_ptx( input_token.create_random_input_token_resource(&mut rng, input_nk, &input_auth); // output intent resource - let input_resource_nk_com = input_resource.get_nk_commitment(); + let input_resource_npk = input_resource.get_npk(); let mut intent_resource = create_intent_resource( &mut rng, &token_1, &token_2, - input_resource_nk_com, + input_resource_npk, input_resource.value, input_nk, ); @@ -102,7 +102,7 @@ pub fn create_token_intent_ptx( output_resources, token_1, token_2, - receiver_nk_com: input_resource_nk_com, + receiver_npk: input_resource_npk, receiver_value: input_resource.value, }; @@ -133,7 +133,7 @@ pub fn create_token_intent_ptx( let ptx = ShieldedPartialTransaction::build(actions, input_vps, output_vps, vec![], &mut rng) .unwrap(); - (ptx, input_nk, input_resource_nk_com, input_resource.value) + (ptx, input_nk, input_resource_npk, input_resource.value) } #[allow(clippy::too_many_arguments)] @@ -142,7 +142,7 @@ pub fn consume_token_intent_ptx( token_1: Token, token_2: Token, input_nk: pallas::Base, - receiver_nk_com: pallas::Base, + receiver_npk: pallas::Base, receiver_value: pallas::Base, output_token: Token, output_auth_pk: pallas::Point, @@ -152,7 +152,7 @@ pub fn consume_token_intent_ptx( &mut rng, &token_1, &token_2, - receiver_nk_com, + receiver_npk, receiver_value, input_nk, ); @@ -160,9 +160,9 @@ pub fn consume_token_intent_ptx( // output resource let input_resource_nf = intent_resource.get_nf().unwrap(); let output_auth = TokenAuthorization::new(output_auth_pk, *COMPRESSED_TOKEN_AUTH_VK); - let output_nk_com = NullifierKeyContainer::from_key(input_nk).get_commitment(); + let output_npk = NullifierKeyContainer::from_key(input_nk).get_npk(); let mut output_resource = - output_token.create_random_output_token_resource(output_nk_com, &output_auth); + output_token.create_random_output_token_resource(output_npk, &output_auth); // padding the zero resources let padding_input_resource = Resource::random_padding_resource(&mut rng); @@ -205,7 +205,7 @@ pub fn consume_token_intent_ptx( output_resources, token_1, token_2, - receiver_nk_com, + receiver_npk, receiver_value, }; @@ -254,7 +254,7 @@ pub fn create_token_swap_intent_transaction(mut rng: R) let token_1 = Token::new("dolphin".to_string(), 1u64); let token_2 = Token::new("monkey".to_string(), 2u64); let btc_token = Token::new("btc".to_string(), 5u64); - let (alice_ptx, intent_nk, receiver_nk_com, receiver_value) = create_token_intent_ptx( + let (alice_ptx, intent_nk, receiver_npk, receiver_value) = create_token_intent_ptx( &mut rng, token_1.clone(), token_2.clone(), @@ -275,7 +275,7 @@ pub fn create_token_swap_intent_transaction(mut rng: R) bob_nk.get_nk().unwrap(), btc_token, bob_auth_pk, - bob_nk.get_commitment(), + bob_nk.get_npk(), ); // Solver/Bob creates the partial transaction to consume the intent resource @@ -285,7 +285,7 @@ pub fn create_token_swap_intent_transaction(mut rng: R) token_1.clone(), token_2, intent_nk, - receiver_nk_com, + receiver_npk, receiver_value, token_1, alice_auth_pk, diff --git a/taiga_halo2/examples/tx_examples/token_swap_without_intent.rs b/taiga_halo2/examples/tx_examples/token_swap_without_intent.rs index e78f3843..39d0a8be 100644 --- a/taiga_halo2/examples/tx_examples/token_swap_without_intent.rs +++ b/taiga_halo2/examples/tx_examples/token_swap_without_intent.rs @@ -33,7 +33,7 @@ pub fn create_token_swap_transaction(mut rng: R) -> Tran alice_nk.get_nk().unwrap(), eth_token.clone(), alice_auth_pk, - alice_nk.get_commitment(), + alice_nk.get_npk(), ); // Bob creates the partial transaction @@ -48,7 +48,7 @@ pub fn create_token_swap_transaction(mut rng: R) -> Tran bob_nk.get_nk().unwrap(), xan_token.clone(), bob_auth_pk, - bob_nk.get_commitment(), + bob_nk.get_npk(), ); // Carol creates the partial transaction @@ -63,7 +63,7 @@ pub fn create_token_swap_transaction(mut rng: R) -> Tran carol_nk.get_nk().unwrap(), btc_token, carol_auth_pk, - carol_nk.get_commitment(), + carol_nk.get_npk(), ); // Solver creates the final transaction diff --git a/taiga_halo2/src/circuit/integrity.rs b/taiga_halo2/src/circuit/integrity.rs index 9eb1552e..27ea9b5c 100644 --- a/taiga_halo2/src/circuit/integrity.rs +++ b/taiga_halo2/src/circuit/integrity.rs @@ -62,10 +62,10 @@ pub fn check_input_resource( pallas::Base::zero(), )?; - // nk_com = Com_r(nk, zero) - let nk_com = poseidon_hash_gadget( + // npk = Com_r(nk, zero) + let npk = poseidon_hash_gadget( resource_commit_chip.get_poseidon_config(), - layouter.namespace(|| "nk_com encoding"), + layouter.namespace(|| "npk encoding"), [nk_var.clone(), zero_constant], )?; @@ -133,7 +133,7 @@ pub fn check_input_resource( logic.clone(), label.clone(), value.clone(), - nk_com.clone(), + npk.clone(), nonce.clone(), psi.clone(), quantity.clone(), @@ -161,7 +161,7 @@ pub fn check_input_resource( is_merkle_checked, value, nonce, - nk_com, + npk, psi, rcm, }; @@ -183,11 +183,11 @@ pub fn check_output_resource( old_nf: AssignedCell, cm_row_idx: usize, ) -> Result { - // Witness nk_com - let nk_com = assign_free_advice( - layouter.namespace(|| "witness nk_com"), + // Witness npk + let npk = assign_free_advice( + layouter.namespace(|| "witness npk"), advices[0], - Value::known(output_resource.get_nk_commitment()), + Value::known(output_resource.get_npk()), )?; // Witness value @@ -247,7 +247,7 @@ pub fn check_output_resource( logic.clone(), label.clone(), value.clone(), - nk_com.clone(), + npk.clone(), old_nf.clone(), psi.clone(), quantity.clone(), @@ -265,7 +265,7 @@ pub fn check_output_resource( is_merkle_checked, value, nonce: old_nf, - nk_com, + npk, psi, rcm, }; diff --git a/taiga_halo2/src/circuit/resource_commitment.rs b/taiga_halo2/src/circuit/resource_commitment.rs index 8398ce25..439a7251 100644 --- a/taiga_halo2/src/circuit/resource_commitment.rs +++ b/taiga_halo2/src/circuit/resource_commitment.rs @@ -146,7 +146,7 @@ pub fn resource_commit( app_vp: AssignedCell, label: AssignedCell, value: AssignedCell, - nk_com: AssignedCell, + npk: AssignedCell, nonce: AssignedCell, psi: AssignedCell, quantity: AssignedCell, @@ -164,7 +164,7 @@ pub fn resource_commit( app_vp, label, value, - nk_com, + npk, nonce, psi, compose_is_merkle_checked_and_quantity, diff --git a/taiga_halo2/src/circuit/vp_circuit.rs b/taiga_halo2/src/circuit/vp_circuit.rs index a6cf240c..566e2019 100644 --- a/taiga_halo2/src/circuit/vp_circuit.rs +++ b/taiga_halo2/src/circuit/vp_circuit.rs @@ -574,7 +574,7 @@ pub struct ResourceVariables { pub is_merkle_checked: AssignedCell, pub value: AssignedCell, pub nonce: AssignedCell, - pub nk_com: AssignedCell, + pub npk: AssignedCell, pub psi: AssignedCell, pub rcm: AssignedCell, } @@ -701,12 +701,10 @@ impl BasicValidityPredicateVariables { ) } - pub fn get_nk_com_searchable_pairs( - &self, - ) -> [ResourceSearchableVariablePair; NUM_RESOURCE * 2] { + pub fn get_npk_searchable_pairs(&self) -> [ResourceSearchableVariablePair; NUM_RESOURCE * 2] { self.get_variable_searchable_pairs( - |variables| variables.resource_variables.nk_com.clone(), - |variables| variables.resource_variables.nk_com.clone(), + |variables| variables.resource_variables.npk.clone(), + |variables| variables.resource_variables.npk.clone(), ) } diff --git a/taiga_halo2/src/circuit/vp_examples/or_relation_intent.rs b/taiga_halo2/src/circuit/vp_examples/or_relation_intent.rs index 4713442c..ec4ada54 100644 --- a/taiga_halo2/src/circuit/vp_examples/or_relation_intent.rs +++ b/taiga_halo2/src/circuit/vp_examples/or_relation_intent.rs @@ -49,7 +49,7 @@ pub struct OrRelationIntentValidityPredicateCircuit { pub output_resources: [Resource; NUM_RESOURCE], pub token_1: Token, pub token_2: Token, - pub receiver_nk_com: pallas::Base, + pub receiver_npk: pallas::Base, pub receiver_value: pallas::Base, } @@ -57,7 +57,7 @@ impl OrRelationIntentValidityPredicateCircuit { pub fn encode_label( token_1: &Token, token_2: &Token, - receiver_nk_com: pallas::Base, + receiver_npk: pallas::Base, receiver_value: pallas::Base, ) -> pallas::Base { let token_property_1 = token_1.encode_name(); @@ -70,7 +70,7 @@ impl OrRelationIntentValidityPredicateCircuit { token_property_2, token_quantity_2, TOKEN_VK.get_compressed(), - receiver_nk_com, + receiver_npk, receiver_value, ]) } @@ -123,10 +123,10 @@ impl ValidityPredicateCircuit for OrRelationIntentValidityPredicateCircuit { Value::known(self.token_2.encode_quantity()), )?; - let receiver_nk_com = assign_free_advice( - layouter.namespace(|| "witness receiver nk_com"), + let receiver_npk = assign_free_advice( + layouter.namespace(|| "witness receiver npk"), config.advices[0], - Value::known(self.receiver_nk_com), + Value::known(self.receiver_npk), )?; let receiver_value = assign_free_advice( @@ -145,7 +145,7 @@ impl ValidityPredicateCircuit for OrRelationIntentValidityPredicateCircuit { token_property_2.clone(), token_quantity_2.clone(), token_vp_vk.clone(), - receiver_nk_com.clone(), + receiver_npk.clone(), receiver_value.clone(), ], )?; @@ -180,16 +180,16 @@ impl ValidityPredicateCircuit for OrRelationIntentValidityPredicateCircuit { }, )?; - // check nk_com + // check npk layouter.assign_region( - || "conditional equal: check nk_com", + || "conditional equal: check npk", |mut region| { config.conditional_equal_config.assign_region( &is_input_resource, - &receiver_nk_com, + &receiver_npk, &basic_variables.output_resource_variables[0] .resource_variables - .nk_com, + .npk, 0, &mut region, ) @@ -280,14 +280,14 @@ pub fn create_intent_resource( mut rng: R, token_1: &Token, token_2: &Token, - receiver_nk_com: pallas::Base, + receiver_npk: pallas::Base, receiver_value: pallas::Base, nk: pallas::Base, ) -> Resource { let label = OrRelationIntentValidityPredicateCircuit::encode_label( token_1, token_2, - receiver_nk_com, + receiver_npk, receiver_value, ); let rseed = RandomSeed::random(&mut rng); @@ -324,12 +324,12 @@ fn test_halo2_or_relation_intent_vp_circuit() { output_resources[0].quantity = token_1.quantity(); let nk = pallas::Base::random(&mut rng); - let nk_com = output_resources[0].get_nk_commitment(); + let npk = output_resources[0].get_npk(); let intent_resource = create_intent_resource( &mut rng, &token_1, &token_2, - nk_com, + npk, output_resources[0].value, nk, ); @@ -341,7 +341,7 @@ fn test_halo2_or_relation_intent_vp_circuit() { output_resources, token_1, token_2, - receiver_nk_com: nk_com, + receiver_npk: npk, receiver_value: output_resources[0].value, } }; diff --git a/taiga_halo2/src/circuit/vp_examples/partial_fulfillment_intent/label.rs b/taiga_halo2/src/circuit/vp_examples/partial_fulfillment_intent/label.rs index 9b0d29e4..785c4330 100644 --- a/taiga_halo2/src/circuit/vp_examples/partial_fulfillment_intent/label.rs +++ b/taiga_halo2/src/circuit/vp_examples/partial_fulfillment_intent/label.rs @@ -21,7 +21,7 @@ pub struct PartialFulfillmentIntentLabel { pub sold_token_quantity: AssignedCell, pub bought_token: AssignedCell, pub bought_token_quantity: AssignedCell, - pub receiver_nk_com: AssignedCell, + pub receiver_npk: AssignedCell, pub receiver_value: AssignedCell, } @@ -41,7 +41,7 @@ impl PartialFulfillmentIntentLabel { self.bought_token.clone(), self.bought_token_quantity.clone(), self.token_vp_vk.clone(), - self.receiver_nk_com.clone(), + self.receiver_npk.clone(), self.receiver_value.clone(), ], ) @@ -85,16 +85,16 @@ impl PartialFulfillmentIntentLabel { }, )?; - // check nk_com + // check npk layouter.assign_region( - || "conditional equal: check bought token nk_com", + || "conditional equal: check bought token npk", |mut region| { config.assign_region( is_input_resource, - &self.receiver_nk_com, + &self.receiver_npk, &basic_variables.output_resource_variables[0] .resource_variables - .nk_com, + .npk, 0, &mut region, ) @@ -237,14 +237,14 @@ impl PartialFulfillmentIntentLabel { )?; layouter.assign_region( - || "conditional equal: check returned token nk_com", + || "conditional equal: check returned token npk", |mut region| { config.assign_region( &is_partial_fulfillment, - &self.receiver_nk_com, + &self.receiver_npk, &basic_variables.output_resource_variables[1] .resource_variables - .nk_com, + .npk, 0, &mut region, ) diff --git a/taiga_halo2/src/circuit/vp_examples/partial_fulfillment_intent/swap.rs b/taiga_halo2/src/circuit/vp_examples/partial_fulfillment_intent/swap.rs index 13c17c3a..d424677b 100644 --- a/taiga_halo2/src/circuit/vp_examples/partial_fulfillment_intent/swap.rs +++ b/taiga_halo2/src/circuit/vp_examples/partial_fulfillment_intent/swap.rs @@ -56,7 +56,7 @@ impl Swap { assert_eq!(offer.quantity() % ratio, 0); let offer_resource = offer.create_random_output_token_resource( - self.sell.resource().nk_container.get_commitment(), + self.sell.resource().nk_container.get_npk(), &self.auth, ); @@ -71,7 +71,7 @@ impl Swap { ); *returned_token .create_random_output_token_resource( - self.sell.resource().nk_container.get_commitment(), + self.sell.resource().nk_container.get_npk(), &self.auth, ) .resource() @@ -93,7 +93,7 @@ impl Swap { self.buy.encode_quantity(), // Assuming the sold_token and bought_token have the same TOKEN_VK TOKEN_VK.get_compressed(), - self.sell.resource().get_nk_commitment(), + self.sell.resource().get_npk(), self.sell.resource().value, ]) } @@ -149,10 +149,10 @@ impl Swap { Value::known(self.buy.encode_quantity()), )?; - let receiver_nk_com = assign_free_advice( - layouter.namespace(|| "witness receiver nk_com"), + let receiver_npk = assign_free_advice( + layouter.namespace(|| "witness receiver npk"), column, - Value::known(self.sell.resource().get_nk_commitment()), + Value::known(self.sell.resource().get_npk()), )?; let receiver_value = assign_free_advice( @@ -167,7 +167,7 @@ impl Swap { sold_token_quantity, bought_token, bought_token_quantity, - receiver_nk_com, + receiver_npk, receiver_value, }) } diff --git a/taiga_halo2/src/circuit/vp_examples/receiver_vp.rs b/taiga_halo2/src/circuit/vp_examples/receiver_vp.rs index 40dee2ef..433e6d74 100644 --- a/taiga_halo2/src/circuit/vp_examples/receiver_vp.rs +++ b/taiga_halo2/src/circuit/vp_examples/receiver_vp.rs @@ -165,11 +165,11 @@ impl ValidityPredicateCircuit for ReceiverValidityPredicateCircuit { &basic_variables.get_nonce_searchable_pairs(), )?; - let nk_com = get_owned_resource_variable( + let npk = get_owned_resource_variable( config.get_owned_resource_variable_config, - layouter.namespace(|| "get owned resource nk_com"), + layouter.namespace(|| "get owned resource npk"), &owned_resource_id, - &basic_variables.get_nk_com_searchable_pairs(), + &basic_variables.get_npk_searchable_pairs(), )?; let psi = get_owned_resource_variable( @@ -186,7 +186,7 @@ impl ValidityPredicateCircuit for ReceiverValidityPredicateCircuit { &basic_variables.get_rcm_searchable_pairs(), )?; - let mut message = vec![logic, label, value, quantity, nonce, nk_com, psi, rcm]; + let mut message = vec![logic, label, value, quantity, nonce, npk, psi, rcm]; let add_chip = AddChip::::construct(config.add_config.clone(), ()); @@ -248,7 +248,7 @@ impl ValidityPredicateCircuit for ReceiverValidityPredicateCircuit { target_resource.value, pallas::Base::from(target_resource.quantity), target_resource.nonce.inner(), - target_resource.get_nk_commitment(), + target_resource.get_npk(), target_resource.psi, target_resource.rcm, ]; @@ -331,10 +331,7 @@ fn test_halo2_receiver_vp_circuit() { pallas::Base::from(circuit.output_resources[0].quantity) ); assert_eq!(de_cipher[4], circuit.output_resources[0].nonce.inner()); - assert_eq!( - de_cipher[5], - circuit.output_resources[0].get_nk_commitment() - ); + assert_eq!(de_cipher[5], circuit.output_resources[0].get_npk()); assert_eq!(de_cipher[6], circuit.output_resources[0].get_psi()); assert_eq!(de_cipher[7], circuit.output_resources[0].get_rcm()); } diff --git a/taiga_halo2/src/circuit/vp_examples/token.rs b/taiga_halo2/src/circuit/vp_examples/token.rs index f6bc6f47..628c76df 100644 --- a/taiga_halo2/src/circuit/vp_examples/token.rs +++ b/taiga_halo2/src/circuit/vp_examples/token.rs @@ -121,7 +121,7 @@ impl Token { pub fn create_random_output_token_resource( &self, - nk_com: pallas::Base, + npk: pallas::Base, auth: &TokenAuthorization, ) -> TokenResource { let label = self.encode_name(); @@ -131,7 +131,7 @@ impl Token { label, value, self.quantity(), - nk_com, + npk, true, ); diff --git a/taiga_halo2/src/nullifier.rs b/taiga_halo2/src/nullifier.rs index 319c4bd4..45366ea3 100644 --- a/taiga_halo2/src/nullifier.rs +++ b/taiga_halo2/src/nullifier.rs @@ -29,8 +29,8 @@ pub struct Nullifier(pallas::Base); #[cfg_attr(feature = "nif", derive(NifTaggedEnum))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum NullifierKeyContainer { - // The NullifierKeyContainer::Commitment is the commitment of NullifierKeyContainer::Key `nk_com = Commitment(nk, 0)` - Commitment(pallas::Base), + // The NullifierKeyContainer::PublicKey is the commitment of NullifierKeyContainer::Key `npk = Commitment(nk, 0)` + PublicKey(pallas::Base), Key(pallas::Base), } @@ -43,7 +43,7 @@ impl Nullifier { cm: &ResourceCommitment, ) -> Option { match nk { - NullifierKeyContainer::Commitment(_) => None, + NullifierKeyContainer::PublicKey(_) => None, NullifierKeyContainer::Key(key) => { let nf = Nullifier(poseidon_hash_n([*key, *nonce, *psi, cm.inner()])); Some(nf) @@ -111,8 +111,8 @@ impl NullifierKeyContainer { NullifierKeyContainer::Key(pallas::Base::random(&mut rng)) } - pub fn random_commitment(mut rng: R) -> Self { - NullifierKeyContainer::Commitment(pallas::Base::random(&mut rng)) + pub fn random_npk(mut rng: R) -> Self { + NullifierKeyContainer::PublicKey(pallas::Base::random(&mut rng)) } /// Creates an NullifierKeyContainer::Key. @@ -120,9 +120,9 @@ impl NullifierKeyContainer { NullifierKeyContainer::Key(key) } - /// Creates a NullifierKeyContainer::Commitment. - pub fn from_commitment(cm: pallas::Base) -> Self { - NullifierKeyContainer::Commitment(cm) + /// Creates a NullifierKeyContainer::PublicKey. + pub fn from_npk(cm: pallas::Base) -> Self { + NullifierKeyContainer::PublicKey(cm) } pub fn get_nk(&self) -> Option { @@ -132,9 +132,9 @@ impl NullifierKeyContainer { } } - pub fn get_commitment(&self) -> pallas::Base { + pub fn get_npk(&self) -> pallas::Base { match self { - NullifierKeyContainer::Commitment(v) => *v, + NullifierKeyContainer::PublicKey(v) => *v, NullifierKeyContainer::Key(key) => { // Commitment(nk, zero), use poseidon hash as Commitment. prf_nf(*key, pallas::Base::zero()) @@ -144,10 +144,8 @@ impl NullifierKeyContainer { pub fn to_commitment(&self) -> Self { match self { - NullifierKeyContainer::Commitment(_) => *self, - NullifierKeyContainer::Key(_) => { - NullifierKeyContainer::Commitment(self.get_commitment()) - } + NullifierKeyContainer::PublicKey(_) => *self, + NullifierKeyContainer::Key(_) => NullifierKeyContainer::PublicKey(self.get_npk()), } } } @@ -176,6 +174,6 @@ pub mod tests { } pub fn random_nullifier_key_commitment(mut rng: R) -> NullifierKeyContainer { - NullifierKeyContainer::from_commitment(pallas::Base::random(&mut rng)) + NullifierKeyContainer::from_npk(pallas::Base::random(&mut rng)) } } diff --git a/taiga_halo2/src/resource.rs b/taiga_halo2/src/resource.rs index 24887999..33034dea 100644 --- a/taiga_halo2/src/resource.rs +++ b/taiga_halo2/src/resource.rs @@ -164,7 +164,7 @@ impl Resource { label: pallas::Base, value: pallas::Base, quantity: u64, - nk_com: pallas::Base, + npk: pallas::Base, is_merkle_checked: bool, ) -> Self { let kind = ResourceKind::new(logic, label); @@ -172,7 +172,7 @@ impl Resource { kind, value, quantity, - nk_container: NullifierKeyContainer::Commitment(nk_com), + nk_container: NullifierKeyContainer::PublicKey(npk), is_merkle_checked, psi: pallas::Base::default(), rcm: pallas::Base::default(), @@ -225,7 +225,7 @@ impl Resource { } } - // resource_commitment = poseidon_hash(logic || label || value || nk_commitment || nonce || psi || is_merkle_checked || quantity || rcm) + // resource_commitment = poseidon_hash(logic || label || value || npk || nonce || psi || is_merkle_checked || quantity || rcm) pub fn commitment(&self) -> ResourceCommitment { let compose_is_merkle_checked_quantity = if self.is_merkle_checked { pallas::Base::from_u128(1 << 64).square() + pallas::Base::from(self.quantity) @@ -236,7 +236,7 @@ impl Resource { self.get_logic(), self.get_label(), self.value, - self.get_nk_commitment(), + self.get_npk(), self.nonce.inner(), self.psi, compose_is_merkle_checked_quantity, @@ -258,8 +258,8 @@ impl Resource { self.nk_container.get_nk() } - pub fn get_nk_commitment(&self) -> pallas::Base { - self.nk_container.get_commitment() + pub fn get_npk(&self) -> pallas::Base { + self.nk_container.get_npk() } pub fn get_kind(&self) -> pallas::Point { @@ -310,7 +310,7 @@ impl BorshSerialize for Resource { writer.write_u64::(self.quantity)?; // Write nk_container match self.nk_container { - NullifierKeyContainer::Commitment(nk) => { + NullifierKeyContainer::PublicKey(nk) => { writer.write_u8(1)?; writer.write_all(&nk.to_repr()) } @@ -363,7 +363,7 @@ impl BorshDeserialize for Resource { let nk = Option::from(pallas::Base::from_repr(nk_container_bytes)) .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "nk not in field"))?; let nk_container = if nk_container_type == 0x01 { - NullifierKeyContainer::from_commitment(nk) + NullifierKeyContainer::from_npk(nk) } else { NullifierKeyContainer::from_key(nk) }; diff --git a/taiga_halo2/src/shielded_ptx.rs b/taiga_halo2/src/shielded_ptx.rs index e833c446..301f0f2e 100644 --- a/taiga_halo2/src/shielded_ptx.rs +++ b/taiga_halo2/src/shielded_ptx.rs @@ -538,14 +538,14 @@ pub mod testing { // If the dynamic VP is not used, set value pallas::Base::zero() by default. let value = pallas::Base::zero(); let quantity = 5000u64; - let nk_com = pallas::Base::random(&mut rng); + let npk = pallas::Base::random(&mut rng); let is_merkle_checked = true; Resource::new_output_resource( compressed_trivial_vp_vk, label, value, quantity, - nk_com, + npk, is_merkle_checked, ) }; @@ -584,14 +584,14 @@ pub mod testing { let label = pallas::Base::one(); let value = pallas::Base::zero(); let quantity = 10u64; - let nk_com = pallas::Base::random(&mut rng); + let npk = pallas::Base::random(&mut rng); let is_merkle_checked = true; Resource::new_output_resource( compressed_trivial_vp_vk, label, value, quantity, - nk_com, + npk, is_merkle_checked, ) }; diff --git a/taiga_halo2/src/taiga_api.rs b/taiga_halo2/src/taiga_api.rs index 1b6e1146..5f32e57e 100644 --- a/taiga_halo2/src/taiga_api.rs +++ b/taiga_halo2/src/taiga_api.rs @@ -57,10 +57,10 @@ pub fn create_output_resource( value: pallas::Base, quantity: u64, // The owner of output resource has the nullifer key and exposes the nullifier_key commitment to output creator. - nk_com: pallas::Base, + npk: pallas::Base, is_merkle_checked: bool, ) -> Resource { - Resource::new_output_resource(logic, label, value, quantity, nk_com, is_merkle_checked) + Resource::new_output_resource(logic, label, value, quantity, npk, is_merkle_checked) } /// Resource borsh serialization @@ -75,7 +75,7 @@ pub fn create_output_resource( /// | value | pallas::Base | 32 | /// | quantity | u64 | 8 | /// | nk_container type | u8 | 1 | -/// | nk_com/nk | pallas::Base | 32 | +/// | npk | pallas::Base | 32 | /// | nonce | pallas::Base | 32 | /// | psi | pallas::Base | 32 | /// | rcm | pallas::Base | 32 |