Skip to content

Commit d221bbc

Browse files
committed
using EventSelector class more
1 parent dad50a4 commit d221bbc

File tree

6 files changed

+14
-22
lines changed

6 files changed

+14
-22
lines changed

yarn-project/builder/src/contract-interface-gen/typescript.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ function generateEvents(events: any[] | undefined) {
281281
if (payload === undefined) {
282282
return undefined;
283283
}
284+
// TODO(#7089): Remove this conversion from EventSelector to FunctionSelector once event metadata is changed
284285
if (
285286
!functionSelector.equals(
286-
FunctionSelector.fromField(payload.eventTypeId),
287+
FunctionSelector.fromField(payload.eventTypeId.toField()),
287288
)
288289
) {
289290
return undefined;

yarn-project/circuit-types/src/logs/l1_payload/l1_event_payload.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ describe('L1 Event Payload', () => {
3030
randomness = Fr.random();
3131
maskedContractAddress = pedersenHash([contractAddress, randomness], 0);
3232

33-
const eventTypeId = Fr.fromBuffer(
34-
Buffer.concat([Buffer.alloc(Fr.SIZE_IN_BYTES - EventSelector.SIZE), randomBytes(EventSelector.SIZE)]),
35-
);
36-
payload = new L1EventPayload(Event.random(), contractAddress, randomness, eventTypeId);
33+
payload = new L1EventPayload(Event.random(), contractAddress, randomness, EventSelector.random());
3734

3835
ovskM = GrumpkinScalar.random();
3936
ivskM = GrumpkinScalar.random();

yarn-project/circuit-types/src/logs/l1_payload/l1_event_payload.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { AztecAddress, type GrumpkinPrivateKey, type KeyValidationRequest, type PublicKey } from '@aztec/circuits.js';
22
import { EventSelector } from '@aztec/foundation/abi';
3-
import { randomBytes } from '@aztec/foundation/crypto';
43
import { Fr } from '@aztec/foundation/fields';
54
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
65

@@ -35,7 +34,7 @@ export class L1EventPayload extends L1Payload {
3534
/**
3635
* Type identifier for the underlying event, (calculated as a function selector).
3736
*/
38-
public eventTypeId: Fr,
37+
public eventTypeId: EventSelector,
3938
) {
4039
super();
4140
}
@@ -51,7 +50,7 @@ export class L1EventPayload extends L1Payload {
5150
reader.readObject(Event),
5251
reader.readObject(AztecAddress),
5352
Fr.fromBuffer(reader),
54-
Fr.fromBuffer(reader),
53+
reader.readObject(EventSelector),
5554
);
5655
}
5756

@@ -68,10 +67,7 @@ export class L1EventPayload extends L1Payload {
6867
* @returns A random L1EventPayload object.
6968
*/
7069
static random() {
71-
const eventTypeId = Fr.fromBuffer(
72-
Buffer.concat([Buffer.alloc(Fr.SIZE_IN_BYTES - EventSelector.SIZE), randomBytes(EventSelector.SIZE)]),
73-
);
74-
return new L1EventPayload(Event.random(), AztecAddress.random(), Fr.random(), eventTypeId);
70+
return new L1EventPayload(Event.random(), AztecAddress.random(), Fr.random(), EventSelector.random());
7571
}
7672

7773
public encrypt(ephSk: GrumpkinPrivateKey, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest) {
@@ -81,7 +77,7 @@ export class L1EventPayload extends L1Payload {
8177
recipient,
8278
ivpk,
8379
ovKeys,
84-
new EncryptedEventLogIncomingBody(this.randomness, this.eventTypeId, this.event),
80+
new EncryptedEventLogIncomingBody(this.randomness, this.eventTypeId.toField(), this.event),
8581
);
8682
}
8783

@@ -117,7 +113,7 @@ export class L1EventPayload extends L1Payload {
117113

118114
this.ensureMatchedMaskedContractAddress(address, incomingBody.randomness, encryptedLog.maskedContractAddress);
119115

120-
return new L1EventPayload(incomingBody.event, address, incomingBody.randomness, incomingBody.eventTypeId);
116+
return new L1EventPayload(incomingBody.event, address, incomingBody.randomness, EventSelector.fromField(incomingBody.eventTypeId));
121117
}
122118

123119
/**
@@ -152,7 +148,7 @@ export class L1EventPayload extends L1Payload {
152148

153149
this.ensureMatchedMaskedContractAddress(address, incomingBody.randomness, encryptedLog.maskedContractAddress);
154150

155-
return new L1EventPayload(incomingBody.event, address, incomingBody.randomness, incomingBody.eventTypeId);
151+
return new L1EventPayload(incomingBody.event, address, incomingBody.randomness, EventSelector.fromField(incomingBody.eventTypeId));
156152
}
157153
}
158154

yarn-project/circuit-types/src/logs/l1_payload/tagged_log.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ describe('L1 Event Payload', () => {
8787
randomness = Fr.random();
8888
maskedContractAddress = pedersenHash([contractAddress, randomness], 0);
8989

90-
const eventTypeId = Fr.fromBuffer(
91-
Buffer.concat([Buffer.alloc(Fr.SIZE_IN_BYTES - EventSelector.SIZE), randomBytes(EventSelector.SIZE)]),
92-
);
93-
const payload = new L1EventPayload(Event.random(), contractAddress, randomness, eventTypeId);
90+
const payload = new L1EventPayload(Event.random(), contractAddress, randomness, EventSelector.random());
9491

9592
ovskM = GrumpkinScalar.random();
9693
ivskM = GrumpkinScalar.random();

yarn-project/pxe/src/pxe_service/pxe_service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,8 @@ export class PXEService implements PXE {
853853
if (visibleEvent.payload === undefined) {
854854
return undefined;
855855
}
856-
if (!FunctionSelector.fromField(visibleEvent.payload.eventTypeId).equals(eventMetadata.functionSelector)) {
856+
// TODO(#7089): Remove this conversion from EventSelector to FunctionSelector once event metadata is changed
857+
if (!FunctionSelector.fromField(visibleEvent.payload.eventTypeId.toField()).equals(eventMetadata.functionSelector)) {
857858
return undefined;
858859
}
859860
if (visibleEvent.payload.event.items.length !== eventMetadata.fieldNames.length) {

yarn-project/simulator/src/client/client_execution_context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '@aztec/circuits.js';
2323
import { Aes128 } from '@aztec/circuits.js/barretenberg';
2424
import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
25-
import { type FunctionAbi, type FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi';
25+
import { EventSelector, type FunctionAbi, type FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi';
2626
import { AztecAddress } from '@aztec/foundation/aztec-address';
2727
import { pedersenHash } from '@aztec/foundation/crypto';
2828
import { Fr, GrumpkinScalar, type Point } from '@aztec/foundation/fields';
@@ -382,7 +382,7 @@ export class ClientExecutionContext extends ViewDataOracle {
382382
preimage: Fr[],
383383
) {
384384
const event = new Event(preimage);
385-
const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, eventTypeId);
385+
const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, EventSelector.fromField(eventTypeId));
386386
const taggedEvent = new TaggedLog(l1EventPayload);
387387

388388
const ephSk = GrumpkinScalar.random();

0 commit comments

Comments
 (0)