Skip to content

Commit

Permalink
docs: Yellow paper updates for the parity circuits (#6048)
Browse files Browse the repository at this point in the history
A small yellow paper update for the parity circuits.
  • Loading branch information
PhilWindle authored May 1, 2024
1 parent 1c305be commit cfe1b05
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions docs/docs/protocol-specs/rollup-circuits/tree-parity.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ And the `sha_root` which must match the root of the sha256 message tree from the
The circuit computes the two trees using the same inputs, and then we ensure that the elements of the trees match the inbox later in the [state transitioner](./../l1-smart-contracts/index.md#overview).
It proves parity of the leaves in the two trees.


```mermaid
classDiagram
direction LR
class ParityPublicInputs {
aggregation_object: AggregationObject
sha_root: Fr[2]
converted_root: Fr
}
Expand All @@ -87,6 +85,7 @@ RootParityInputs *-- RootParityInput: children
class RootParityInput {
proof: Proof
verification_key: VerificationKey
public_inputs: ParityPublicInputs
}
RootParityInput *-- ParityPublicInputs: public_inputs
Expand All @@ -95,6 +94,7 @@ class BaseParityInputs {
msgs: List~Fr[2]~
}
```

The logic of the circuits is quite simple - build both a SHA256 and a snark-friendly tree from the same inputs.
For optimization purposes, it can be useful to have the layers take more than 2 inputs to increase the task of every layer.
If each just take 2 inputs, the overhead of recursing through the layers might be higher than the actual work done.
Expand All @@ -108,17 +108,15 @@ def base_parity_circuit(inputs: BaseParityInputs) -> ParityPublicInputs:

def root_parity_circuit(inputs: RootParityInputs) -> ParityPublicInputs:
for msg in inputs.children:
assert msg.proof.verify(msg.public_inputs);
assert msg.proof.verify(msg.public_inputs, msg.verification_key);

sha_root = MERKLE_TREE(
[msg.public_inputs.sha_root for msg in inputs.children],
[msg.public_inputs.sha_root for msg in inputs.children],
SHA256
);
converted_root = MERKLE_TREE(
[msg.public_inputs.converted_root for msg in inputs.children],
[msg.public_inputs.converted_root for msg in inputs.children],
SNARK_FRIENDLY_HASH_FUNCTION
);
return ParityPublicInputs(sha_root, converted_root)
```


0 comments on commit cfe1b05

Please sign in to comment.