-
Notifications
You must be signed in to change notification settings - Fork 234
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
feat!: tree leaf value as Fr
everywhere in our public API
#3173
Changes from all commits
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 |
---|---|---|
|
@@ -291,9 +291,9 @@ export class AztecNodeService implements AztecNode { | |
* @param leafValue - The value to search for | ||
* @returns The index of the given leaf in the given tree or undefined if not found. | ||
*/ | ||
public async findLeafIndex(treeId: MerkleTreeId, leafValue: Buffer): Promise<bigint | undefined> { | ||
public async findLeafIndex(treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined> { | ||
const committedDb = await this.#getWorldState(); | ||
return committedDb.findLeafIndex(treeId, leafValue); | ||
return committedDb.findLeafIndex(treeId, leafValue.toBuffer()); | ||
} | ||
|
||
/** | ||
|
@@ -324,7 +324,7 @@ export class AztecNodeService implements AztecNode { | |
*/ | ||
public async getL1ToL2MessageAndIndex(messageKey: Fr): Promise<L1ToL2MessageAndIndex> { | ||
// todo: #697 - make this one lookup. | ||
const index = (await this.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGES_TREE, messageKey.toBuffer()))!; | ||
const index = (await this.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGES_TREE, messageKey))!; | ||
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. wait hold up above uses buffer and this uses FR? 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 am AFK already so I merged it and I will consider addressing this tomorrow. |
||
const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(messageKey); | ||
return Promise.resolve(new L1ToL2MessageAndIndex(index, message)); | ||
} | ||
|
@@ -346,10 +346,11 @@ export class AztecNodeService implements AztecNode { | |
* @returns Storage value at the given contract slot (or undefined if not found). | ||
* Note: Aztec's version of `eth_getStorageAt`. | ||
*/ | ||
public async getPublicStorageAt(contract: AztecAddress, slot: bigint): Promise<Buffer | undefined> { | ||
public async getPublicStorageAt(contract: AztecAddress, slot: bigint): Promise<Fr | undefined> { | ||
const committedDb = await this.#getWorldState(); | ||
const leafIndex = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, new Fr(slot)); | ||
return committedDb.getLeafValue(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex.value); | ||
const value = await committedDb.getLeafValue(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex.value); | ||
return value ? Fr.fromBuffer(value) : undefined; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ import { | |
Wallet, | ||
} from '@aztec/aztec.js'; | ||
import { CompleteAddress, GrumpkinPrivateKey, GrumpkinScalar } from '@aztec/circuits.js'; | ||
import { toBigInt } from '@aztec/foundation/serialize'; | ||
import { ChildContract } from '@aztec/noir-contracts/types'; | ||
|
||
import { randomBytes } from 'crypto'; | ||
|
@@ -56,7 +55,8 @@ function itShouldBehaveLikeAnAccountContract( | |
const { logger, pxe } = context; | ||
logger('Calling public function...'); | ||
await child.methods.pubIncValue(42).send().wait({ interval: 0.1 }); | ||
expect(toBigInt((await pxe.getPublicStorageAt(child.address, new Fr(1)))!)).toEqual(42n); | ||
const storedValue = await pxe.getPublicStorageAt(child.address, new Fr(1)); | ||
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. |
||
expect(storedValue!).toEqual(new Fr(42n)); | ||
}, 60_000); | ||
|
||
it('fails to call a function using an invalid signature', async () => { | ||
|
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.
should the find leaf index api also use Fr ?
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.
I felt like changing the types in the merkle tree package could get a bit tricky in some places we pass the serialized indexed tree value which should not be Fr. Also we'll nuke the whole package and replace it with Rust or C++ so it's probably ok to keep the code disgusting.