Skip to content

Commit

Permalink
sinsemilla::merkle.rs: Rename advice column names for clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
therealyingtong committed Jun 6, 2021
1 parent 78e4d8a commit 8602455
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions src/circuit/gadget/sinsemilla/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ pub struct MerkleConfig<
const K: usize,
const MAX_WORDS: usize,
> {
a: Column<Advice>,
b: Column<Advice>,
c: Column<Advice>,
left: Column<Advice>,
a_a0: Column<Advice>,
b_a1: Column<Advice>,
c_b0: Column<Advice>,
left_b1: Column<Advice>,
right: Column<Advice>,
l_star_plus1: Column<Fixed>,
perm: Permutation,
Expand Down Expand Up @@ -111,10 +111,10 @@ impl<C: CurveAffine, const PATH_LENGTH: usize, const K: usize, const MAX_WORDS:
sinsemilla_config.perm.clone(),
);

let a = advices[0];
let b = advices[1];
let c = advices[2];
let left = advices[3];
let a_a0 = advices[0];
let b_a1 = advices[1];
let c_b0 = advices[2];
let left_b1 = advices[3];
let right = advices[4];

let l_star_plus1 = meta.fixed_column();
Expand All @@ -126,16 +126,16 @@ impl<C: CurveAffine, const PATH_LENGTH: usize, const K: usize, const MAX_WORDS:
// `b = b_0||b_1` = (bits 240..=254 of `left`) || (bits 0..=234 of `right`)
// `c = bits 235..=254 of `right`
meta.create_gate("Merkle path validity check", |meta| {
let a_whole = meta.query_advice(a, Rotation::cur());
let b_whole = meta.query_advice(b, Rotation::cur());
let c_whole = meta.query_advice(c, Rotation::cur());
let left_node = meta.query_advice(left, Rotation::cur());
let a_whole = meta.query_advice(a_a0, Rotation::cur());
let b_whole = meta.query_advice(b_a1, Rotation::cur());
let c_whole = meta.query_advice(c_b0, Rotation::cur());
let left_node = meta.query_advice(left_b1, Rotation::cur());
let right_node = meta.query_advice(right, Rotation::cur());

let a_0 = meta.query_advice(a, Rotation::next());
let a_1 = meta.query_advice(b, Rotation::next());
let b_0 = meta.query_advice(c, Rotation::next());
let b_1 = meta.query_advice(left, Rotation::next());
let a_0 = meta.query_advice(a_a0, Rotation::next());
let a_1 = meta.query_advice(b_a1, Rotation::next());
let b_0 = meta.query_advice(c_b0, Rotation::next());
let b_1 = meta.query_advice(left_b1, Rotation::next());

let l_star_plus1 = meta.query_fixed(l_star_plus1, Rotation::cur());

Expand Down Expand Up @@ -165,10 +165,10 @@ impl<C: CurveAffine, const PATH_LENGTH: usize, const K: usize, const MAX_WORDS:
});

MerkleConfig {
a,
b,
c,
left,
a_a0,
b_a1,
c_b0,
left_b1,
right,
l_star_plus1,
perm: sinsemilla_config.perm.clone(),
Expand Down Expand Up @@ -329,7 +329,7 @@ impl<C: CurveAffine, const PATH_LENGTH: usize, const K: usize, const MAX_WORDS:
copy(
&mut region,
|| "copy a",
config.a,
config.a_a0,
0,
&(a.into()),
&config.perm,
Expand All @@ -338,7 +338,7 @@ impl<C: CurveAffine, const PATH_LENGTH: usize, const K: usize, const MAX_WORDS:
copy(
&mut region,
|| "copy b",
config.b,
config.b_a1,
0,
&b.into(),
&config.perm,
Expand All @@ -347,13 +347,20 @@ impl<C: CurveAffine, const PATH_LENGTH: usize, const K: usize, const MAX_WORDS:
copy(
&mut region,
|| "copy c",
config.c,
config.c_b0,
0,
&c.into(),
&config.perm,
)?;
// Copy and assign the left node at the correct position.
copy(&mut region, || "left", config.left, 0, &left, &config.perm)?;
copy(
&mut region,
|| "left",
config.left_b1,
0,
&left,
&config.perm,
)?;
// Copy and assign the right node at the correct position.
copy(
&mut region,
Expand All @@ -367,28 +374,28 @@ impl<C: CurveAffine, const PATH_LENGTH: usize, const K: usize, const MAX_WORDS:
// Witness the piece `a_0`.
region.assign_advice(
|| "a_0",
config.a,
config.a_a0,
1,
|| a_0.ok_or(Error::SynthesisError),
)?;
// Witness the piece `a_1`.
region.assign_advice(
|| "a_1",
config.b,
config.b_a1,
1,
|| a_1.ok_or(Error::SynthesisError),
)?;
// Witness the piece `b_0`.
region.assign_advice(
|| "b_0",
config.c,
config.c_b0,
1,
|| b_0.ok_or(Error::SynthesisError),
)?;
// Witness the piece `b_1`.
region.assign_advice(
|| "b_1",
config.left,
config.left_b1,
1,
|| b_1.ok_or(Error::SynthesisError),
)?;
Expand Down

0 comments on commit 8602455

Please sign in to comment.