Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with RM: compliance proof, is_ephemeral, and rseed #254

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion taiga_halo2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ proptest = "1.2"
serde_json = "1.0"

[[bench]]
name = "action_proof"
name = "compliance_proof"
harness = false

[[bench]]
Expand Down
6 changes: 3 additions & 3 deletions taiga_halo2/benches/Perfromance.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Action proof performance
# Compliance proof performance
```
action-proof-prover time: [3.6500 s 3.1445 s 3.7210 s]
action-proof-verifier time: [35.858 ms 36.359 ms 36.873 ms]
compliance-proof-prover time: [3.6500 s 3.1445 s 3.7210 s]
compliance-proof-verifier time: [35.858 ms 36.359 ms 36.873 ms]
```

# VP proof performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ use pasta_curves::{pallas, vesta};
use rand::rngs::OsRng;
use rand::Rng;
use taiga_halo2::{
action::ActionInfo,
compliance::ComplianceInfo,
constant::{
ACTION_CIRCUIT_PARAMS_SIZE, ACTION_PROVING_KEY, ACTION_VERIFYING_KEY, SETUP_PARAMS_MAP,
TAIGA_COMMITMENT_TREE_DEPTH,
COMPLIANCE_CIRCUIT_PARAMS_SIZE, COMPLIANCE_PROVING_KEY, COMPLIANCE_VERIFYING_KEY,
SETUP_PARAMS_MAP, TAIGA_COMMITMENT_TREE_DEPTH,
},
merkle_tree::MerklePath,
nullifier::{Nullifier, NullifierKeyContainer},
resource::{RandomSeed, Resource, ResourceKind},
resource::{Resource, ResourceKind},
};

fn bench_action_proof(name: &str, c: &mut Criterion) {
fn bench_compliance_proof(name: &str, c: &mut Criterion) {
let mut rng = OsRng;
let action_info = {
let compliance_info = {
let input_resource = {
let nonce = Nullifier::from(pallas::Base::random(&mut rng));
let nk = NullifierKeyContainer::from_key(pallas::Base::random(&mut rng));
Expand All @@ -31,16 +31,15 @@ fn bench_action_proof(name: &str, c: &mut Criterion) {
};
let value = pallas::Base::random(&mut rng);
let quantity: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
let rseed = pallas::Base::random(&mut rng);
Resource {
kind,
value,
quantity,
nk_container: nk,
is_merkle_checked: true,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
is_ephemeral: false,
nonce,
rseed,
}
};
let mut output_resource = {
Expand All @@ -53,29 +52,30 @@ fn bench_action_proof(name: &str, c: &mut Criterion) {
};
let value = pallas::Base::random(&mut rng);
let quantity: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
let rseed = pallas::Base::random(&mut rng);
Resource {
kind,
value,
quantity,
nk_container: npk,
is_merkle_checked: true,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
is_ephemeral: false,
nonce,
rseed,
}
};
let input_merkle_path = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH);
ActionInfo::new(
ComplianceInfo::new(
input_resource,
input_merkle_path,
None,
&mut output_resource,
&mut rng,
)
};
let (action, action_circuit) = action_info.build();
let params = SETUP_PARAMS_MAP.get(&ACTION_CIRCUIT_PARAMS_SIZE).unwrap();
let (compliance, compliance_circuit) = compliance_info.build();
let params = SETUP_PARAMS_MAP
.get(&COMPLIANCE_CIRCUIT_PARAMS_SIZE)
.unwrap();

// Prover bench
let prover_name = name.to_string() + "-prover";
Expand All @@ -84,9 +84,9 @@ fn bench_action_proof(name: &str, c: &mut Criterion) {
let mut transcript = Blake2bWrite::<_, vesta::Affine, _>::init(vec![]);
create_proof(
params,
&ACTION_PROVING_KEY,
&[action_circuit.clone()],
&[&[&action.to_instance()]],
&COMPLIANCE_PROVING_KEY,
&[compliance_circuit.clone()],
&[&[&compliance.to_instance()]],
&mut rng,
&mut transcript,
)
Expand All @@ -101,9 +101,9 @@ fn bench_action_proof(name: &str, c: &mut Criterion) {
let mut transcript = Blake2bWrite::<_, vesta::Affine, _>::init(vec![]);
create_proof(
params,
&ACTION_PROVING_KEY,
&[action_circuit],
&[&[&action.to_instance()]],
&COMPLIANCE_PROVING_KEY,
&[compliance_circuit],
&[&[&compliance.to_instance()]],
&mut rng,
&mut transcript,
)
Expand All @@ -118,17 +118,17 @@ fn bench_action_proof(name: &str, c: &mut Criterion) {
let mut transcript = Blake2bRead::init(&proof[..]);
assert!(verify_proof(
params,
&ACTION_VERIFYING_KEY,
&COMPLIANCE_VERIFYING_KEY,
strategy,
&[&[&action.to_instance()]],
&[&[&compliance.to_instance()]],
&mut transcript
)
.is_ok());
})
});
}
fn criterion_benchmark(c: &mut Criterion) {
bench_action_proof("halo2-action-proof", c);
bench_compliance_proof("halo2-compliance-proof", c);
}

criterion_group!(benches, criterion_benchmark);
Expand Down
16 changes: 7 additions & 9 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::{RandomSeed, Resource, ResourceKind},
resource::{Resource, ResourceKind},
};

