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: rename action to compliance #252

Closed
wants to merge 2 commits into from
Closed
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},
};

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 Down Expand Up @@ -66,16 +66,18 @@ fn bench_action_proof(name: &str, c: &mut Criterion) {
}
};
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 +86,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 +103,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 +120,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
28 changes: 15 additions & 13 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 Down Expand Up @@ -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
29 changes: 15 additions & 14 deletions taiga_halo2/examples/tx_examples/partial_fulfillment_token_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use halo2_proofs::arithmetic::Field;
use pasta_curves::{group::Curve, pallas};
use rand::{CryptoRng, RngCore};
use taiga_halo2::{
action::ActionInfo,
circuit::vp_examples::{
partial_fulfillment_intent::{PartialFulfillmentIntentValidityPredicateCircuit, Swap},
signature_verification::COMPRESSED_TOKEN_AUTH_VK,
token::{Token, TokenAuthorization, TokenResource},
},
compliance::ComplianceInfo,
constant::TAIGA_COMMITMENT_TREE_DEPTH,
merkle_tree::{Anchor, MerklePath},
nullifier::NullifierKeyContainer,
Expand All @@ -38,9 +38,9 @@ pub fn create_token_intent_ptx<R: RngCore>(
let mut padding_output_resource = Resource::random_padding_resource(&mut rng);
let merkle_path = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH);

// Create action pairs
let actions = {
let action_1 = ActionInfo::new(
// Create compliance pairs
let compliances = {
let compliance_1 = ComplianceInfo::new(
*swap.sell.resource(),
merkle_path.clone(),
None,
Expand All @@ -50,14 +50,14 @@ pub fn create_token_intent_ptx<R: RngCore>(

// Fetch a valid anchor for dummy resources
let anchor = Anchor::from(pallas::Base::random(&mut rng));
let action_2 = ActionInfo::new(
let compliance_2 = ComplianceInfo::new(
padding_input_resource,
merkle_path,
Some(anchor),
&mut padding_output_resource,
&mut rng,
);
vec![action_1, action_2]
vec![compliance_1, compliance_2]
};

// Create VPs
Expand Down Expand Up @@ -106,8 +106,9 @@ pub fn create_token_intent_ptx<R: RngCore>(
};

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

(ptx, swap, intent_resource)
}
Expand All @@ -131,24 +132,24 @@ pub fn consume_token_intent_ptx<R: RngCore>(
// Fetch a valid anchor for dummy resources
let anchor = Anchor::from(pallas::Base::random(&mut rng));

// Create action pairs
let actions = {
let action_1 = ActionInfo::new(
// Create compliance pairs
let compliances = {
let compliance_1 = ComplianceInfo::new(
intent_resource,
merkle_path.clone(),
Some(anchor),
&mut bought_resource,
&mut rng,
);

let action_2 = ActionInfo::new(
let compliance_2 = ComplianceInfo::new(
padding_input_resource,
merkle_path,
Some(anchor),
&mut returned_resource,
&mut rng,
);
vec![action_1, action_2]
vec![compliance_1, compliance_2]
};

// Create VPs
Expand Down Expand Up @@ -204,7 +205,7 @@ pub fn consume_token_intent_ptx<R: RngCore>(
};

// 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()
}

pub fn create_token_swap_transaction<R: RngCore + CryptoRng>(mut rng: R) -> Transaction {
Expand Down
14 changes: 7 additions & 7 deletions taiga_halo2/examples/tx_examples/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use pasta_curves::pallas;
use rand::RngCore;

use taiga_halo2::{
action::ActionInfo,
circuit::vp_examples::{
signature_verification::COMPRESSED_TOKEN_AUTH_VK,
token::{Token, TokenAuthorization},
},
compliance::ComplianceInfo,
constant::TAIGA_COMMITMENT_TREE_DEPTH,
merkle_tree::{Anchor, MerklePath},
resource::{Resource, ResourceValidityPredicates},
Expand Down Expand Up @@ -43,9 +43,9 @@ pub fn create_token_swap_ptx<R: RngCore>(
// Generate proving info
let merkle_path = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH);

// Create action pairs
let actions = {
let action_1 = ActionInfo::new(
// Create compliance pairs
let compliances = {
let compliance_1 = ComplianceInfo::new(
*input_resource.resource(),
merkle_path.clone(),
None,
Expand All @@ -55,14 +55,14 @@ pub fn create_token_swap_ptx<R: RngCore>(

// Fetch a valid anchor for padding input resources
let anchor = Anchor::from(pallas::Base::random(&mut rng));
let action_2 = ActionInfo::new(
let compliance_2 = ComplianceInfo::new(
padding_input_resource,
merkle_path,
Some(anchor),
&mut padding_output_resource,
&mut rng,
);
vec![action_1, action_2]
vec![compliance_1, compliance_2]
};

// Create VPs
Expand Down Expand Up @@ -107,5 +107,5 @@ pub fn create_token_swap_ptx<R: RngCore>(
};

// 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()
}
Loading
Loading