-
Notifications
You must be signed in to change notification settings - Fork 598
feat: purge of log decryption in TS #12992
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
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 |
|---|---|---|
|
|
@@ -2,14 +2,12 @@ import { type InitialAccountData, deployFundedSchnorrAccount } from '@aztec/acco | |
| import type { AztecNodeService } from '@aztec/aztec-node'; | ||
| import { | ||
| type AccountWallet, | ||
| AccountWalletWithSecretKey, | ||
| type AztecAddress, | ||
| type AztecNode, | ||
| ContractDeployer, | ||
| ContractFunctionInteraction, | ||
| Fr, | ||
| type GlobalVariables, | ||
| L1EventPayload, | ||
| type Logger, | ||
| type PXE, | ||
| TxStatus, | ||
|
|
@@ -420,13 +418,27 @@ describe('e2e_block_building', () => { | |
| afterAll(() => teardown()); | ||
|
|
||
| it('calls a method with nested encrypted logs', async () => { | ||
| const thisWallet = new AccountWalletWithSecretKey(pxe, ownerWallet, owner.secret, owner.salt); | ||
| const address = owner.address; | ||
|
|
||
| const values = { | ||
|
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 expected value changed to a struct because that's how the event looks and the getPrivateEvents endpoint returns the value ABI decoded and not as an array of fields. |
||
| value0: 5n, | ||
| value1: 4n, | ||
| value2: 3n, | ||
| value3: 2n, | ||
| value4: 1n, | ||
| }; | ||
| const nestedValues = { | ||
| value0: 0n, | ||
| value1: 0n, | ||
| value2: 0n, | ||
| value3: 0n, | ||
| value4: 0n, | ||
| }; | ||
|
|
||
| // call test contract | ||
| const values = [new Fr(5), new Fr(4), new Fr(3), new Fr(2), new Fr(1)]; | ||
| const nestedValues = [new Fr(0), new Fr(0), new Fr(0), new Fr(0), new Fr(0)]; | ||
| const action = testContract.methods.emit_array_as_encrypted_log(values, address, address, true); | ||
| const valuesAsArray = Object.values(values); | ||
|
|
||
| const action = testContract.methods.emit_array_as_encrypted_log(valuesAsArray, address, address, true); | ||
| const tx = await action.prove(); | ||
| const rct = await tx.send().wait(); | ||
|
|
||
|
|
@@ -436,16 +448,23 @@ describe('e2e_block_building', () => { | |
| expect(privateLogs.length).toBe(3); | ||
|
|
||
| // The first two logs are encrypted. | ||
| const event0 = (await L1EventPayload.decryptAsIncoming(privateLogs[0], await thisWallet.getEncryptionSecret()))!; | ||
| expect(event0.event.items).toEqual(values); | ||
|
|
||
| const event1 = (await L1EventPayload.decryptAsIncoming(privateLogs[1], await thisWallet.getEncryptionSecret()))!; | ||
| expect(event1.event.items).toEqual(nestedValues); | ||
| const events = await pxe.getPrivateEvents( | ||
| testContract.address, | ||
| TestContract.events.ExampleEvent, | ||
| rct.blockNumber!, | ||
| 1, | ||
| [address], | ||
| ); | ||
| expect(events[0]).toEqual(values); | ||
| expect(events[1]).toEqual(nestedValues); | ||
|
|
||
| // The last log is not encrypted. | ||
| // The first field is the first value and is siloed with contract address by the kernel circuit. | ||
| const expectedFirstField = await poseidon2Hash([testContract.address, values[0]]); | ||
| expect(privateLogs[2].fields.slice(0, 5)).toEqual([expectedFirstField, ...values.slice(1)]); | ||
| const expectedFirstField = await poseidon2Hash([testContract.address, valuesAsArray[0]]); | ||
| expect(privateLogs[2].fields.slice(0, 5).map((f: Fr) => f.toBigInt())).toEqual([ | ||
| expectedFirstField.toBigInt(), | ||
| ...valuesAsArray.slice(1), | ||
| ]); | ||
| }, 60_000); | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,6 @@ import { | |
| getContractClassFromArtifact, | ||
| } from '@aztec/stdlib/contract'; | ||
| import { SimulationError } from '@aztec/stdlib/errors'; | ||
| import { EventMetadata } from '@aztec/stdlib/event'; | ||
| import type { GasFees } from '@aztec/stdlib/gas'; | ||
| import { siloNullifier } from '@aztec/stdlib/hash'; | ||
| import type { | ||
|
|
@@ -915,7 +914,6 @@ export class PXEService implements PXE { | |
| } | ||
|
|
||
| async getPublicEvents<T>(eventMetadataDef: EventMetadataDefinition, from: number, limit: number): Promise<T[]> { | ||
| const eventMetadata = new EventMetadata<T>(eventMetadataDef); | ||
|
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. I completely nuked the EventMetadata thing as it now felt largely useless. |
||
| const { logs } = await this.node.getPublicLogs({ | ||
| fromBlock: from, | ||
| toBlock: from + limit, | ||
|
|
@@ -924,10 +922,10 @@ export class PXEService implements PXE { | |
| const decodedEvents = logs | ||
| .map(log => { | ||
| // +1 for the event selector | ||
| const expectedLength = eventMetadata.fieldNames.length + 1; | ||
| const expectedLength = eventMetadataDef.fieldNames.length + 1; | ||
| const logFields = log.log.log.slice(0, expectedLength); | ||
| // We are assuming here that event logs are the last 4 bytes of the event. This is not enshrined but is a function of aztec.nr raw log emission. | ||
| if (!EventSelector.fromField(logFields[logFields.length - 1]).equals(eventMetadata.eventSelector)) { | ||
| if (!EventSelector.fromField(logFields[logFields.length - 1]).equals(eventMetadataDef.eventSelector)) { | ||
| return undefined; | ||
| } | ||
| // If any of the remaining fields, are non-zero, the payload does match expected: | ||
|
|
@@ -937,7 +935,7 @@ export class PXEService implements PXE { | |
| ); | ||
| } | ||
|
|
||
| return eventMetadata.decode(log.log); | ||
| return decodeFromAbi([eventMetadataDef.abiType], log.log.log) as T; | ||
| }) | ||
| .filter(log => log !== undefined) as T[]; | ||
|
|
||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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.
While originally we manually decrypted here now I call the getPrivateEvents endpoint.