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

Sinsemilla chip with HashDomain #67

Merged
merged 20 commits into from
Jun 22, 2021
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
83eddd8
ecc::chip.rs: Add Point::from_coordinates_unchecked() API
therealyingtong Jun 19, 2021
af2ac76
gadget::sinsemilla.rs: Add Sinsemilla instructions.
therealyingtong Jun 19, 2021
e2859df
sinsemilla::message.rs: Add message module.
therealyingtong Jun 19, 2021
ebb7dae
sinsemilla::chip.rs: Add Sinsemilla chip.
therealyingtong Jun 19, 2021
74e617b
chip::generator_table.rs: Load Sinsemilla generator lookup table.
therealyingtong Jun 19, 2021
7cddc9b
sinsemilla::chip.rs: Implement witness_message_* APIs.
therealyingtong Jun 19, 2021
f122e48
sinsemilla::chip.rs: Configure Sinsemilla gates.
therealyingtong Jun 19, 2021
eba2172
chip::hash_to_point.rs: Implement hash_to_point instruction.
therealyingtong Jun 19, 2021
158ab86
gadget::sinsemilla.rs: Add Sinsemilla test.
therealyingtong Jun 19, 2021
2f6ca9e
generator_table.rs: Enforce z_n = 0 for the last message piece.
therealyingtong Jun 19, 2021
9072ed4
generator_table.rs: Fix bug in y_p lookup expression.
therealyingtong Jun 20, 2021
031bb0b
SinsemillaChip::configure(): Introduce closures for Y_A and x_r
therealyingtong Jun 20, 2021
9ce29d9
hash_to_point(): Introduce final_piece boolean flag
therealyingtong Jun 20, 2021
eccd72f
hash_piece(): Remove (correct) duplicate assignment of x_a.
therealyingtong Jun 20, 2021
744f3d1
SinsemillaChip::configure(): Combine and label gates.
therealyingtong Jun 20, 2021
002596f
Docfixes and cleanups.
therealyingtong Jun 20, 2021
5f5238f
Doc comment fixes
str4d Jun 20, 2021
a01c2ee
test: Print layout for Sinsemilla test circuit
str4d Jun 20, 2021
bd08808
SinsemillaChip::configure(): Merge "Initial y_q" gate with main gate
therealyingtong Jun 20, 2021
8af8447
Rename "Sinsemilla gate" constraint to "y check".
daira Jun 21, 2021
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
52 changes: 24 additions & 28 deletions src/circuit/gadget/sinsemilla/chip/hash_to_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ impl SinsemillaChip {

let mut zs_sum: Vec<Vec<CellValue<pallas::Base>>> = Vec::new();

// Hash each piece in the message except the final piece.
for piece in message[0..(message.len() - 1)].iter() {
// Hash each piece in the message.
for (idx, piece) in message[0..message.len()].iter().enumerate() {
therealyingtong marked this conversation as resolved.
Show resolved Hide resolved
let final_piece = idx == message.len() - 1;

// The value of the accumulator after this piece is processed.
let (x, y, zs) = self.hash_piece(region, offset, piece, x_a, y_a)?;
let (x, y, zs) = self.hash_piece(region, offset, piece, x_a, y_a, final_piece)?;

// Since each message word takes one row to process, we increase
// the offset by `piece.num_words` on each iteration.
Expand All @@ -75,29 +77,9 @@ impl SinsemillaChip {
zs_sum.push(zs);
}

// Hash the final message piece.
// Assign the final y_a.
let y_a = {
let piece = &message[message.len() - 1];
// The value of the accumulator after this piece is processed.
let (x, y, zs) = self.hash_piece(region, offset, piece, x_a, y_a)?;

// Since each message word takes one row to process, we increase
// the offset by `piece.num_words` on each iteration.
offset += piece.num_words();

// Update the accumulator to the latest value.
x_a = x;
y_a = y;
zs_sum.push(zs);

// Assign and constrain the final `y_a`.
region.assign_fixed(
|| "qs_2 = 2 on final row",
config.q_sinsemilla2,
offset - 1,
|| Ok(pallas::Base::from_u64(2)),
)?;

// Assign the final y_a.
let y_a_cell = region.assign_advice(
|| "y_a",
config.lambda_1,
Expand Down Expand Up @@ -181,6 +163,7 @@ impl SinsemillaChip {
>>::MessagePiece,
x_a: X<pallas::Base>,
y_a: Y<pallas::Base>,
therealyingtong marked this conversation as resolved.
Show resolved Hide resolved
final_piece: bool,
) -> Result<
(
X<pallas::Base>,
Expand Down Expand Up @@ -208,12 +191,25 @@ impl SinsemillaChip {
)?;
}

// Set `q_sinsemilla2` fixed column to 0 on the last row.
// Set `q_sinsemilla2` fixed column to 0 on the last row if this is
// not the final piece, or to 2 on the last row of the final piece.
region.assign_fixed(
|| "q_s2 = 1",
|| {
if final_piece {
"q_s2 for final piece"
} else {
"q_s2 between pieces"
}
},
config.q_sinsemilla2,
offset + piece.num_words() - 1,
|| Ok(pallas::Base::zero()),
|| {
Ok(if final_piece {
pallas::Base::from_u64(2)
} else {
pallas::Base::zero()
})
},
)?;
}

Expand Down