Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed May 14, 2024
1 parent 3e27ab7 commit f44993d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,7 @@ Encrypted events can only be emitted by private functions and are encrypted usin
For this reason it is necessary to register a recipient in the Private Execution Environment (PXE) before encrypting the events for them.
Recipients can be registered using Aztec.js:

```ts
const aztecAddress = AztecAddress.fromString(
"0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529"
);
const publicKey = Point.fromString(
"0x26e193aef4f83c70651485b5526c6d01a36d763223ab24efd1f9ff91b394ac0c20ad99d0ef669dc0dde8d5f5996c63105de8e15c2c87d8260b9e6f02f72af622"
);
const partialAddress = Fr.fromString(
"0x200e9a6c2d2e8352012e51c6637659713d336405c29386c7c4ac56779ab54fa7"
);

const completeAddress = new CompleteAddress(
aztecAddress,
publicKey,
partialKey
);
await pxe.registerRecipient(completeAddress);
```
#include_code register-recipient yarn-project/end-to-end/src/flakey_e2e_account_init_fees.test.ts rust

:::info
If a note recipient is one of the accounts inside the PXE, we don't need to register it as a recipient because we already have the public key available. You can register a recipient as shown [here](../../deploying_contracts/how_to_deploy_contract.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/learn/concepts/accounts/keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To retrieve them a developer can use one of the getters in aztec_nr:
If the keys are registered in the key registry these methods can be called without any setup.
If they are not there, it is necessary to first register the user as a recipient in our PXE by passing in the recipient's [complete address](#complete-address) as an argument:

#include_code key-getters /noir-projects/aztec-nr/aztec/src/keys/getters.nr rust
#include_code register-recipient yarn-project/end-to-end/src/flakey_e2e_account_init_fees.test.ts rust

Simulator will then retrieve these keys via an oracle call from PXE during private function execution.

Expand Down
51 changes: 27 additions & 24 deletions yarn-project/end-to-end/src/flakey_e2e_account_init_fees.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { getSchnorrAccount } from '@aztec/accounts/schnorr';
import {
type AccountManager,
type AztecNode,
type DebugLogger,
type DeployL1Contracts,
ExtendedNote,
Fr,
NativeFeePaymentMethod,
Note,
type PXE,
PrivateFeePaymentMethod,
PublicFeePaymentMethod,
Schnorr,
Expand All @@ -25,14 +28,7 @@ import {

import { jest } from '@jest/globals';

import {
type BalancesFn,
type EndToEndContext,
expectMapping,
getBalancesFn,
publicDeployAccounts,
setup,
} from './fixtures/utils.js';
import { type BalancesFn, expectMapping, getBalancesFn, publicDeployAccounts, setup } from './fixtures/utils.js';
import { GasPortalTestingHarnessFactory, type IGasBridgingTestHarness } from './shared/gas_portal_test_harness.js';

const TOKEN_NAME = 'BananaCoin';
Expand All @@ -43,8 +39,11 @@ const BRIDGED_FPC_GAS = BigInt(10e12);
jest.setTimeout(1_000_000);

describe('e2e_fees_account_init', () => {
let ctx: EndToEndContext;
let logger: DebugLogger;
let aztecNode: AztecNode;
let pxe: PXE;
let teardown: () => Promise<void>;

let sequencer: Wallet;
let sequencersAddress: AztecAddress;
let alice: Wallet;
Expand Down Expand Up @@ -84,22 +83,24 @@ describe('e2e_fees_account_init', () => {
}

beforeAll(async () => {
ctx = await setup(2, {}, {}, true);
logger = ctx.logger;
[sequencer, alice] = ctx.wallets;
let wallets: Wallet[];
let wallet: Wallet;
let deployL1ContractsValues: DeployL1Contracts;
({ logger, wallets, wallet, aztecNode, pxe, deployL1ContractsValues } = await setup(2, {}, {}, true));
[sequencer, alice] = wallets;
sequencersAddress = sequencer.getAddress();

await ctx.aztecNode.setConfig({
await aztecNode.setConfig({
feeRecipient: sequencersAddress,
});

gasBridgeTestHarness = await GasPortalTestingHarnessFactory.create({
aztecNode: ctx.aztecNode,
pxeService: ctx.pxe,
publicClient: ctx.deployL1ContractsValues.publicClient,
walletClient: ctx.deployL1ContractsValues.walletClient,
wallet: ctx.wallet,
logger: ctx.logger,
aztecNode,
pxeService: pxe,
publicClient: deployL1ContractsValues.publicClient,
walletClient: deployL1ContractsValues.walletClient,
wallet,
logger,
mockL1: false,
});

Expand All @@ -122,15 +123,15 @@ describe('e2e_fees_account_init', () => {
gasBalances = getBalancesFn('⛽', gas.methods.balance_of_public, logger);
});

afterAll(() => ctx.teardown());
afterAll(() => teardown());

beforeEach(() => {
gasSettings = GasSettings.default();
maxFee = gasSettings.getFeeLimit().toBigInt();
actualFee = 1n;
bobsSecretKey = Fr.random();
bobsPrivateSigningKey = Fq.random();
bobsAccountManager = getSchnorrAccount(ctx.pxe, bobsSecretKey, bobsPrivateSigningKey, Fr.random());
bobsAccountManager = getSchnorrAccount(pxe, bobsSecretKey, bobsPrivateSigningKey, Fr.random());
bobsAddress = bobsAccountManager.getCompleteAddress().address;
});

Expand Down Expand Up @@ -288,11 +289,13 @@ describe('e2e_fees_account_init', () => {
const instance = bobsAccountManager.getInstance();

// and gives the public keys to alice
// docs:start:register-recipient
const signingPubKey = new Schnorr().computePublicKey(bobsPrivateSigningKey);
const completeAddress = CompleteAddress.fromSecretKeyAndInstance(bobsSecretKey, instance);

// alice registers the keys in the PXE
await ctx.pxe.registerRecipient(completeAddress);
await pxe.registerRecipient(completeAddress);
// docs:end:register-recipient

// and deploys bob's account, paying the fee from her balance
const publicKeysHash = deriveKeys(bobsSecretKey).publicKeys.hash();
Expand Down Expand Up @@ -339,6 +342,6 @@ describe('e2e_fees_account_init', () => {
const note = new Note([new Fr(amount), secretHash]);
// this note isn't encrypted but we need to provide a registered public key
const extendedNote = new ExtendedNote(note, owner, bananaCoin.address, storageSlot, noteTypeId, txHash);
await ctx.pxe.addNote(extendedNote);
await pxe.addNote(extendedNote);
}
});
2 changes: 0 additions & 2 deletions yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
it('registers a recipient and returns it as a recipient only and not as an account', async () => {
const completeAddress = CompleteAddress.random();

// docs:start:register-recipient
await pxe.registerRecipient(completeAddress);
// docs:end:register-recipient

// Check that the recipient is correctly registered using the getAccounts and getRecipients methods
const accounts = await pxe.getRegisteredAccounts();
Expand Down

0 comments on commit f44993d

Please sign in to comment.