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

Merkle hash chip #98

Merged
merged 13 commits into from
Jun 29, 2021
Merged

Merkle hash chip #98

merged 13 commits into from
Jun 29, 2021

Conversation

therealyingtong
Copy link
Contributor

@therealyingtong therealyingtong commented Jun 2, 2021

Closes #95.

@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2021

Codecov Report

Merging #98 (7c38f14) into main (0ccb010) will increase coverage by 31.66%.
The diff coverage is 81.85%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main      #98       +/-   ##
===========================================
+ Coverage   52.31%   83.98%   +31.66%     
===========================================
  Files          16       53       +37     
  Lines         583     4657     +4074     
===========================================
+ Hits          305     3911     +3606     
- Misses        278      746      +468     
Impacted Files Coverage Δ
src/constants/commit_ivk_r.rs 100.00% <ø> (ø)
src/constants/load.rs 0.00% <0.00%> (ø)
src/constants/note_commit_r.rs 100.00% <ø> (ø)
src/constants/nullifier_k.rs 100.00% <ø> (ø)
src/constants/spend_auth_g.rs 100.00% <ø> (ø)
src/constants/value_commit_r.rs 100.00% <ø> (ø)
src/primitives/poseidon/grain.rs 91.04% <ø> (ø)
src/test_vectors/note_encryption.rs 100.00% <ø> (ø)
src/primitives/redpallas.rs 61.11% <40.00%> (-1.39%) ⬇️
src/bundle.rs 42.50% <43.22%> (+42.50%) ⬆️
... and 88 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 12cef17...7c38f14. Read the comment docs.

@therealyingtong therealyingtong force-pushed the sinsemilla-chip-config branch 3 times, most recently from b279de3 to 5074388 Compare June 3, 2021 04:31
@therealyingtong therealyingtong force-pushed the merkle-chip branch 4 times, most recently from b025ffb to 9882fe8 Compare June 3, 2021 18:40
@therealyingtong therealyingtong force-pushed the merkle-chip branch 3 times, most recently from 7669068 to 23e5018 Compare June 4, 2021 12:48
@therealyingtong therealyingtong mentioned this pull request Jun 5, 2021
@therealyingtong therealyingtong force-pushed the merkle-chip branch 3 times, most recently from 8a5f541 to 527963c Compare June 5, 2021 09:05
copy(
&mut region,
|| "copy a",
config.advices[0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name these rather than repeating the indices from earlier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of naming the columns, I have chosen to inline a table in the doc comments showing how they're being used in the custom gate:

The pieces and subpieces are arranged in the following configuration:
|  A_0  |  A_1  |  A_2  |  A_3  |  A_4  | l_plus_1 |
----------------------------------------------------
|   a   |   b   |   c   |  left | right |   l + 1  |
|  z1_a |  z1_b |  b_1  |  b_2  |       |          |

// z_1 of SinsemillaHash(b) = b_1 + 2^5 b_2
// => b_0 = b - (z1_b * 2^10)
let z1_b = meta.query_advice(advices[1], Rotation::next());
// b_1 has been constrained to be 5 bits outside this gate.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where this is done (I may have just missed it). Similarly for b_2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done when witness_short_check() is called in hash_layer().

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK modulo comments and suggestions.

therealyingtong and others added 10 commits June 29, 2021 12:07
This has three const generic parameters: PATH_LENGTH, K, MAX_WORDS.
PATH_LENGTH is the length of the Merkle path being hashed. K and
MAX_WORDS parameterize the internal Sinsemilla instance used in
hashing the path.
MerkleChip::configure() takes a SinsemillaConfig as input.
Co-authored-by: Daira Hopwood <[email protected]>
@therealyingtong therealyingtong changed the base branch from patch-sinsemilla to main June 29, 2021 09:40
@therealyingtong therealyingtong changed the base branch from main to patch-sinsemilla June 29, 2021 09:41
Base automatically changed from patch-sinsemilla to main June 29, 2021 09:43
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 3806a9d with a non-blocking question. Layout LGTM.

merkle-path-layout

src/circuit/gadget/sinsemilla/merkle/chip.rs Outdated Show resolved Hide resolved
src/circuit/gadget/sinsemilla/merkle/chip.rs Outdated Show resolved Hide resolved
// is decomposed.
// - Disabling the entire decomposition gate when set to zero
// (i.e. replacing a Selector).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Visually connect the comment to the fixed column:

Suggested change

src/circuit/gadget/sinsemilla/merkle/chip.rs Outdated Show resolved Hide resolved
@str4d
Copy link
Contributor

str4d commented Jun 29, 2021

I merged my suggestions, after confirming that the lookup_config in MerkleConfig was unused in the action-circuit PR. If it turns out to be necessary later, we can revert that commit.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 7c38f14 (last three commits).

@str4d str4d merged commit bb159a2 into main Jun 29, 2021
@str4d str4d deleted the merkle-chip branch June 29, 2021 22:09
@daira
Copy link
Contributor

daira commented Jul 6, 2021

Hmm, looking at the layout, there's a single cell in the middle column that is taking up its own row in each 5-column side, and there is space in the previous row(s) for it to be moved to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Merkle path validity chip
5 participants