fn bench_vp_proof(name: &str, c: &mut Criterion) {
Expand All @@ -27,16 +27,15 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
};
let value = pallas::Base::random(&mut rng);
let quantity: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
let rseed = pallas::Base::random(&mut rng);
Resource {
kind,
value,
quantity,
nk_container: nk,
is_merkle_checked: true,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
is_ephemeral: false,
nonce,
rseed,
}
});
let output_resources = input_resources
Expand All @@ -51,16 +50,15 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
};
let value = pallas::Base::random(&mut rng);
let quantity: u64 = rng.gen();
let rseed = RandomSeed::random(&mut rng);
let rseed = pallas::Base::random(&mut rng);
Resource {
kind,
value,
quantity,
nk_container: npk,
is_merkle_checked: true,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
is_ephemeral: false,
nonce,
rseed,
}
})
.collect::<Vec<_>>();
Expand Down
34 changes: 18 additions & 16 deletions taiga_halo2/examples/tx_examples/cascaded_partial_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use halo2_proofs::arithmetic::Field;
use pasta_curves::pallas;
use rand::{CryptoRng, RngCore};
use taiga_halo2::{
action::ActionInfo,
circuit::vp_examples::{
cascade_intent::{create_intent_resource, CascadeIntentValidityPredicateCircuit},
signature_verification::COMPRESSED_TOKEN_AUTH_VK,
token::{Token, TokenAuthorization},
},
compliance::ComplianceInfo,
constant::TAIGA_COMMITMENT_TREE_DEPTH,
merkle_tree::{Anchor, MerklePath},
resource::ResourceValidityPredicates,
Expand All @@ -31,7 +31,7 @@ pub fn create_transaction<R: RngCore + CryptoRng>(mut rng: R) -> Transaction {
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_npk, &bob_auth);
output_token_1.create_random_output_token_resource(&mut rng, 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_npk, &bob_auth);
output_token_2.create_random_output_token_resource(&mut rng, 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_npk, &bob_auth);
output_token_3.create_random_output_token_resource(&mut rng, bob_npk, &bob_auth);

let merkle_path = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH);

Expand All @@ -57,24 +57,24 @@ pub fn create_transaction<R: RngCore + CryptoRng>(mut rng: R) -> Transaction {
// Alice consumes 1 "BTC" and 2 "ETH".
// Alice creates a cascade intent resource and 1 "BTC" to Bob.
let ptx_1 = {
// Create action pairs
let actions = {
let action_1 = ActionInfo::new(
// Create compliance pairs
let compliances = {
let compliance_1 = ComplianceInfo::new(
*input_resource_1.resource(),
merkle_path.clone(),
None,
&mut output_resource_1.resource,
&mut rng,
);

let action_2 = ActionInfo::new(
let compliance_2 = ComplianceInfo::new(
*input_resource_2.resource(),
merkle_path.clone(),
None,
&mut cascade_intent_resource,
&mut rng,
);
vec![action_1, action_2]
vec![compliance_1, compliance_2]
};

// Create VPs
Expand Down Expand Up @@ -127,31 +127,32 @@ pub fn create_transaction<R: RngCore + CryptoRng>(mut rng: R) -> Transaction {
};

// Create shielded partial tx
ShieldedPartialTransaction::build(actions, input_vps, output_vps, vec![], &mut rng).unwrap()
ShieldedPartialTransaction::build(compliances, input_vps, output_vps, vec![], &mut rng)
.unwrap()
};

// The second partial transaction:
// Alice consumes the intent resource and 3 "XAN";
// Alice creates 2 "ETH" and 3 "XAN" to Bob
let ptx_2 = {
// Create action pairs
let actions = {
let action_1 = ActionInfo::new(
// Create compliance pairs
let compliances = {
let compliance_1 = ComplianceInfo::new(
cascade_intent_resource,
merkle_path.clone(),
Some(anchor),
&mut output_resource_2.resource,
&mut rng,
);

let action_2 = ActionInfo::new(
let compliance_2 = ComplianceInfo::new(
*input_resource_3.resource(),
merkle_path,
None,
&mut output_resource_3.resource,
&mut rng,
);
vec![action_1, action_2]
vec![compliance_1, compliance_2]
};

// Create VPs
Expand Down Expand Up @@ -203,7 +204,8 @@ pub fn create_transaction<R: RngCore + CryptoRng>(mut rng: R) -> Transaction {
};

// Create shielded partial tx
ShieldedPartialTransaction::build(actions, input_vps, output_vps, vec![], &mut rng).unwrap()
ShieldedPartialTransaction::build(compliances, input_vps, output_vps, vec![], &mut rng)
.unwrap()
};

// Create the final transaction
Expand Down
Loading
Loading