Skip to content

Commit

Permalink
rename nullifier key commitment to nullifier public key
Browse files Browse the repository at this point in the history
  • Loading branch information
XuyangSong committed Nov 23, 2023
1 parent 060ea08 commit ad23872
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 118 deletions.
4 changes: 2 additions & 2 deletions taiga_halo2/benches/action_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions taiga_halo2/benches/vp_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ pub fn create_transaction<R: RngCore + CryptoRng>(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);
Expand All @@ -43,10 +43,10 @@ pub fn create_transaction<R: RngCore + CryptoRng>(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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub fn create_token_swap_transaction<R: RngCore + CryptoRng>(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
Expand Down
4 changes: 2 additions & 2 deletions taiga_halo2/examples/tx_examples/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn create_token_swap_ptx<R: RngCore>(
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);

Expand All @@ -34,7 +34,7 @@ pub fn create_token_swap_ptx<R: RngCore>(
// 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);
Expand Down
24 changes: 12 additions & 12 deletions taiga_halo2/examples/tx_examples/token_swap_with_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ pub fn create_token_intent_ptx<R: RngCore>(
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,
);
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn create_token_intent_ptx<R: RngCore>(
output_resources,
token_1,
token_2,
receiver_nk_com: input_resource_nk_com,
receiver_npk: input_resource_npk,
receiver_value: input_resource.value,
};

Expand Down Expand Up @@ -133,7 +133,7 @@ pub fn create_token_intent_ptx<R: RngCore>(
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)]
Expand All @@ -142,7 +142,7 @@ pub fn consume_token_intent_ptx<R: RngCore>(
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,
Expand All @@ -152,17 +152,17 @@ pub fn consume_token_intent_ptx<R: RngCore>(
&mut rng,
&token_1,
&token_2,
receiver_nk_com,
receiver_npk,
receiver_value,
input_nk,
);

// 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);
Expand Down Expand Up @@ -205,7 +205,7 @@ pub fn consume_token_intent_ptx<R: RngCore>(
output_resources,
token_1,
token_2,
receiver_nk_com,
receiver_npk,
receiver_value,
};

Expand Down Expand Up @@ -254,7 +254,7 @@ pub fn create_token_swap_intent_transaction<R: RngCore + CryptoRng>(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(),
Expand All @@ -275,7 +275,7 @@ pub fn create_token_swap_intent_transaction<R: RngCore + CryptoRng>(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
Expand All @@ -285,7 +285,7 @@ pub fn create_token_swap_intent_transaction<R: RngCore + CryptoRng>(mut rng: R)
token_1.clone(),
token_2,
intent_nk,
receiver_nk_com,
receiver_npk,
receiver_value,
token_1,
alice_auth_pk,
Expand Down
6 changes: 3 additions & 3 deletions taiga_halo2/examples/tx_examples/token_swap_without_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn create_token_swap_transaction<R: RngCore + CryptoRng>(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
Expand All @@ -48,7 +48,7 @@ pub fn create_token_swap_transaction<R: RngCore + CryptoRng>(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
Expand All @@ -63,7 +63,7 @@ pub fn create_token_swap_transaction<R: RngCore + CryptoRng>(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
Expand Down
22 changes: 11 additions & 11 deletions taiga_halo2/src/circuit/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
)?;

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -161,7 +161,7 @@ pub fn check_input_resource(
is_merkle_checked,
value,
nonce,
nk_com,
npk,
psi,
rcm,
};
Expand All @@ -183,11 +183,11 @@ pub fn check_output_resource(
old_nf: AssignedCell<pallas::Base, pallas::Base>,
cm_row_idx: usize,
) -> Result<OutputResourceVariables, Error> {
// 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
Expand Down Expand Up @@ -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(),
Expand All @@ -265,7 +265,7 @@ pub fn check_output_resource(
is_merkle_checked,
value,
nonce: old_nf,
nk_com,
npk,
psi,
rcm,
};
Expand Down
4 changes: 2 additions & 2 deletions taiga_halo2/src/circuit/resource_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn resource_commit(
app_vp: AssignedCell<pallas::Base, pallas::Base>,
label: AssignedCell<pallas::Base, pallas::Base>,
value: AssignedCell<pallas::Base, pallas::Base>,
nk_com: AssignedCell<pallas::Base, pallas::Base>,
npk: AssignedCell<pallas::Base, pallas::Base>,
nonce: AssignedCell<pallas::Base, pallas::Base>,
psi: AssignedCell<pallas::Base, pallas::Base>,
quantity: AssignedCell<pallas::Base, pallas::Base>,
Expand All @@ -164,7 +164,7 @@ pub fn resource_commit(
app_vp,
label,
value,
nk_com,
npk,
nonce,
psi,
compose_is_merkle_checked_and_quantity,
Expand Down
10 changes: 4 additions & 6 deletions taiga_halo2/src/circuit/vp_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ pub struct ResourceVariables {
pub is_merkle_checked: AssignedCell<pallas::Base, pallas::Base>,
pub value: AssignedCell<pallas::Base, pallas::Base>,
pub nonce: AssignedCell<pallas::Base, pallas::Base>,
pub nk_com: AssignedCell<pallas::Base, pallas::Base>,
pub npk: AssignedCell<pallas::Base, pallas::Base>,
pub psi: AssignedCell<pallas::Base, pallas::Base>,
pub rcm: AssignedCell<pallas::Base, pallas::Base>,
}
Expand Down Expand Up @@ -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(),
)
}

Expand Down
Loading

0 comments on commit ad23872

Please sign in to comment.