Skip to content

Commit

Permalink
rename rho to nonce, NullifierKeyContainer to NullifierPublicKey
Browse files Browse the repository at this point in the history
  • Loading branch information
XuyangSong committed Nov 23, 2023
1 parent e236703 commit 01f2a40
Show file tree
Hide file tree
Showing 22 changed files with 281 additions and 293 deletions.
26 changes: 13 additions & 13 deletions taiga_halo2/benches/action_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ use taiga_halo2::{
TAIGA_COMMITMENT_TREE_DEPTH,
},
merkle_tree::MerklePath,
nullifier::{Nullifier, NullifierKeyContainer},
nullifier::{Nullifier, NullifierPublicKey},
resource::{RandomSeed, Resource, ResourceKind},
};

fn bench_action_proof(name: &str, c: &mut Criterion) {
let mut rng = OsRng;
let action_info = {
let input_resource = {
let rho = Nullifier::from(pallas::Base::random(&mut rng));
let nk = NullifierKeyContainer::from_key(pallas::Base::random(&mut rng));
let nonce = Nullifier::from(pallas::Base::random(&mut rng));
let nk = NullifierPublicKey::from_key(pallas::Base::random(&mut rng));
let kind = {
let logic = pallas::Base::random(&mut rng);
let label = pallas::Base::random(&mut rng);
Expand All @@ -36,16 +36,16 @@ fn bench_action_proof(name: &str, c: &mut Criterion) {
kind,
value,
quantity,
nk_container: nk,
npk: nk,
is_merkle_checked: true,
psi: rseed.get_psi(&rho),
rcm: rseed.get_rcm(&rho),
rho,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
}
};
let mut output_resource = {
let rho = input_resource.get_nf().unwrap();
let nk_com = NullifierKeyContainer::from_commitment(pallas::Base::random(&mut rng));
let nonce = input_resource.get_nf().unwrap();
let npk = NullifierPublicKey::from_pk(pallas::Base::random(&mut rng));
let kind = {
let logic = pallas::Base::random(&mut rng);
let label = pallas::Base::random(&mut rng);
Expand All @@ -58,11 +58,11 @@ fn bench_action_proof(name: &str, c: &mut Criterion) {
kind,
value,
quantity,
nk_container: nk_com,
npk: npk,
is_merkle_checked: true,
psi: rseed.get_psi(&rho),
rcm: rseed.get_rcm(&rho),
rho,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
}
};
let input_merkle_path = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH);
Expand Down
26 changes: 13 additions & 13 deletions taiga_halo2/benches/vp_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rand::Rng;
use taiga_halo2::{
circuit::{vp_circuit::ValidityPredicateCircuit, vp_examples::TrivialValidityPredicateCircuit},
constant::{NUM_RESOURCE, SETUP_PARAMS_MAP, VP_CIRCUIT_PARAMS_SIZE},
nullifier::{Nullifier, NullifierKeyContainer},
nullifier::{Nullifier, NullifierPublicKey},
proof::Proof,
resource::{RandomSeed, Resource, ResourceKind},
};
Expand All @@ -18,8 +18,8 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {

let vp_circuit = {
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 nonce = Nullifier::from(pallas::Base::random(&mut rng));
let nk = NullifierPublicKey::from_key(pallas::Base::random(&mut rng));
let kind = {
let logic = pallas::Base::random(&mut rng);
let label = pallas::Base::random(&mut rng);
Expand All @@ -32,18 +32,18 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
kind,
value,
quantity,
nk_container: nk,
npk: nk,
is_merkle_checked: true,
psi: rseed.get_psi(&rho),
rcm: rseed.get_rcm(&rho),
rho,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
}
});
let output_resources = input_resources
.iter()
.map(|input| {
let rho = input.get_nf().unwrap();
let nk_com = NullifierKeyContainer::from_commitment(pallas::Base::random(&mut rng));
let nonce = input.get_nf().unwrap();
let npk = NullifierPublicKey::from_pk(pallas::Base::random(&mut rng));
let kind = {
let logic = pallas::Base::random(&mut rng);
let label = pallas::Base::random(&mut rng);
Expand All @@ -56,11 +56,11 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
kind,
value,
quantity,
nk_container: nk_com,
npk,
is_merkle_checked: true,
psi: rseed.get_psi(&rho),
rcm: rseed.get_rcm(&rho),
rho,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
}
})
.collect::<Vec<_>>();
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 @@ -17,7 +17,7 @@ use taiga_halo2::{
},
constant::TAIGA_COMMITMENT_TREE_DEPTH,
merkle_tree::{Anchor, MerklePath},
nullifier::NullifierKeyContainer,
nullifier::NullifierPublicKey,
resource::{Resource, ResourceValidityPredicates},
shielded_ptx::ShieldedPartialTransaction,
transaction::{ShieldedPartialTxBundle, Transaction, TransparentPartialTxBundle},
Expand Down Expand Up @@ -223,7 +223,7 @@ pub fn create_token_swap_transaction<R: RngCore + CryptoRng>(mut rng: R) -> Tran
// Bob creates the partial transaction with 1 DOLPHIN input and 5 BTC output
let bob_auth_sk = pallas::Scalar::random(&mut rng);
let bob_auth_pk = generator * bob_auth_sk;
let bob_nk = NullifierKeyContainer::random_key(&mut rng);
let bob_nk = NullifierPublicKey::random_key(&mut rng);
let offer = Token::new("eth".to_string(), 5);
let returned = Token::new("btc".to_string(), 1);

Expand All @@ -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_pk(),
);

// 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
28 changes: 14 additions & 14 deletions taiga_halo2/examples/tx_examples/token_swap_with_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use taiga_halo2::{
},
constant::TAIGA_COMMITMENT_TREE_DEPTH,
merkle_tree::{Anchor, MerklePath},
nullifier::NullifierKeyContainer,
nullifier::NullifierPublicKey,
resource::{Resource, ResourceValidityPredicates},
shielded_ptx::ShieldedPartialTransaction,
transaction::{ShieldedPartialTxBundle, Transaction, TransparentPartialTxBundle},
Expand All @@ -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 = NullifierPublicKey::from_key(input_nk).get_pk();
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 @@ -266,7 +266,7 @@ pub fn create_token_swap_intent_transaction<R: RngCore + CryptoRng>(mut rng: R)
// Bob creates the partial transaction with 1 DOLPHIN input and 5 BTC output
let bob_auth_sk = pallas::Scalar::random(&mut rng);
let bob_auth_pk = generator * bob_auth_sk;
let bob_nk = NullifierKeyContainer::random_key(&mut rng);
let bob_nk = NullifierPublicKey::random_key(&mut rng);

let bob_ptx = create_token_swap_ptx(
&mut rng,
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_pk(),
);

// 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
14 changes: 7 additions & 7 deletions taiga_halo2/examples/tx_examples/token_swap_without_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use pasta_curves::{group::Curve, pallas};
use rand::{CryptoRng, RngCore};
use taiga_halo2::{
circuit::vp_examples::token::Token,
nullifier::NullifierKeyContainer,
nullifier::NullifierPublicKey,
transaction::{ShieldedPartialTxBundle, Transaction, TransparentPartialTxBundle},
};

Expand All @@ -24,7 +24,7 @@ pub fn create_token_swap_transaction<R: RngCore + CryptoRng>(mut rng: R) -> Tran
// Alice creates the partial transaction
let alice_auth_sk = pallas::Scalar::random(&mut rng);
let alice_auth_pk = generator * alice_auth_sk;
let alice_nk = NullifierKeyContainer::random_key(&mut rng);
let alice_nk = NullifierPublicKey::random_key(&mut rng);

let alice_ptx = create_token_swap_ptx(
&mut rng,
Expand All @@ -33,13 +33,13 @@ 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_pk(),
);

// Bob creates the partial transaction
let bob_auth_sk = pallas::Scalar::random(&mut rng);
let bob_auth_pk = generator * bob_auth_sk;
let bob_nk = NullifierKeyContainer::random_key(&mut rng);
let bob_nk = NullifierPublicKey::random_key(&mut rng);

let bob_ptx = create_token_swap_ptx(
&mut rng,
Expand All @@ -48,13 +48,13 @@ 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_pk(),
);

// Carol creates the partial transaction
let carol_auth_sk = pallas::Scalar::random(&mut rng);
let carol_auth_pk = generator * carol_auth_sk;
let carol_nk = NullifierKeyContainer::random_key(&mut rng);
let carol_nk = NullifierPublicKey::random_key(&mut rng);

let carol_ptx = create_token_swap_ptx(
&mut rng,
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_pk(),
);

// Solver creates the final transaction
Expand Down
8 changes: 4 additions & 4 deletions taiga_halo2/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl BorshDeserialize for ActionPublicInputs {
impl ActionInfo {
// The dummy input resource must provide a valid custom_anchor, but a random merkle path
// The normal input resource only needs to provide a valid merkle path. The anchor will be calculated from the resource and path.
// The rho of output_resource will be reset to the nullifier of input_resource
// The nonce of output_resource will be set to the nullifier of input_resource
pub fn new<R: RngCore>(
input_resource: Resource,
input_merkle_path: MerklePath,
Expand All @@ -133,7 +133,7 @@ impl ActionInfo {
None => input_resource.calculate_root(&input_merkle_path),
};

output_resource.set_rho(&input_resource, &mut rng);
output_resource.set_nonce(&input_resource, &mut rng);

Self {
input_resource,
Expand Down Expand Up @@ -180,8 +180,8 @@ impl ActionInfo {
pub fn build(&self) -> (ActionPublicInputs, ActionCircuit) {
let nf = self.get_input_resource_nullifer();
assert_eq!(
nf, self.output_resource.rho,
"The nf of input resource should be equal to the rho of output resource"
nf, self.output_resource.nonce,
"The nf of input resource should be equal to the nonce of output resource"
);

let cm = self.get_output_resource_cm();
Expand Down
Loading

0 comments on commit 01f2a40

Please sign in to comment.