-
Notifications
You must be signed in to change notification settings - Fork 191
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
refactor: PublicCircuitPublicInputs
and PrivateCircuitPublicInputs
cleanup
#4360
Merged
benesjan
merged 8 commits into
master
from
02-01-refactor_PublicCircuitPublicInputs_cleanup
Feb 1, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ee33c1a
refactor: typing contents of MessageLoadOracleInputs
benesjan 1300439
test fix
benesjan e30fbc5
stale comment
benesjan dd67ce5
refactor: PublicCircuitPublicInputs cleanup
benesjan 7e8d3f1
cleanup of extractPublicCircuitPublicInputs
benesjan 1fba608
cleanup of extractPrivateCircuitPublicInputs
benesjan d14c88f
nuking extractPublicCircuitPublicInputs and extractPrivateCircuitPubl…
benesjan bb571a2
comment
benesjan 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 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,31 +1,4 @@ | ||
import { | ||
CallContext, | ||
ContractDeploymentData, | ||
ContractStorageRead, | ||
ContractStorageUpdateRequest, | ||
HEADER_LENGTH, | ||
Header, | ||
MAX_NEW_COMMITMENTS_PER_CALL, | ||
MAX_NEW_L2_TO_L1_MSGS_PER_CALL, | ||
MAX_NEW_NULLIFIERS_PER_CALL, | ||
MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, | ||
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, | ||
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, | ||
MAX_PUBLIC_DATA_READS_PER_CALL, | ||
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, | ||
MAX_READ_REQUESTS_PER_CALL, | ||
NUM_FIELDS_PER_SHA256, | ||
NullifierKeyValidationRequest, | ||
PrivateCircuitPublicInputs, | ||
PublicCircuitPublicInputs, | ||
RETURN_VALUES_LENGTH, | ||
SideEffect, | ||
SideEffectLinkedToNoteHash, | ||
} from '@aztec/circuits.js'; | ||
import { AztecAddress } from '@aztec/foundation/aztec-address'; | ||
import { EthAddress } from '@aztec/foundation/eth-address'; | ||
import { Fr, Point } from '@aztec/foundation/fields'; | ||
import { FieldReader, Tuple } from '@aztec/foundation/serialize'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
|
||
import { getReturnWitness } from '@noir-lang/acvm_js'; | ||
|
||
|
@@ -44,6 +17,7 @@ export function fromACVMField(field: ACVMField): Fr { | |
* Converts a field to a number. | ||
* @param fr - The field to convert. | ||
* @returns The number. | ||
* TODO(#4102): Nuke this once block number is big int. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
export function frToNumber(fr: Fr): number { | ||
return Number(fr.value); | ||
|
@@ -60,142 +34,3 @@ export function extractReturnWitness(acir: Buffer, partialWitness: ACVMWitness): | |
const sortedKeys = [...returnWitness.keys()].sort((a, b) => a - b); | ||
return sortedKeys.map(key => returnWitness.get(key)!).map(fromACVMField); | ||
} | ||
|
||
/** | ||
* Create a reader for the public inputs of the ACVM generated partial witness. | ||
*/ | ||
function createPublicInputsReader(witness: ACVMWitness, acir: Buffer) { | ||
const fields = extractReturnWitness(acir, witness); | ||
return new FieldReader(fields); | ||
} | ||
|
||
/** | ||
* Extracts the public inputs from the ACVM generated partial witness. | ||
* @param partialWitness - The partial witness. | ||
* @param acir - The ACIR bytecode. | ||
* @returns The public inputs. | ||
*/ | ||
export function extractPrivateCircuitPublicInputs( | ||
partialWitness: ACVMWitness, | ||
acir: Buffer, | ||
): PrivateCircuitPublicInputs { | ||
const witnessReader = createPublicInputsReader(partialWitness, acir); | ||
|
||
const callContext = witnessReader.readObject(CallContext); | ||
const argsHash = witnessReader.readField(); | ||
const returnValues = witnessReader.readFieldArray(RETURN_VALUES_LENGTH); | ||
const readRequests = witnessReader.readArray(MAX_READ_REQUESTS_PER_CALL, SideEffect); | ||
const nullifierKeyValidationRequests = witnessReader.readArray( | ||
MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, | ||
NullifierKeyValidationRequest, | ||
); | ||
const newCommitments = witnessReader.readArray(MAX_NEW_COMMITMENTS_PER_CALL, SideEffect); | ||
const newNullifiers = witnessReader.readArray(MAX_NEW_NULLIFIERS_PER_CALL, SideEffectLinkedToNoteHash); | ||
const privateCallStack = witnessReader.readFieldArray(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL); | ||
const publicCallStack = witnessReader.readFieldArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); | ||
const newL2ToL1Msgs = witnessReader.readFieldArray(MAX_NEW_L2_TO_L1_MSGS_PER_CALL); | ||
const endSideEffectCounter = witnessReader.readField(); | ||
|
||
const encryptedLogsHash = witnessReader.readFieldArray(NUM_FIELDS_PER_SHA256); | ||
const unencryptedLogsHash = witnessReader.readFieldArray(NUM_FIELDS_PER_SHA256); | ||
const encryptedLogPreimagesLength = witnessReader.readField(); | ||
const unencryptedLogPreimagesLength = witnessReader.readField(); | ||
|
||
const header = Header.fromFields(witnessReader.readFieldArray(HEADER_LENGTH)); | ||
|
||
const contractDeploymentData = new ContractDeploymentData( | ||
new Point(witnessReader.readField(), witnessReader.readField()), | ||
witnessReader.readField(), | ||
witnessReader.readField(), | ||
witnessReader.readField(), | ||
EthAddress.fromField(witnessReader.readField()), | ||
); | ||
|
||
const chainId = witnessReader.readField(); | ||
const version = witnessReader.readField(); | ||
|
||
return new PrivateCircuitPublicInputs( | ||
callContext, | ||
argsHash, | ||
returnValues, | ||
readRequests, | ||
nullifierKeyValidationRequests, | ||
newCommitments, | ||
newNullifiers, | ||
privateCallStack, | ||
publicCallStack, | ||
newL2ToL1Msgs, | ||
endSideEffectCounter, | ||
encryptedLogsHash, | ||
unencryptedLogsHash, | ||
encryptedLogPreimagesLength, | ||
unencryptedLogPreimagesLength, | ||
header, | ||
contractDeploymentData, | ||
chainId, | ||
version, | ||
); | ||
} | ||
|
||
/** | ||
* Extracts the public circuit public inputs from the ACVM generated partial witness. | ||
* @param partialWitness - The partial witness. | ||
* @param acir - The ACIR bytecode. | ||
* @returns The public inputs. | ||
*/ | ||
export function extractPublicCircuitPublicInputs(partialWitness: ACVMWitness, acir: Buffer): PublicCircuitPublicInputs { | ||
const witnessReader = createPublicInputsReader(partialWitness, acir); | ||
|
||
const callContext = witnessReader.readObject(CallContext); | ||
|
||
const argsHash = witnessReader.readField(); | ||
const returnValues = witnessReader.readFieldArray(RETURN_VALUES_LENGTH); | ||
|
||
const contractStorageUpdateRequests = new Array(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL).fill( | ||
ContractStorageUpdateRequest.empty(), | ||
); | ||
for (let i = 0; i < MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL; i++) { | ||
const request = new ContractStorageUpdateRequest( | ||
witnessReader.readField(), | ||
witnessReader.readField(), | ||
witnessReader.readField(), | ||
); | ||
contractStorageUpdateRequests[i] = request; | ||
} | ||
const contractStorageReads = new Array(MAX_PUBLIC_DATA_READS_PER_CALL).fill(ContractStorageRead.empty()); | ||
for (let i = 0; i < MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL; i++) { | ||
const request = new ContractStorageRead(witnessReader.readField(), witnessReader.readField()); | ||
contractStorageReads[i] = request; | ||
} | ||
|
||
const publicCallStack = witnessReader.readFieldArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL); | ||
const newCommitments = witnessReader.readArray(MAX_NEW_COMMITMENTS_PER_CALL, SideEffect); | ||
const newNullifiers = witnessReader.readArray(MAX_NEW_NULLIFIERS_PER_CALL, SideEffectLinkedToNoteHash); | ||
const newL2ToL1Msgs = witnessReader.readFieldArray(MAX_NEW_L2_TO_L1_MSGS_PER_CALL); | ||
|
||
const unencryptedLogsHash = witnessReader.readFieldArray(NUM_FIELDS_PER_SHA256); | ||
const unencryptedLogPreimagesLength = witnessReader.readField(); | ||
|
||
const header = Header.fromFields(witnessReader.readFieldArray(HEADER_LENGTH)); | ||
|
||
const proverAddress = AztecAddress.fromField(witnessReader.readField()); | ||
|
||
return new PublicCircuitPublicInputs( | ||
callContext, | ||
argsHash, | ||
returnValues, | ||
contractStorageUpdateRequests as Tuple< | ||
ContractStorageUpdateRequest, | ||
typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL | ||
>, | ||
contractStorageReads as Tuple<ContractStorageRead, typeof MAX_PUBLIC_DATA_READS_PER_CALL>, | ||
publicCallStack, | ||
newCommitments, | ||
newNullifiers, | ||
newL2ToL1Msgs, | ||
unencryptedLogsHash, | ||
unencryptedLogPreimagesLength, | ||
header, | ||
proverAddress, | ||
); | ||
} |
This file contains 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 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 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 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 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 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 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 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 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
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.
🧹