-
Notifications
You must be signed in to change notification settings - Fork 612
fix(pxe): respect slot boundaries in oracle (de)serialization #24211
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
Changes from all commits
83a5670
aaabdfa
43d153e
00a81e9
d2d7d76
d68da31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ import { | |
| U32, | ||
| UTILITY_CONTEXT, | ||
| assertReadersConsumed, | ||
| slotsOf, | ||
| } from './oracle_type_mappings.js'; | ||
|
|
||
| export { | ||
|
|
@@ -59,6 +60,7 @@ export { | |
| BOUNDED_VEC, | ||
| BUFFER, | ||
| BYTE, | ||
| CONTRACT_CLASS_LOG_INPUT, | ||
| DELIVERY_MODE, | ||
| EPHEMERAL_ARRAY, | ||
| EVENT_VALIDATION_REQUEST, | ||
|
|
@@ -75,9 +77,11 @@ export { | |
| PROVIDED_SECRET, | ||
| STR, | ||
| U32, | ||
| slotsOf, | ||
| type InputSlot, | ||
| type MaybePromise, | ||
| type OutputSlot, | ||
| type SlotShape, | ||
| type TypeMapping, | ||
| } from './oracle_type_mappings.js'; | ||
|
|
||
|
|
@@ -103,7 +107,10 @@ export const ORACLE_REGISTRY = { | |
| aztec_utl_getUtilityContext: makeEntry({ returnType: UTILITY_CONTEXT }), | ||
|
|
||
| aztec_utl_getKeyValidationRequest: makeEntry({ | ||
| params: [{ name: 'pkMHash', type: FIELD }], | ||
| params: [ | ||
| { name: 'pkMHash', type: FIELD }, | ||
| { name: 'keyIndex', type: FIELD }, | ||
|
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. The |
||
| ], | ||
| returnType: KEY_VALIDATION_REQUEST, | ||
| }), | ||
|
|
||
|
|
@@ -540,12 +547,12 @@ export function makeEntry<const TParams extends RegistryParam[] = [], TReturnVal | |
| const resolvedParams: RegistryParam[] = params ?? []; | ||
| // Walk the input slots left-to-right, advancing by each param's slot count. | ||
| let offset = 0; | ||
| return resolvedParams.map(param => { | ||
| const named = resolvedParams.map(param => { | ||
| if (!param.type.deserialization) { | ||
| throw new Error(`Param '${param.name}' has no deserialization defined`); | ||
| } | ||
| // Collect the slots for this param and wrap each in a FieldReader. | ||
| const slotCount = param.type.deserialization.slots; | ||
| const slotCount = slotsOf(param.type); | ||
| const readers = inputs | ||
| .slice(offset, offset + slotCount) | ||
| .map(slot => new FieldReader(slot.map(hex => Fr.fromString(hex)))); | ||
|
|
@@ -555,7 +562,13 @@ export function makeEntry<const TParams extends RegistryParam[] = [], TReturnVal | |
| const value = param.type.deserialization.fn(readers); | ||
| assertReadersConsumed(readers); | ||
| return { name: param.name, value }; | ||
| }) as unknown as InferDeserializedParams<TParams>; | ||
| }); | ||
| // Every input slot must be specified by a param: oracles whose Noir decl passes an extra field must declare it | ||
| // (the handler can ignore it). Otherwise an under-declared shape would silently drop a field into nothing. | ||
| if (offset !== inputs.length) { | ||
|
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 new check asserts we are not messing up |
||
| throw new Error(`Oracle received ${inputs.length} input slot(s) but the registry specifies ${offset}`); | ||
| } | ||
| return named as unknown as InferDeserializedParams<TParams>; | ||
| }, | ||
| serializeReturn(result: TReturnValue): OutputSlot[] { | ||
| if (returnType?.serialization === undefined) { | ||
|
|
||
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.
This is so that we can do things like
Option.none({ maxLength: ciphertext.maxLength });I tried passing a
Sizetype all the way from the registry to the Option, but in most cases, a size isn't needed. So I thought the extra type added more noise than it helped