Skip to content

Orchard proposed mainnet circuit#237

Merged
str4d merged 70 commits intomainfrom
orchard-mainnet-circuit
Dec 20, 2021
Merged

Orchard proposed mainnet circuit#237
str4d merged 70 commits intomainfrom
orchard-mainnet-circuit

Conversation

@str4d
Copy link
Contributor

@str4d str4d commented Nov 19, 2021

This is the feature branch for the proposed mainnet version of the Orchard Action circuit.

Closes #231.

@codecov-commenter
Copy link

codecov-commenter commented Nov 19, 2021

Codecov Report

Merging #237 (8a4f4e3) into main (dfcea20) will decrease coverage by 1.15%.
The diff coverage is 85.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #237      +/-   ##
==========================================
- Coverage   90.62%   89.47%   -1.16%     
==========================================
  Files          66       67       +1     
  Lines        7830     7989     +159     
==========================================
+ Hits         7096     7148      +52     
- Misses        734      841     +107     
Impacted Files Coverage Δ
benches/poseidon.rs 0.00% <0.00%> (ø)
src/primitives/poseidon/p128pow5t3.rs 88.29% <66.66%> (-3.29%) ⬇️
src/circuit/gadget/utilities.rs 87.85% <70.00%> (-5.67%) ⬇️
src/circuit/gadget/poseidon.rs 75.80% <73.21%> (+4.65%) ⬆️
src/circuit/gadget/utilities/lookup_range_check.rs 85.45% <73.91%> (+0.18%) ⬆️
src/circuit/gadget/utilities/cond_swap.rs 79.80% <76.66%> (-1.11%) ⬇️
src/primitives/poseidon.rs 82.64% <81.35%> (+7.43%) ⬆️
.../circuit/gadget/utilities/decompose_running_sum.rs 85.18% <84.61%> (+0.50%) ⬆️
src/circuit/gadget/poseidon/pow5.rs 86.45% <86.45%> (ø)
src/circuit/gadget/ecc/chip/mul/incomplete.rs 91.25% <87.17%> (-4.10%) ⬇️
... and 37 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 dfcea20...8a4f4e3. Read the comment docs.

therealyingtong and others added 3 commits November 30, 2021 20:36
Co-authored-by: Jack Grigg <jack@electriccoin.co>
Co-authored-by: str4d <jack@electriccoin.co>
Benchmark Poseidon gadget for rates {2, 8, 11}
@str4d str4d mentioned this pull request Dec 1, 2021
@str4d str4d added the M-circuit-change This causes a circuit change label Dec 1, 2021
str4d added 2 commits December 8, 2021 04:11
The ECC test chip performs various checks that assume the chip will only
be synthesized with witnesses. This assumption is broken by the chip
printer test, so we fix the assumption here.
@str4d str4d changed the title Orchard mainnet circuit Orchard proposed mainnet circuit Dec 9, 2021
str4d and others added 13 commits December 9, 2021 15:30
Migrate to halo2 version with `AssignedCell`
The `Sponge` struct's API correctly enforces the properties of a sponge:
it can absorb an arbitrary number of elements, and then squeeze an
arbitrary number of elements, but cannot absorb after it has squeezed.

Co-authored-by: ying tong <yingtong@z.cash>
For almost all the sponge constructions defined in the Poseidon paper,
the domain can be defined completely statically. Variable-length hashing
requires knowledge of the message length, but that can be provided to
the fixed padding function in a subsequent commit, and in any case we
can't use variable-length inputs in a circuit.
This exposes a bug in the way padding was being handled by the invalid
sponge-duplex hybrid construction.
Sponge constructions pad the entire input message and then split it into
rate-sized chunks. The previous implementation was using an incorrect
duplex-like hybrid where padding was applied to each chunked input. We
now use an enum to distinguish message and padding words being absorbed
into the sponge.

This also fixes two previous bugs:
- If a `ConstantLength` hash had a length greater than the permutation's
  rate but not a multiple of it, no padding would be generated and the
  circuit would fail to create proofs.
- If a sponge usage required more output than the permutation's rate,
  the squeeze-side permutations would in some cases incorrectly apply
  padding, when it should instead use the prior state as-is. We now add
  zeroes instead.

This change doesn't alter the Orchard circuit, because it doesn't need
any padding cells, only takes a single field element as output, and
padding is still assigned in the same region as before.
In the previous commit, we fixed a bug where padding was being added to
the state when the sponge was in squeezing mode. But there's no need to
assign a circuit region in which we add constant zeroes to the state :)
`M` was at one point only used as a type marker, but now it stores per-mode state.

Co-authored-by: ying tong <yingtong@z.cash>
Also fixes some clippy lints (public docs linking to private items).

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
A sponge can only have two modes: absorbing, and squeezing.
`PrimeField::from_repr` explicitly leaves the endianness opaque. We
therefore can't use it in places we were using `FieldExt::from_bytes`
(which was specifically little-endian) generically, but the previous
commit replaced it everywhere. We now handle generic contexts on a
case-by-case basis:

- Where we needed to convert bitstrings into field elements, we now use
  double-and-add on the field elements directly instead of on bytes.
  This is less efficient, but visible correct (and a future change to
  the `ff` crate APIs could enable the more efficient version).

- `INV_TWO_POW_K`, which is pre-computed for `pallas::Base`, was being
  incorrectly used in a field-generic circuit. We now compute it live.

- `test_zs_and_us` was only used in tests, and hard-coded a field
  element encoding length of 32 bytes. It now uses Pallas concretely.
Also fixes some incorrect code comments.

Closes #263.
Remove various usages of `FieldExt` methods
@str4d str4d marked this pull request as ready for review December 20, 2021 17:35
@str4d
Copy link
Contributor Author

str4d commented Dec 20, 2021

orchard 0.1.0-beta.1 has been released, which encodes the first testnet version of the circuit. The next beta release of this crate will encode the proposed mainnet circuit, and we've made the changes we wanted to here. The only remaining change to the circuit code will be #183, but that will be easier to perform directly on main.

@str4d str4d added this to the Core Sprint 2021-50 milestone Dec 20, 2021
@str4d
Copy link
Contributor Author

str4d commented Dec 20, 2021

I confirmed locally that this branch only contains merge commits. So there's new to review in this PR, beyond what was already reviewed in the PRs themselves.

@str4d str4d merged commit 54cdc05 into main Dec 20, 2021
@str4d str4d deleted the orchard-mainnet-circuit branch December 20, 2021 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cut proposed mainnet version of the Orchard circuit

4 participants