Skip to content

Commit

Permalink
invert the is_ephemeral value
Browse files Browse the repository at this point in the history
  • Loading branch information
XuyangSong committed Nov 29, 2023
1 parent 80cd7d1 commit 1f1f555
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions taiga_halo2/benches/compliance_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn bench_compliance_proof(name: &str, c: &mut Criterion) {
value,
quantity,
nk_container: nk,
is_ephemeral: true,
is_ephemeral: false,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
Expand All @@ -59,7 +59,7 @@ fn bench_compliance_proof(name: &str, c: &mut Criterion) {
value,
quantity,
nk_container: npk,
is_ephemeral: true,
is_ephemeral: false,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
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 @@ -33,7 +33,7 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
value,
quantity,
nk_container: nk,
is_ephemeral: true,
is_ephemeral: false,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
Expand All @@ -57,7 +57,7 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
value,
quantity,
nk_container: npk,
is_ephemeral: true,
is_ephemeral: false,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
Expand Down
9 changes: 5 additions & 4 deletions taiga_halo2/src/circuit/compliance_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use halo2_gadgets::{
use halo2_proofs::{
circuit::{floor_planner, Layouter, Value},
plonk::{
Advice, Circuit, Column, ConstraintSystem, Constraints, Error, Instance, Selector,
TableColumn,
Advice, Circuit, Column, ConstraintSystem, Constraints, Error, Expression, Instance,
Selector, TableColumn,
},
poly::Rotation,
};
Expand Down Expand Up @@ -128,12 +128,13 @@ impl Circuit<pallas::Base> for ComplianceCircuit {
let is_ephemeral_input = meta.query_advice(advices[0], Rotation::cur());
let anchor = meta.query_advice(advices[1], Rotation::cur());
let root = meta.query_advice(advices[2], Rotation::cur());
let constant_one = Expression::Constant(pallas::Base::one());

Constraints::with_selector(
merkle_path_selector,
[(
"is_ephemeral is false, or root = anchor",
is_ephemeral_input * (root - anchor),
"is_ephemeral is true, or root = anchor",
(constant_one - is_ephemeral_input) * (root - anchor),
)],
)
});
Expand Down
2 changes: 1 addition & 1 deletion taiga_halo2/src/circuit/vp_examples/cascade_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn create_intent_resource<R: RngCore>(
1u64,
nk,
nonce,
false,
true,
rseed,
)
}
Expand Down
2 changes: 1 addition & 1 deletion taiga_halo2/src/circuit/vp_examples/or_relation_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ pub fn create_intent_resource<R: RngCore>(
1u64,
nk,
nonce,
false,
true,
rseed,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Swap {
1u64,
self.sell.resource().nk_container.get_nk().unwrap(),
self.sell.resource().get_nf().unwrap(),
false,
true,
rseed,
)
}
Expand Down
12 changes: 6 additions & 6 deletions taiga_halo2/src/circuit/vp_examples/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Token {
self.quantity(),
nk,
nonce,
true,
false,
rseed,
);

Expand All @@ -132,7 +132,7 @@ impl Token {
value,
self.quantity(),
npk,
true,
false,
);

TokenResource {
Expand Down Expand Up @@ -380,14 +380,14 @@ impl ValidityPredicateCircuit for TokenValidityPredicateCircuit {
&owned_resource_id,
&basic_variables.get_is_ephemeral_searchable_pairs(),
)?;
let constant_one = assign_free_constant(
layouter.namespace(|| "one"),
let constant_zero = assign_free_constant(
layouter.namespace(|| "zero"),
config.advices[0],
pallas::Base::one(),
pallas::Base::zero(),
)?;
layouter.assign_region(
|| "check is_ephemeral",
|mut region| region.constrain_equal(is_ephemeral.cell(), constant_one.cell()),
|mut region| region.constrain_equal(is_ephemeral.cell(), constant_zero.cell()),
)?;

// VP Commitment
Expand Down
6 changes: 3 additions & 3 deletions taiga_halo2/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub struct Resource {
pub psi: pallas::Base,
/// rcm is the trapdoor of the resource commitment
pub rcm: pallas::Base,
/// If the is_ephemeral flag is true, the merkle path authorization(membership) of input resource will be checked in ComplianceProof.
/// If the is_ephemeral flag is false, the merkle path authorization(membership) of input resource will be checked in ComplianceProof.
pub is_ephemeral: bool,
}

Expand Down Expand Up @@ -221,7 +221,7 @@ impl Resource {
nonce,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
is_ephemeral: false,
is_ephemeral: true,
}
}

Expand Down Expand Up @@ -579,7 +579,7 @@ pub mod tests {
value: pallas::Base::random(&mut rng),
quantity: rng.gen(),
nk_container: random_nullifier_key(&mut rng),
is_ephemeral: true,
is_ephemeral: false,
psi: rseed.get_psi(&nonce),
rcm: rseed.get_rcm(&nonce),
nonce,
Expand Down
8 changes: 4 additions & 4 deletions taiga_halo2/src/shielded_ptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ pub mod testing {
let quantity = 5000u64;
let nk = pallas::Base::random(&mut rng);
let rseed = RandomSeed::random(&mut rng);
let is_ephemeral = true;
let is_ephemeral = false;
Resource::new_input_resource(
compressed_trivial_vp_vk,
label,
Expand All @@ -543,7 +543,7 @@ pub mod testing {
let value = pallas::Base::zero();
let quantity = 5000u64;
let npk = pallas::Base::random(&mut rng);
let is_ephemeral = true;
let is_ephemeral = false;
Resource::new_output_resource(
compressed_trivial_vp_vk,
label,
Expand Down Expand Up @@ -572,7 +572,7 @@ pub mod testing {
let quantity = 10u64;
let nk = pallas::Base::random(&mut rng);
let rseed = RandomSeed::random(&mut rng);
let is_ephemeral = true;
let is_ephemeral = false;
Resource::new_input_resource(
compressed_trivial_vp_vk,
label,
Expand All @@ -589,7 +589,7 @@ pub mod testing {
let value = pallas::Base::zero();
let quantity = 10u64;
let npk = pallas::Base::random(&mut rng);
let is_ephemeral = true;
let is_ephemeral = false;
Resource::new_output_resource(
compressed_trivial_vp_vk,
label,
Expand Down
2 changes: 1 addition & 1 deletion taiga_halo2/src/taiga_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use borsh::{BorshDeserialize, BorshSerialize};
/// value is the fungible data of the resource
/// nk is the nullifier key
/// nonce guarantees the uniqueness of the resource computable fields
/// is_ephemeral is true for normal resources, false for intent(ephemeral) resources
/// is_ephemeral is false for normal resources, true for intent(ephemeral) resources
///
/// In practice, input resources are fetched and decrypted from blockchain storage.
/// The create_input_resource API is only for test.
Expand Down
2 changes: 1 addition & 1 deletion taiga_halo2/src/transparent_ptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Executable for TransparentPartialTransaction {

fn get_anchors(&self) -> Vec<Anchor> {
// TODO: We have easier way to check the anchor in transparent scenario, but keep consistent with sheilded right now.
// TODO: we can skip the root if the is_ephemeral flag is false?
// TODO: we can skip the root if the is_ephemeral flag is true?
self.compliances
.iter()
.map(|compliance| compliance.calculate_root())
Expand Down

0 comments on commit 1f1f555

Please sign in to comment.