Skip to content

Commit

Permalink
Emitting owner address through a note (#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Jul 21, 2023
1 parent 5b522ee commit 47fc6ea
Show file tree
Hide file tree
Showing 26 changed files with 89 additions and 73 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ jobs:
name: "Test"
command: cond_spot_run_tests end-to-end e2e_nested_contract.test.ts

e2e-no-contract-account:
e2e-non-contract-account:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
Expand All @@ -493,7 +493,7 @@ jobs:
- *setup_env
- run:
name: "Test"
command: cond_spot_run_tests end-to-end e2e_no_contract_account.test.ts
command: cond_spot_run_tests end-to-end e2e_non_contract_account.test.ts

e2e-cross-chain-messaging:
docker:
Expand Down Expand Up @@ -842,7 +842,7 @@ workflows:
- e2e-zk-token-contract: *e2e_test
- e2e-block-building: *e2e_test
- e2e-nested-contract: *e2e_test
- e2e-no-contract-account: *e2e_test
- e2e-non-contract-account: *e2e_test
- e2e-public-token-contract: *e2e_test
- e2e-cross-chain-messaging: *e2e_test
- e2e-public-cross-chain-messaging: *e2e_test
Expand All @@ -862,7 +862,7 @@ workflows:
- e2e-zk-token-contract
- e2e-block-building
- e2e-nested-contract
- e2e-no-contract-account
- e2e-non-contract-account
- e2e-public-token-contract
- e2e-cross-chain-messaging
- e2e-public-cross-chain-messaging
Expand Down
13 changes: 10 additions & 3 deletions yarn-project/acir-simulator/src/client/private_execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,22 @@ export class PrivateFunctionExecution {
this.log(`Emitted unencrypted log: "${log.toString('ascii')}"`);
return Promise.resolve(ZERO_ACVM_FIELD);
},
emitEncryptedLog: ([acvmContractAddress], [acvmStorageSlot], [ownerX], [ownerY], acvmPreimage) => {
emitEncryptedLog: (
[acvmContractAddress],
[acvmStorageSlot],
[owner],
[encPubKeyX],
[encPubKeyY],
acvmPreimage,
) => {
const contractAddress = AztecAddress.fromBuffer(convertACVMFieldToBuffer(acvmContractAddress));
const ownerAddress = AztecAddress.ZERO; // TODO(#1021): Needs to be emitted
const ownerAddress = AztecAddress.fromBuffer(convertACVMFieldToBuffer(owner));
const storageSlot = fromACVMField(acvmStorageSlot);
const preimage = acvmPreimage.map(f => fromACVMField(f));

const notePreimage = new NotePreimage(preimage);
const noteSpendingInfo = new NoteSpendingInfo(notePreimage, contractAddress, ownerAddress, storageSlot);
const ownerPublicKey = new Point(fromACVMField(ownerX), fromACVMField(ownerY));
const ownerPublicKey = new Point(fromACVMField(encPubKeyX), fromACVMField(encPubKeyY));

const encryptedNotePreimage = noteSpendingInfo.toEncryptedBuffer(ownerPublicKey, this.curve);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class AztecRPCServer implements AztecRPC {
// );
// }
await this.db.addPublicKeyAndPartialAddress(address, pubKey, partialContractAddress);
this.synchroniser.addAccount(pubKey, address, this.keyStore);
this.synchroniser.addAccount(pubKey, this.keyStore);
this.log.info(`Added account ${address.toString()}`);
return address;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ describe('Note Processor', () => {
block.startPrivateDataTreeSnapshot.nextAvailableLeafIndex = firstBlockDataStartIndex + i * numCommitmentsPerBlock;

const newNotes = Array(numCommitmentsPerBlock).fill(0).map(NoteSpendingInfo.random);
// Set the note owners to ownerAddress.
newNotes.forEach(n => (n.ownerAddress = ownerAddress));

block.newCommitments = newNotes.map(n => computeMockNoteHash(n.notePreimage.items));

const isTargetBlock = i === prependedBlocks;
Expand Down Expand Up @@ -120,7 +123,7 @@ describe('Note Processor', () => {
keyStore = mock<KeyStore>();
simulator = mock<AcirSimulator>();
keyStore.getAccountPrivateKey.mockResolvedValue(owner.getPrivateKey());
noteProcessor = new NoteProcessor(owner.getPublicKey(), ownerAddress, keyStore, database, aztecNode, simulator);
noteProcessor = new NoteProcessor(owner.getPublicKey(), keyStore, database, aztecNode, simulator);

simulator.computeNoteHashAndNullifier.mockImplementation((...args) =>
Promise.resolve({
Expand Down
5 changes: 2 additions & 3 deletions yarn-project/aztec-rpc/src/note_processor/note_processor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AztecAddress, CircuitsWasm, MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX } from '@aztec/circuits.js';
import { CircuitsWasm, MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX } from '@aztec/circuits.js';
import { computeCommitmentNonce, siloNullifier } from '@aztec/circuits.js/abis';
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
import { Fr } from '@aztec/foundation/fields';
Expand Down Expand Up @@ -41,7 +41,6 @@ export class NoteProcessor {
* The public counterpart to the private key to be used in note decryption.
*/
public readonly publicKey: PublicKey,
private address: AztecAddress, // TODO: Remove once owner addresses are emitted by contracts
private keyStore: KeyStore,
private db: Database,
private node: AztecNode,
Expand Down Expand Up @@ -236,7 +235,7 @@ export class NoteProcessor {
txHash,
blockHash: blockContext.getBlockHash(),
blockNumber: blockContext.block.number,
origin: this.address,
origin: noteSpendingInfo.ownerAddress,
contractAddress,
error: '',
});
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-rpc/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export class SimulatorOracle implements DBOracle {
}

/**
* Retreives the L1ToL2Message associated with a specific message key
* Retrieves the L1ToL2Message associated with a specific message key
* Throws an error if the message key is not found
*
* @param msgKey - The key of the message to be retreived
* @param msgKey - The key of the message to be retrieved
* @returns A promise that resolves to the message data, a sibling path and the
* index of the message in the l1ToL2MessagesTree
*/
Expand Down
5 changes: 2 additions & 3 deletions yarn-project/aztec-rpc/src/synchroniser/synchroniser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,15 @@ export class Synchroniser {
* The method resolves immediately after pushing the new note processor.
*
* @param publicKey - The public key for the account.
* @param address - The address for the account.
* @param keyStore - The key store.
* @returns A promise that resolves once the account is added to the Synchroniser.
*/
public addAccount(publicKey: PublicKey, address: AztecAddress, keyStore: KeyStore) {
public addAccount(publicKey: PublicKey, keyStore: KeyStore) {
const processor = this.noteProcessors.find(x => x.publicKey.equals(publicKey));
if (processor) {
return;
}
this.noteProcessors.push(new NoteProcessor(publicKey, address, keyStore, this.db, this.node));
this.noteProcessors.push(new NoteProcessor(publicKey, keyStore, this.db, this.node));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DeployMethod } from './deploy_method.js';
* A class for deploying contract.
*/
export class ContractDeployer {
// TODO: remove this?
constructor(private abi: ContractAbi, private arc: AztecRPC, private publicKey?: PublicKey) {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SignerlessWallet extends BaseWallet {
}
}

describe('e2e_no_contract_account', () => {
describe('e2e_non_contract_account', () => {
let aztecNode: AztecNodeService | undefined;
let aztecRpcServer: AztecRPC;
let wallet: Wallet;
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('e2e_no_contract_account', () => {
await pokerWallet.addAccount(pokerPrivKey, poker, new Fr(0n));

logger(`Deploying L2 contract...`);
const tx = PokeableTokenContract.deploy(aztecRpcServer, initialBalance, sender, recipient, pokerPubKey).send();
const tx = PokeableTokenContract.deploy(aztecRpcServer, initialBalance, sender, recipient, poker).send();
const receipt = await tx.getReceipt();
contract = new PokeableTokenContract(receipt.contractAddress!, wallet);
await tx.isMined(0, 0.1);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export async function setupAztecRPCServer(
});
}

// We do this in a seperate loop to try and get all transactions into the same rollup.
// We do this in a separate loop to try and get all transactions into the same rollup.
// Doing this here will submit the transactions with minimal delay between them.
for (const context of txContexts) {
logger(`Deploying account contract for ${context.deploymentData.address.toString()}`);
Expand Down
Loading

0 comments on commit 47fc6ea

Please sign in to comment.