Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Oct 29, 2024
1 parent a00acd4 commit 9963e49
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('EncryptedLogPayload', () => {

const ephSk = GrumpkinScalar.random();

encrypted = original.encrypt(ephSk, completeAddress.address, computePoint(completeAddress.address), ovKeys);
encrypted = original.encrypt(ephSk, completeAddress.address, ovKeys);
});

it('decrypt a log as incoming', () => {
Expand Down Expand Up @@ -122,9 +122,7 @@ describe('EncryptedLogPayload', () => {
'0x25afb798ea6d0b8c1618e50fdeafa463059415013d3b7c75d46abf5e242be70c138af8799f2fba962549802469e12e3b7ba4c5f9c999c6421e05c73f45ec68481970dd8ce0250b677759dfc040f6edaf77c5827a7bcd425e66bcdec3fa7e59bc18dd22d6a4032eefe3a7a55703f583396596235f7c186e450c92981186ee74042e49e00996565114016a1a478309842ecbaf930fb716c3f498e7e10370631d7507f696b8b233de2c1935e43c793399586f532da5ff7c0356636a75acb862e964156e8a3e42bfca3663936ba98c7fd26386a14657c23b5f5146f1a94b6c4651542685ea16f17c580a7cc7c8ff2688dce9bde8bf1f50475f4c3281e1c33404ee0025f50db0733f719462b22eff03cec746bb9e3829ae3636c84fbccd2754b5a5a92087a5f41ccf94a03a2671cd341ba3264c45147e75d4ea96e3b1a58498550b89',
);

const encrypted = log
.encrypt(ephSk, recipientCompleteAddress.address, computePoint(recipientCompleteAddress.address), ovKeys)
.toString('hex');
const encrypted = log.encrypt(ephSk, recipientCompleteAddress.address, ovKeys).toString('hex');
expect(encrypted).toMatchInlineSnapshot(
`"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008d460c0e434d846ec1ea286e4090eb56376ff27bddc1aacae1d856549f701fa70577790aeabcc2d81ec8d0c99e7f5d2bf2f1452025dc777a178404f851d93de818923f85187871d99bdf95d695eff0a9e09ba15153fc9b4d224b6e1e71dfbdcaab06c09d5b3c749bfebe1c0407eccd04f51bbb59142680c8a091b97fc6cbcf61f6c2af9b8ebc8f78537ab23fd0c5e818e4d42d459d265adb77c2ef829bf68f87f2c47b478bb57ae7e41a07643f65c353083d557b94e31da4a2a13127498d2eb3f0346da5eed2e9bc245aaf022a954ed0b09132b498f537702899b44e3666776238ebf633b3562d7f124dbba82918e871958a94218fd796bc6983feecc7ce382c82861d63fe45999244ea9494b226ddb694b2640dce005b473acf1ae3be158f558ad1ca228e9f793d09390230a2597e0e53ad28f7aa9a700ccc302607ad6c26ea1410735b6a8c793f6317f7009409a3912b15ee2f28ccf17cf6c94b720301e5c5826de39e85bc7db3dc33aa79afcaf325670d1b359d08b10bd07840d394c9f038"`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Point,
type PublicKey,
computeOvskApp,
computePoint,
derivePublicKeyFromSecretKey,
} from '@aztec/circuits.js';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
Expand Down Expand Up @@ -45,18 +46,11 @@ export class EncryptedLogPayload {
public readonly incomingBodyPlaintext: Buffer,
) {}

public encrypt(
ephSk: GrumpkinScalar,
recipient: AztecAddress,
ivpk: PublicKey,
ovKeys: KeyValidationRequest,
): Buffer {
if (ivpk.isZero()) {
throw new Error(`Attempting to encrypt an event log with a zero ivpk.`);
}
public encrypt(ephSk: GrumpkinScalar, recipient: AztecAddress, ovKeys: KeyValidationRequest): Buffer {
const addressPoint = computePoint(recipient);

const ephPk = derivePublicKeyFromSecretKey(ephSk);
const incomingHeaderCiphertext = encrypt(this.contractAddress.toBuffer(), ephSk, ivpk);
const incomingHeaderCiphertext = encrypt(this.contractAddress.toBuffer(), ephSk, addressPoint);
const outgoingHeaderCiphertext = encrypt(this.contractAddress.toBuffer(), ephSk, ovKeys.pkM);

if (incomingHeaderCiphertext.length !== HEADER_SIZE) {
Expand All @@ -66,9 +60,9 @@ export class EncryptedLogPayload {
throw new Error(`Invalid outgoing header size: ${outgoingHeaderCiphertext.length}`);
}

const incomingBodyCiphertext = encrypt(this.incomingBodyPlaintext, ephSk, ivpk);
const incomingBodyCiphertext = encrypt(this.incomingBodyPlaintext, ephSk, addressPoint);
// The serialization of Fq is [high, low] check `outgoing_body.nr`
const outgoingBodyPlaintext = serializeToBuffer(ephSk.hi, ephSk.lo, recipient, ivpk.toCompressedBuffer());
const outgoingBodyPlaintext = serializeToBuffer(ephSk.hi, ephSk.lo, recipient, addressPoint.toCompressedBuffer());
const outgoingBodyCiphertext = encrypt(
outgoingBodyPlaintext,
ovKeys.skAppAsGrumpkinScalar,
Expand All @@ -94,18 +88,18 @@ export class EncryptedLogPayload {
/**
* Decrypts a ciphertext as an incoming log.
*
* This is executable by the recipient of the note, and uses the ivsk to decrypt the payload.
* This is executable by the recipient of the note, and uses the addressSecret to decrypt the payload.
* The outgoing parts of the log are ignored entirely.
*
* Produces the same output as `decryptAsOutgoing`.
*
* @param ciphertext - The ciphertext for the log
* @param ivsk - The incoming viewing secret key, used to decrypt the logs
* @param addressSecret - The incoming viewing secret key, used to decrypt the logs
* @returns The decrypted log payload
*/
public static decryptAsIncoming(
ciphertext: Buffer | BufferReader,
ivsk: GrumpkinScalar,
addressSecret: GrumpkinScalar,
): EncryptedLogPayload | undefined {
const reader = BufferReader.asReader(ciphertext);

Expand All @@ -115,14 +109,14 @@ export class EncryptedLogPayload {

const ephPk = Point.fromCompressedBuffer(reader.readBytes(Point.COMPRESSED_SIZE_IN_BYTES));

const incomingHeader = decrypt(reader.readBytes(HEADER_SIZE), ivsk, ephPk);
const incomingHeader = decrypt(reader.readBytes(HEADER_SIZE), addressSecret, ephPk);

// Skipping the outgoing header and body
reader.readBytes(HEADER_SIZE);
reader.readBytes(OUTGOING_BODY_SIZE);

// The incoming can be of variable size, so we read until the end
const incomingBodyPlaintext = decrypt(reader.readToEnd(), ivsk, ephPk);
const incomingBodyPlaintext = decrypt(reader.readToEnd(), addressSecret, ephPk);

return new EncryptedLogPayload(
incomingTag,
Expand Down Expand Up @@ -180,19 +174,19 @@ export class EncryptedLogPayload {
const ovskApp = computeOvskApp(ovsk, contractAddress);

let ephSk: GrumpkinScalar;
let recipientIvpk: PublicKey;
let recipientAddressPoint: PublicKey;
{
const outgoingBody = decrypt(reader.readBytes(OUTGOING_BODY_SIZE), ovskApp, ephPk, derivePoseidonAESSecret);
const obReader = BufferReader.asReader(outgoingBody);

// From outgoing body we extract ephSk, recipient and recipientIvpk
// From outgoing body we extract ephSk, recipient and recipientAddressPoint
ephSk = GrumpkinScalar.fromHighLow(obReader.readObject(Fr), obReader.readObject(Fr));
const _recipient = obReader.readObject(AztecAddress);
recipientIvpk = Point.fromCompressedBuffer(obReader.readBytes(Point.COMPRESSED_SIZE_IN_BYTES));
recipientAddressPoint = Point.fromCompressedBuffer(obReader.readBytes(Point.COMPRESSED_SIZE_IN_BYTES));
}

// Now we decrypt the incoming body using the ephSk and recipientIvpk
const incomingBody = decrypt(reader.readToEnd(), ephSk, recipientIvpk);
// Now we decrypt the incoming body using the ephSk and recipientAddressPoint
const incomingBody = decrypt(reader.readToEnd(), ephSk, recipientAddressPoint);

return new EncryptedLogPayload(incomingTag, outgoingTag, contractAddress, incomingBody);
} catch (e: any) {
Expand Down
80 changes: 40 additions & 40 deletions yarn-project/end-to-end/scripts/e2e_test_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ tests:
base: {}
bench_prover:
env:
HARDWARE_CONCURRENCY: "32"
COMPOSE_FILE: "scripts/docker-compose-no-sandbox.yml"
DEBUG: "aztec:benchmarks:*,aztec:sequencer,aztec:sequencer:*,aztec:world_state,aztec:merkle_trees"
command: "./scripts/e2e_compose_test.sh bench_prover"
HARDWARE_CONCURRENCY: '32'
COMPOSE_FILE: 'scripts/docker-compose-no-sandbox.yml'
DEBUG: 'aztec:benchmarks:*,aztec:sequencer,aztec:sequencer:*,aztec:world_state,aztec:merkle_trees'
command: './scripts/e2e_compose_test.sh bench_prover'
bench_publish_rollup:
env:
HARDWARE_CONCURRENCY: "32"
COMPOSE_FILE: "scripts/docker-compose-no-sandbox.yml"
DEBUG: "aztec:benchmarks:*,aztec:sequencer,aztec:sequencer:*,aztec:world_state,aztec:merkle_trees"
command: "./scripts/e2e_compose_test.sh bench_publish_rollup"
HARDWARE_CONCURRENCY: '32'
COMPOSE_FILE: 'scripts/docker-compose-no-sandbox.yml'
DEBUG: 'aztec:benchmarks:*,aztec:sequencer,aztec:sequencer:*,aztec:world_state,aztec:merkle_trees'
command: './scripts/e2e_compose_test.sh bench_publish_rollup'
bench_tx_size:
env:
HARDWARE_CONCURRENCY: "32"
COMPOSE_FILE: "scripts/docker-compose-no-sandbox.yml"
DEBUG: "aztec:benchmarks:*,aztec:sequencer,aztec:sequencer:*,aztec:world_state,aztec:merkle_trees"
command: "./scripts/e2e_compose_test.sh bench_tx_size"
HARDWARE_CONCURRENCY: '32'
COMPOSE_FILE: 'scripts/docker-compose-no-sandbox.yml'
DEBUG: 'aztec:benchmarks:*,aztec:sequencer,aztec:sequencer:*,aztec:world_state,aztec:merkle_trees'
command: './scripts/e2e_compose_test.sh bench_tx_size'
e2e_2_pxes: {}
e2e_account_contracts: {}
e2e_authwit: {}
Expand All @@ -37,20 +37,20 @@ tests:
use_compose: true
e2e_escrow_contract: {}
e2e_fees_account_init:
test_path: "e2e_fees/account_init.test.ts"
test_path: 'e2e_fees/account_init.test.ts'
# TODO(https://github.com/AztecProtocol/aztec-packages/issues/9488): reenable
# e2e_fees_dapp_subscription:
# test_path: "e2e_fees/dapp_subscription.test.ts"
e2e_fees_failures:
test_path: "e2e_fees/failures.test.ts"
test_path: 'e2e_fees/failures.test.ts'
e2e_fees_fee_juice_payments:
test_path: "e2e_fees/fee_juice_payments.test.ts"
test_path: 'e2e_fees/fee_juice_payments.test.ts'
e2e_fees_gas_estimation:
test_path: "e2e_fees/gas_estimation.test.ts"
test_path: 'e2e_fees/gas_estimation.test.ts'
e2e_fees_private_payments:
test_path: "e2e_fees/private_payments.test.ts"
test_path: 'e2e_fees/private_payments.test.ts'
e2e_fees_private_refunds:
test_path: "e2e_fees/private_refunds.test.ts"
test_path: 'e2e_fees/private_refunds.test.ts'
e2e_keys: {}
e2e_l1_with_wall_time: {}
e2e_lending_contract: {}
Expand All @@ -67,13 +67,13 @@ tests:
e2e_private_voting_contract: {}
e2e_prover_coordination: {}
e2e_prover_fake_proofs:
test_path: "e2e_prover/full.test.ts"
test_path: 'e2e_prover/full.test.ts'
env:
FAKE_PROOFS: "1"
FAKE_PROOFS: '1'
e2e_prover_full:
test_path: "e2e_prover/full.test.ts"
test_path: 'e2e_prover/full.test.ts'
env:
HARDWARE_CONCURRENCY: "32"
HARDWARE_CONCURRENCY: '32'
e2e_public_testnet: {}
e2e_sandbox_example:
use_compose: true
Expand All @@ -82,44 +82,44 @@ tests:
e2e_synching: {}
e2e_token_contract: {}
flakey_e2e_tests:
test_path: "./src/flakey"
test_path: './src/flakey'
ignore_failures: true
guides_dapp_testing:
use_compose: true
test_path: "guides/dapp_testing.test.ts"
test_path: 'guides/dapp_testing.test.ts'
guides_sample_dapp:
use_compose: true
test_path: "sample-dapp/index.test.mjs"
test_path: 'sample-dapp/index.test.mjs'
guides_sample_dapp_ci:
use_compose: true
test_path: "sample-dapp/ci/index.test.mjs"
test_path: 'sample-dapp/ci/index.test.mjs'
guides_up_quick_start:
use_compose: true
test_path: "guides/up_quick_start.test.ts"
test_path: 'guides/up_quick_start.test.ts'
guides_writing_an_account_contract:
use_compose: true
test_path: "guides/writing_an_account_contract.test.ts"
test_path: 'guides/writing_an_account_contract.test.ts'
integration_l1_publisher:
use_compose: true
kind_network_4epochs:
env:
NAMESPACE: "smoke"
FRESH_INSTALL: "true"
VALUES_FILE: "$-default.yaml"
command: "./scripts/network_test.sh ./src/spartan/4epochs.test.ts"
NAMESPACE: 'smoke'
FRESH_INSTALL: 'true'
VALUES_FILE: '$-default.yaml'
command: './scripts/network_test.sh ./src/spartan/4epochs.test.ts'
ignore_failures: true
kind_network_smoke:
env:
NAMESPACE: "smoke"
FRESH_INSTALL: "true"
VALUES_FILE: "$-default.yaml"
command: "./scripts/network_test.sh ./src/spartan/smoke.test.ts"
NAMESPACE: 'smoke'
FRESH_INSTALL: 'true'
VALUES_FILE: '$-default.yaml'
command: './scripts/network_test.sh ./src/spartan/smoke.test.ts'
kind_network_transfer:
env:
NAMESPACE: "transfer"
FRESH_INSTALL: "true"
VALUES_FILE: "$-default.yaml"
command: "./scripts/network_test.sh ./src/spartan/smoke.test.ts"
NAMESPACE: 'transfer'
FRESH_INSTALL: 'true'
VALUES_FILE: '$-default.yaml'
command: './scripts/network_test.sh ./src/spartan/smoke.test.ts'
pxe:
use_compose: true
uniswap_trade_on_l1_from_l2:
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/database/deferred_note_dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
*/
export class DeferredNoteDao {
constructor(
/** IvpkM or OvpkM (depending on if incoming or outgoing) the note was encrypted with. */
/** Address Point or OvpkM (depending on if incoming or outgoing) the note was encrypted with. */
public publicKey: PublicKey,
/** The note payload delivered via L1. */
public payload: L1NotePayload,
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/database/incoming_note_dao.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const randomIncomingNoteDao = ({
noteHash = Fr.random(),
siloedNullifier = Fr.random(),
index = Fr.random().toBigInt(),
ivpkM = Point.random(),
addressPoint = Point.random(),
}: Partial<IncomingNoteDao> = {}) => {
return new IncomingNoteDao(
note,
Expand All @@ -26,7 +26,7 @@ export const randomIncomingNoteDao = ({
noteHash,
siloedNullifier,
index,
ivpkM,
addressPoint,
);
};

Expand Down
8 changes: 4 additions & 4 deletions yarn-project/pxe/src/database/incoming_note_dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ export class IncomingNoteDao implements NoteData {
/** The location of the relevant note in the note hash tree. */
public index: bigint,
/** The public key with which the note was encrypted. */
public ivpkM: PublicKey,
public addressPoint: PublicKey,
) {}

static fromPayloadAndNoteInfo(
note: Note,
payload: L1NotePayload,
noteInfo: NoteInfo,
dataStartIndexForTx: number,
ivpkM: PublicKey,
addressPoint: PublicKey,
) {
const noteHashIndexInTheWholeTree = BigInt(dataStartIndexForTx + noteInfo.noteHashIndex);
return new IncomingNoteDao(
Expand All @@ -58,7 +58,7 @@ export class IncomingNoteDao implements NoteData {
noteInfo.noteHash,
noteInfo.siloedNullifier,
noteHashIndexInTheWholeTree,
ivpkM,
addressPoint,
);
}

Expand All @@ -73,7 +73,7 @@ export class IncomingNoteDao implements NoteData {
this.noteHash,
this.siloedNullifier,
this.index,
this.ivpkM,
this.addressPoint,
]);
}
static fromBuffer(buffer: Buffer | BufferReader) {
Expand Down
Loading

0 comments on commit 9963e49

Please sign in to comment.