-
Notifications
You must be signed in to change notification settings - Fork 598
feat(prover | p2p): extend epoch quote validation #10863
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a73836f
feat: extend epoch quote validation
Maddiaa0 74e47e8
change: configure rollup version in constructor
Maddiaa0 42b260e
fix: merge
Maddiaa0 eb82767
fix: dirty merge
Maddiaa0 ea94877
fix: rebase tests + fmt
Maddiaa0 6b5aa6f
fix: typesafe
Maddiaa0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
yarn-project/circuit-types/src/prover_coordination/epoch_proof_quote_hasher.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { RollupAbi } from '@aztec/ethereum/contracts'; | ||
| import { Buffer32 } from '@aztec/foundation/buffer'; | ||
|
|
||
| import { getAbiItem, hashTypedData, keccak256, parseAbiParameters } from 'viem'; | ||
|
|
||
| import { type EpochProofQuotePayload, type EthAddress } from './epoch_proof_quote_payload.js'; | ||
|
|
||
| type EpochProofQuoteTypeHash = { | ||
| EpochProofQuote: { | ||
| name: string; | ||
| type: string; | ||
| }[]; | ||
| }; | ||
|
|
||
| /** | ||
| * Constructs the type hash for the EpochProofQuote struct. | ||
| * | ||
| * Given an abi type like so { | ||
| * EpochProofQuote: { | ||
| * name: 'epochToProve', | ||
| * type: 'uint256', | ||
| * } | ||
| * } | ||
| * | ||
| * it would construct the hash of the following string: | ||
| * E.g: EpochProofQuote(uint256 epochToProve) | ||
| * | ||
| * @param types - The types of the EpochProofQuote struct | ||
| */ | ||
| function constructTypeHash(types: EpochProofQuoteTypeHash): `0x${string}` { | ||
| const paramsString = types.EpochProofQuote.map(({ name, type }) => `${type} ${name}`).join(','); | ||
| const typeString = `EpochProofQuote(${paramsString})`; | ||
| return keccak256(Buffer.from(typeString)); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs the abi for the quoteToDigest function. | ||
| * | ||
| * Given an abi type like so { | ||
| * EpochProofQuote: { | ||
| * name: 'epochToProve', | ||
| * type: 'uint256', | ||
| * } | ||
| * } | ||
| * | ||
| * it would construct the abi of the following string: | ||
| * [name (EpochProofQuote), ...params] | ||
| * E.g: bytes32, uint256 epochToProve | ||
| * | ||
| * @param types - The types of the EpochProofQuote struct | ||
| */ | ||
| function constructHasherAbi(types: EpochProofQuoteTypeHash) { | ||
| return parseAbiParameters(`bytes32, ${types.EpochProofQuote.map(({ name, type }) => `${type} ${name}`).join(',')}`); | ||
| } | ||
|
|
||
| /** | ||
| * A utility class to hash EpochProofQuotePayloads following the EIP-712 standard. | ||
| */ | ||
| export class EpochProofQuoteHasher { | ||
| // Domain information | ||
| private readonly domain: { | ||
| name: string; | ||
| version: string; | ||
| chainId: number; | ||
| verifyingContract: `0x${string}`; | ||
| }; | ||
|
|
||
| /** | ||
| * Reads the abi of the quoteToDigest function from the rollup contract and extracts the types | ||
| * of the EpochProofQuote struct. | ||
| * function quoteToDigest(EpochProofQuote quote) | ||
| * | ||
| * This avoids re-declaring the types and values here that could go out of sync with | ||
| * the rollup contract | ||
| */ | ||
| static readonly types: EpochProofQuoteTypeHash = { | ||
| EpochProofQuote: getAbiItem({ abi: RollupAbi, name: 'quoteToDigest' }).inputs[0].components.map(component => ({ | ||
| name: component.name, | ||
| type: component.type, | ||
| })), | ||
| }; | ||
|
|
||
| // Type hash for the types defined in the types object | ||
| static readonly EPOCH_PROOF_QUOTE_TYPE_HASH = constructTypeHash(EpochProofQuoteHasher.types); | ||
|
|
||
| // Viem abi object for the types defined in the types object | ||
| static readonly HASHER_ABI = constructHasherAbi(EpochProofQuoteHasher.types); | ||
|
|
||
| constructor(rollupAddress: EthAddress, version: number, chainId: number) { | ||
| this.domain = { | ||
| name: 'Aztec Rollup', | ||
| version: version.toString(), | ||
| chainId, | ||
| verifyingContract: rollupAddress.toString(), | ||
| }; | ||
| } | ||
|
|
||
| hash(payload: EpochProofQuotePayload): Buffer32 { | ||
| return Buffer32.fromString( | ||
| hashTypedData({ | ||
| domain: this.domain, | ||
| types: EpochProofQuoteHasher.types, | ||
| primaryType: 'EpochProofQuote', | ||
| message: payload.toViemArgs(), | ||
| }), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './epoch_proof_quote.js'; | ||
| export * from './epoch_proof_quote_hasher.js'; | ||
| export * from './epoch_proof_quote_payload.js'; | ||
| export * from './epoch_proof_claim.js'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we encounter something like a struct or list I would kinda expect to fail miserably. Could we specify it to explode if it ecounter
tupleortuple[]as the type.