-
Notifications
You must be signed in to change notification settings - Fork 599
fix: oracles handlers #12864
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
fix: oracles handlers #12864
Changes from all commits
397d6e1
db696a8
ab503ab
519163b
cd51e9d
a4e29a7
c67557c
d38602a
593c1d8
2673a8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,20 @@ | ||
| use crate::utils::array; | ||
| use dep::protocol_types::{constants::PUBLIC_DATA_TREE_HEIGHT, data::PublicDataTreeLeafPreimage}; | ||
|
|
||
| global LEAF_PREIMAGE_LENGTH: u32 = 4; | ||
| global PUBLIC_DATA_WITNESS: u32 = 45; | ||
|
|
||
| pub struct PublicDataWitness { | ||
| pub index: Field, | ||
| pub leaf_preimage: PublicDataTreeLeafPreimage, | ||
| pub path: [Field; PUBLIC_DATA_TREE_HEIGHT], | ||
| } | ||
|
|
||
| #[oracle(getPublicDataTreeWitness)] | ||
| #[oracle(getPublicDataWitness)] | ||
| unconstrained fn get_public_data_witness_oracle( | ||
| _block_number: u32, | ||
| _public_data_tree_index: Field, | ||
| ) -> [Field; PUBLIC_DATA_WITNESS] {} | ||
| ) -> PublicDataWitness {} | ||
|
|
||
| pub unconstrained fn get_public_data_witness( | ||
| block_number: u32, | ||
| public_data_tree_index: Field, | ||
| ) -> PublicDataWitness { | ||
| let fields = get_public_data_witness_oracle(block_number, public_data_tree_index); | ||
| PublicDataWitness { | ||
| index: fields[0], | ||
| leaf_preimage: PublicDataTreeLeafPreimage { | ||
| slot: fields[1], | ||
| value: fields[2], | ||
| next_index: fields[3] as u32, | ||
| next_slot: fields[4], | ||
| }, | ||
| path: array::subarray(fields, 1 + LEAF_PREIMAGE_LENGTH), | ||
| } | ||
| get_public_data_witness_oracle(block_number, public_data_tree_index) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,14 @@ | ||
| use dep::protocol_types::{ | ||
| abis::validation_requests::{ | ||
| key_validation_request::KEY_VALIDATION_REQUEST_LENGTH, KeyValidationRequest, | ||
| }, | ||
| traits::Deserialize, | ||
| }; | ||
| use protocol_types::abis::validation_requests::KeyValidationRequest; | ||
|
|
||
| #[oracle(getKeyValidationRequest)] | ||
| unconstrained fn get_key_validation_request_oracle( | ||
| _pk_m_hash: Field, | ||
| _key_index: Field, | ||
| ) -> [Field; KEY_VALIDATION_REQUEST_LENGTH] {} | ||
|
|
||
| unconstrained fn get_key_validation_request_internal( | ||
| npk_m_hash: Field, | ||
| key_index: Field, | ||
| ) -> KeyValidationRequest { | ||
| let result = get_key_validation_request_oracle(npk_m_hash, key_index); | ||
| KeyValidationRequest::deserialize(result) | ||
| } | ||
| ) -> KeyValidationRequest {} | ||
|
|
||
| pub unconstrained fn get_key_validation_request( | ||
| pk_m_hash: Field, | ||
| key_index: Field, | ||
| ) -> KeyValidationRequest { | ||
| get_key_validation_request_internal(pk_m_hash, key_index) | ||
| get_key_validation_request_oracle(pk_m_hash, key_index) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -784,7 +784,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable { | |
| return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath); | ||
| } | ||
|
|
||
| async getPublicDataTreeWitness(blockNumber: L2BlockNumber, leafSlot: Fr): Promise<PublicDataWitness | undefined> { | ||
| async getPublicDataWitness(blockNumber: L2BlockNumber, leafSlot: Fr): Promise<PublicDataWitness | undefined> { | ||
|
Contributor
Author
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. This inconsistency was triggering me. Unfortunately this is on the public API. If we would want to not have this change while keeping consistency we would have to rename PublicDataWitness to PublicDataTreeWitness which would result in a monster diff. |
||
| const committedDb = await this.#getWorldState(blockNumber); | ||
| const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt()); | ||
| if (!lowLeafResult) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,19 +4,15 @@ import type { ForeignCallInput, ForeignCallOutput } from '@aztec/noir-acvm_js'; | |
|
|
||
| import { strict as assert } from 'assert'; | ||
|
|
||
| function fromACVMField(field: string): Fr { | ||
|
Contributor
Author
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. This was a copy of Fr.fromString |
||
| return Fr.fromBuffer(Buffer.from(field.slice(2), 'hex')); | ||
| } | ||
|
|
||
| export function foreignCallHandler(name: string, args: ForeignCallInput[]): Promise<ForeignCallOutput[]> { | ||
| // ForeignCallInput is actually a string[], so the args are string[][]. | ||
| const log = createLogger('noir-protocol-circuits:oracle'); | ||
|
|
||
| if (name === 'debugLog') { | ||
| assert(args.length === 3, 'expected 3 arguments for debugLog: msg, fields_length, fields'); | ||
| const [msgRaw, _ignoredFieldsSize, fields] = args; | ||
| const msg: string = msgRaw.map(acvmField => String.fromCharCode(fromACVMField(acvmField).toNumber())).join(''); | ||
| const fieldsFr: Fr[] = fields.map((field: string) => fromACVMField(field)); | ||
| const msg: string = msgRaw.map(acvmField => String.fromCharCode(Fr.fromString(acvmField).toNumber())).join(''); | ||
| const fieldsFr: Fr[] = fields.map((field: string) => Fr.fromString(field)); | ||
| log.verbose('debug_log ' + applyStringFormatting(msg, fieldsFr)); | ||
| } else if (name === 'noOp') { | ||
| // Workaround for compiler issues where data is deleted because it's "unused" | ||
|
|
||
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.
Why does this oracle function not have the
_oraclesuffix in the name as the others that have the #[oracle] tag have ? i.e. why is this one okay to directly return where the others have wrappers ?