-
Notifications
You must be signed in to change notification settings - Fork 611
fix: update function selector to be 4 bytes #293
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 7 commits
bbb6931
eb52495
9a5076d
a1c6ca0
4f55439
033a416
0589136
6daf833
55e7ace
c3315d3
d6350a3
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,7 +1,13 @@ | ||
| import { Buffer } from 'buffer'; | ||
| import { AztecAddress, Fr } from '@aztec/foundation'; | ||
| import { CircuitsWasm } from '../wasm/index.js'; | ||
| import { FunctionData, FUNCTION_SELECTOR_NUM_BYTES, TxRequest, NewContractData } from '../index.js'; | ||
| import { | ||
| FunctionData, | ||
| FUNCTION_SELECTOR_NUM_BYTES, | ||
| TxRequest, | ||
| NewContractData, | ||
| FunctionLeafPreimage, | ||
| } from '../index.js'; | ||
| import { serializeToBuffer } from '../utils/serialize.js'; | ||
| import { AsyncWasmWrapper, WasmWrapper } from '@aztec/foundation/wasm'; | ||
|
|
||
|
|
@@ -81,11 +87,11 @@ export async function hashVK(wasm: CircuitsWasm, vkBuf: Buffer) { | |
| return await wasmAsyncCall(wasm, 'abis__hash_vk', { toBuffer: () => vkBuf }, 32); | ||
| } | ||
|
|
||
| export async function computeFunctionLeaf(wasm: CircuitsWasm, fnLeaf: Buffer) { | ||
| // Size must match circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp | ||
| if (fnLeaf.length !== 32 + 1 + 32 + 32) throw new Error(`Invalid length for function leaf`); | ||
| export async function computeFunctionLeaf(wasm: CircuitsWasm, fnLeaf: FunctionLeafPreimage) { | ||
| const fnLeafBuf = fnLeaf.toBuffer(); | ||
| if (!FunctionLeafPreimage.verifyBufferSize(fnLeafBuf)) throw new Error(`Invalid length for function leaf`); | ||
| wasm.call('pedersen__init'); | ||
| return Fr.fromBuffer(await wasmAsyncCall(wasm, 'abis__compute_function_leaf', { toBuffer: () => fnLeaf }, 32)); | ||
| return Fr.fromBuffer(await wasmAsyncCall(wasm, 'abis__compute_function_leaf', { toBuffer: () => fnLeafBuf }, 32)); | ||
|
Collaborator
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. We can just pass |
||
| } | ||
|
|
||
| export async function computeFunctionTreeRoot(wasm: CircuitsWasm, fnLeafs: Fr[]) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`basic FunctionLeafPreimage serialization serializes a trivial Function Leaf Preimage and prints it 1`] = ` | ||
| "function_selector: 0x7b01000000000000000000000000000000000000000000000000000000 | ||
| is_private: 0 | ||
| "function_selector: 123 | ||
| is_private: 1 | ||
| vk_hash: 0x0 | ||
| acir_hash: 0x31000000082f1200f8e21100000000000000000000 | ||
|
Maddiaa0 marked this conversation as resolved.
|
||
| acir_hash: 0x0 | ||
| " | ||
| `; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,4 +28,8 @@ export class FunctionLeafPreimage { | |
| const reader = BufferReader.asReader(buffer); | ||
| return new FunctionLeafPreimage(reader.readBytes(4), reader.readBoolean(), reader.readFr(), reader.readFr()); | ||
| } | ||
|
|
||
| static verifyBufferSize(buffer: Buffer): boolean { | ||
|
Collaborator
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. I don't think this is needed now is it? Let's remove it.
Member
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. It is being used abis.ts line 92. Can we remove that check too? I think its still necessary as we are using a plain buffer as the input?
Collaborator
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. I guess I just find it a bit messy. What do you think of sanity checking the length of the buffer inside
Member
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. that sounds good to me |
||
| return buffer.length === 4 + 1 + 32 + 32; | ||
| } | ||
| } | ||
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.
Lets remove this out of date comment