Skip to content

Commit

Permalink
using EventSelector class more
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jun 18, 2024
1 parent dad50a4 commit d221bbc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ function generateEvents(events: any[] | undefined) {
if (payload === undefined) {
return undefined;
}
// TODO(#7089): Remove this conversion from EventSelector to FunctionSelector once event metadata is changed
if (
!functionSelector.equals(
FunctionSelector.fromField(payload.eventTypeId),
FunctionSelector.fromField(payload.eventTypeId.toField()),
)
) {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ describe('L1 Event Payload', () => {
randomness = Fr.random();
maskedContractAddress = pedersenHash([contractAddress, randomness], 0);

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

ovskM = GrumpkinScalar.random();
ivskM = GrumpkinScalar.random();
Expand Down
16 changes: 6 additions & 10 deletions yarn-project/circuit-types/src/logs/l1_payload/l1_event_payload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AztecAddress, type GrumpkinPrivateKey, type KeyValidationRequest, type PublicKey } from '@aztec/circuits.js';
import { EventSelector } from '@aztec/foundation/abi';
import { randomBytes } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

Expand Down Expand Up @@ -35,7 +34,7 @@ export class L1EventPayload extends L1Payload {
/**
* Type identifier for the underlying event, (calculated as a function selector).
*/
public eventTypeId: Fr,
public eventTypeId: EventSelector,
) {
super();
}
Expand All @@ -51,7 +50,7 @@ export class L1EventPayload extends L1Payload {
reader.readObject(Event),
reader.readObject(AztecAddress),
Fr.fromBuffer(reader),
Fr.fromBuffer(reader),
reader.readObject(EventSelector),
);
}

Expand All @@ -68,10 +67,7 @@ export class L1EventPayload extends L1Payload {
* @returns A random L1EventPayload object.
*/
static random() {
const eventTypeId = Fr.fromBuffer(
Buffer.concat([Buffer.alloc(Fr.SIZE_IN_BYTES - EventSelector.SIZE), randomBytes(EventSelector.SIZE)]),
);
return new L1EventPayload(Event.random(), AztecAddress.random(), Fr.random(), eventTypeId);
return new L1EventPayload(Event.random(), AztecAddress.random(), Fr.random(), EventSelector.random());
}

public encrypt(ephSk: GrumpkinPrivateKey, recipient: AztecAddress, ivpk: PublicKey, ovKeys: KeyValidationRequest) {
Expand All @@ -81,7 +77,7 @@ export class L1EventPayload extends L1Payload {
recipient,
ivpk,
ovKeys,
new EncryptedEventLogIncomingBody(this.randomness, this.eventTypeId, this.event),
new EncryptedEventLogIncomingBody(this.randomness, this.eventTypeId.toField(), this.event),
);
}

Expand Down Expand Up @@ -117,7 +113,7 @@ export class L1EventPayload extends L1Payload {

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

return new L1EventPayload(incomingBody.event, address, incomingBody.randomness, incomingBody.eventTypeId);
return new L1EventPayload(incomingBody.event, address, incomingBody.randomness, EventSelector.fromField(incomingBody.eventTypeId));
}

/**
Expand Down Expand Up @@ -152,7 +148,7 @@ export class L1EventPayload extends L1Payload {

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

return new L1EventPayload(incomingBody.event, address, incomingBody.randomness, incomingBody.eventTypeId);
return new L1EventPayload(incomingBody.event, address, incomingBody.randomness, EventSelector.fromField(incomingBody.eventTypeId));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ describe('L1 Event Payload', () => {
randomness = Fr.random();
maskedContractAddress = pedersenHash([contractAddress, randomness], 0);

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

ovskM = GrumpkinScalar.random();
ivskM = GrumpkinScalar.random();
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,8 @@ export class PXEService implements PXE {
if (visibleEvent.payload === undefined) {
return undefined;
}
if (!FunctionSelector.fromField(visibleEvent.payload.eventTypeId).equals(eventMetadata.functionSelector)) {
// TODO(#7089): Remove this conversion from EventSelector to FunctionSelector once event metadata is changed
if (!FunctionSelector.fromField(visibleEvent.payload.eventTypeId.toField()).equals(eventMetadata.functionSelector)) {
return undefined;
}
if (visibleEvent.payload.event.items.length !== eventMetadata.fieldNames.length) {
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/simulator/src/client/client_execution_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '@aztec/circuits.js';
import { Aes128 } from '@aztec/circuits.js/barretenberg';
import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
import { type FunctionAbi, type FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi';
import { EventSelector, type FunctionAbi, type FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { pedersenHash } from '@aztec/foundation/crypto';
import { Fr, GrumpkinScalar, type Point } from '@aztec/foundation/fields';
Expand Down Expand Up @@ -382,7 +382,7 @@ export class ClientExecutionContext extends ViewDataOracle {
preimage: Fr[],
) {
const event = new Event(preimage);
const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, eventTypeId);
const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, EventSelector.fromField(eventTypeId));
const taggedEvent = new TaggedLog(l1EventPayload);

const ephSk = GrumpkinScalar.random();
Expand Down

0 comments on commit d221bbc

Please sign in to comment.