Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions l1-contracts/src/core/libraries/Decoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ library Decoder {
* newContractDataKernel2.ethAddress (padded to 32 bytes), ____
* encryptedLogsHashKernel1, |
* encryptedLogsHashKernel2, |=> Computed below from logs' preimages.
* unencryptedLogsHashKernel1, |
* unencryptedLogsHashKernel2 ___|
* unencryptedLogsHashKernel1, |
* unencryptedLogsHashKernel2 ____|
* );
* Note that we always read data, the l2Block (atm) must therefore include dummy or zero-notes for
* Zero values.
Expand Down
20 changes: 19 additions & 1 deletion l1-contracts/src/periphery/ContractDeploymentEmitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,33 @@ contract ContractDeploymentEmitter is IContractDeploymentEmitter {
* @param _aztecAddress - The address of the L2 counterparty
* @param _portalAddress - The address of the L1 counterparty
* @param _l2BlockHash - The hash of the L2 block that this is related to
* @param _partialAddress - The partial address of the deployed contract
* @param _pubKeyX - The x coordinate of the contract's public key
* @param _pubKeyY - The y coordinate of the contract's public key
* @param _acir - The acir bytecode of the L2 contract
* @dev See the link bellow for more info on partial address and public key:
* https://github.com/AztecProtocol/aztec-packages/blob/master/docs/docs/concepts/foundation/accounts/keys.md#addresses-partial-addresses-and-public-keys
* TODO: replace the link above with the link to deployed docs
*/
function emitContractDeployment(
uint256 _l2BlockNum,
bytes32 _aztecAddress,
address _portalAddress,
bytes32 _l2BlockHash,
bytes32 _partialAddress,
bytes32 _pubKeyX,
bytes32 _pubKeyY,
bytes calldata _acir
) external override(IContractDeploymentEmitter) {
emit ContractDeployment(_l2BlockNum, _aztecAddress, _portalAddress, _l2BlockHash, _acir);
emit ContractDeployment(
_l2BlockNum,
_aztecAddress,
_portalAddress,
_l2BlockHash,
_partialAddress,
_pubKeyX,
_pubKeyY,
_acir
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ interface IContractDeploymentEmitter {
* @param aztecAddress - The address of the L2 counterparty
* @param portalAddress - The address of the L1 counterparty
* @param l2BlockHash - The hash of the L2 block that this is related to
* @param partialAddress - The partial address of the deployed contract
* @param pubKeyX - The x coordinate of the contract's public key
* @param pubKeyY - The y coordinate of the contract's public key
* @param acir - The acir bytecode of the L2 contract
* @dev See the link bellow for more info on partial address and public key:
* https://github.com/AztecProtocol/aztec-packages/blob/master/docs/docs/concepts/foundation/accounts/keys.md#addresses-partial-addresses-and-public-keys
* TODO: replace the link above with the link to deployed docs
*/
event ContractDeployment(
uint256 indexed l2BlockNum,
bytes32 indexed aztecAddress,
address indexed portalAddress,
bytes32 l2BlockHash,
bytes32 partialAddress,
bytes32 pubKeyX,
bytes32 pubKeyY,
bytes acir
);

Expand All @@ -30,6 +39,9 @@ interface IContractDeploymentEmitter {
bytes32 _aztecAddress,
address _portalAddress,
bytes32 _l2BlockHash,
bytes32 _partialAddress,
bytes32 _pubKeyX,
bytes32 _pubKeyY,
bytes calldata _acir
) external;
}
26 changes: 8 additions & 18 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { sleep } from '@aztec/foundation/sleep';
import { ContractDeploymentEmitterAbi, InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import {
ContractData,
ContractDataAndBytecode,
EncodedContractFunction,
L2Block,
L2BlockL2Logs,
LogType,
} from '@aztec/types';
import { ExtendedContractData, L2Block, L2BlockL2Logs, LogType } from '@aztec/types';

import { MockProxy, mock } from 'jest-mock-extended';
import { Chain, HttpTransport, Log, PublicClient, Transaction, encodeFunctionData, toHex } from 'viem';
Expand Down Expand Up @@ -155,21 +148,18 @@ function makeL2BlockProcessedEvent(l1BlockNum: bigint, l2BlockNum: bigint) {
* @returns An ContractDeployment event.
*/
function makeContractDeploymentEvent(l1BlockNum: bigint, l2Block: L2Block) {
// const contractData = ContractData.random();
const aztecAddress = AztecAddress.random();
const portalAddress = EthAddress.random();
const contractData = new ContractDataAndBytecode(new ContractData(aztecAddress, portalAddress), [
EncodedContractFunction.random(),
EncodedContractFunction.random(),
]);
const acir = contractData.bytecode?.toString('hex');
const extendedContractData = ExtendedContractData.random();
const acir = extendedContractData.bytecode?.toString('hex');
return {
blockNumber: l1BlockNum,
args: {
l2BlockNum: BigInt(l2Block.number),
aztecAddress: aztecAddress.toString(),
portalAddress: portalAddress.toString(),
aztecAddress: extendedContractData.contractData.contractAddress.toString(),
portalAddress: extendedContractData.contractData.portalContractAddress.toString(),
l2BlockHash: `0x${l2Block.getCalldataHash().toString('hex')}`,
partialAddress: extendedContractData.partialAddress.toString(true),
pubKeyX: extendedContractData.publicKey.x.toString(true),
pubKeyY: extendedContractData.publicKey.y.toString(true),
acir: '0x' + acir,
},
transactionHash: `0x${l2Block.number}`,
Expand Down
21 changes: 10 additions & 11 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
import { RunningPromise } from '@aztec/foundation/running-promise';
import {
ContractData,
ContractDataAndBytecode,
ContractDataSource,
EncodedContractFunction,
ExtendedContractData,
INITIAL_L2_BLOCK_NUM,
L1ToL2Message,
L1ToL2MessageSource,
Expand Down Expand Up @@ -224,9 +224,9 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
// store contracts for which we have retrieved L2 blocks
const lastKnownL2BlockNum = retrievedBlocks.retrievedData[retrievedBlocks.retrievedData.length - 1].number;
retrievedContracts.retrievedData.forEach(async ([contracts, l2BlockNum], index) => {
this.log(`Retrieved contract data and bytecode for l2 block number: ${index}`);
this.log(`Retrieved extended contract data for l2 block number: ${index}`);
if (l2BlockNum <= lastKnownL2BlockNum) {
await this.store.addContractDataAndBytecode(contracts, l2BlockNum);
await this.store.addExtendedContractData(contracts, l2BlockNum);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, the name DataAndBytecode has finally been vanquished! :-P

}
});

Expand Down Expand Up @@ -293,22 +293,21 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
}

/**
* Lookup the L2 contract data for this contract.
* Contains the contract's public function bytecode.
* Get the extended contract data for this contract.
* @param contractAddress - The contract data address.
* @returns The contract data.
* @returns The extended contract data or undefined if not found.
*/
public getContractDataAndBytecode(contractAddress: AztecAddress): Promise<ContractDataAndBytecode | undefined> {
return this.store.getContractDataAndBytecode(contractAddress);
getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
return this.store.getExtendedContractData(contractAddress);
}

/**
* Lookup all contract data in an L2 block.
* @param blockNum - The block number to get all contract data from.
* @returns All new contract data in the block (if found).
*/
public getContractDataAndBytecodeInBlock(blockNum: number): Promise<ContractDataAndBytecode[]> {
return this.store.getContractDataAndBytecodeInBlock(blockNum);
public getExtendedContractDataInBlock(blockNum: number): Promise<ExtendedContractData[]> {
return this.store.getExtendedContractDataInBlock(blockNum);
}

/**
Expand Down Expand Up @@ -341,7 +340,7 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
contractAddress: AztecAddress,
selector: FunctionSelector,
): Promise<EncodedContractFunction | undefined> {
const contractData = await this.getContractDataAndBytecode(contractAddress);
const contractData = await this.getExtendedContractData(contractAddress);
return contractData?.getPublicFunction(selector);
}

Expand Down
54 changes: 27 additions & 27 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import {
ContractData,
ContractDataAndBytecode,
ExtendedContractData,
INITIAL_L2_BLOCK_NUM,
L1ToL2Message,
L2Block,
Expand All @@ -16,7 +16,7 @@ import { L1ToL2MessageStore, PendingL1ToL2MessageStore } from './l1_to_l2_messag

/**
* Interface describing a data store to be used by the archiver to store all its relevant data
* (blocks, encrypted logs, aztec contract data and bytecode).
* (blocks, encrypted logs, aztec contract data extended contract data).
*/
export interface ArchiverDataStore {
/**
Expand Down Expand Up @@ -95,26 +95,26 @@ export interface ArchiverDataStore {
getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]>;

/**
* Store new Contract data and bytecode from an L2 block to the store's list.
* Add new extended contract data from an L2 block to the store's list.
* @param data - List of contracts' data to be added.
* @param blockNum - Number of the L2 block the contract data was deployed in.
* @returns True if the operation is successful.
*/
addContractDataAndBytecode(data: ContractDataAndBytecode[], blockNum: number): Promise<boolean>;
addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean>;

/**
* Lookup the L2 contract data for a contract address.
* Get the extended contract data for this contract.
* @param contractAddress - The contract data address.
* @returns The contract's public data.
* @returns The extended contract data or undefined if not found.
*/
getContractDataAndBytecode(contractAddress: AztecAddress): Promise<ContractDataAndBytecode | undefined>;
getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined>;

/**
* Lookup all contract data and bytecode in an L2 block.
* Lookup all extended contract data in an L2 block.
* @param blockNum - The block number to get all contract data from.
* @returns All contract data and bytecode in the block (if found).
* @returns All extended contract data in the block (if found).
*/
getContractDataAndBytecodeInBlock(blockNum: number): Promise<ContractDataAndBytecode[]>;
getExtendedContractDataInBlock(blockNum: number): Promise<ExtendedContractData[]>;

/**
* Get basic info for an L2 contract.
Expand Down Expand Up @@ -172,14 +172,14 @@ export class MemoryArchiverStore implements ArchiverDataStore {
private unencryptedLogs: L2BlockL2Logs[] = [];

/**
* A sparse array containing all the contract data and bytecode that have been fetched so far.
* A sparse array containing all the extended contract data that have been fetched so far.
*/
private contractDataAndBytecodeByBlock: (ContractDataAndBytecode[] | undefined)[] = [];
private extendedContractDataByBlock: (ExtendedContractData[] | undefined)[] = [];

/**
* A mapping of contract address to contract data and bytecode.
* A mapping of contract address to extended contract data.
*/
private contractDataAndBytecode: Map<string, ContractDataAndBytecode> = new Map();
private extendedContractData: Map<string, ExtendedContractData> = new Map();

/**
* Contains all the confirmed L1 to L2 messages (i.e. messages that were consumed in an L2 block)
Expand Down Expand Up @@ -255,23 +255,23 @@ export class MemoryArchiverStore implements ArchiverDataStore {
}

/**
* Store new Contract data and bytecode from an L2 block to the store's list.
* Store new extended contract data from an L2 block to the store's list.
* @param data - List of contracts' data to be added.
* @param blockNum - Number of the L2 block the contract data was deployed in.
* @returns True if the operation is successful (always in this implementation).
*/
public addContractDataAndBytecode(data: ContractDataAndBytecode[], blockNum: number): Promise<boolean> {
public addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean> {
// Add to the contracts mapping
for (const contractData of data) {
const key = contractData.contractData.contractAddress.toString();
this.contractDataAndBytecode.set(key, contractData);
this.extendedContractData.set(key, contractData);
}

// Add the index per block
if (this.contractDataAndBytecodeByBlock[blockNum]?.length) {
this.contractDataAndBytecodeByBlock[blockNum]?.push(...data);
if (this.extendedContractDataByBlock[blockNum]?.length) {
this.extendedContractDataByBlock[blockNum]?.push(...data);
} else {
this.contractDataAndBytecodeByBlock[blockNum] = [...data];
this.extendedContractDataByBlock[blockNum] = [...data];
}
return Promise.resolve(true);
}
Expand Down Expand Up @@ -348,25 +348,25 @@ export class MemoryArchiverStore implements ArchiverDataStore {
}

/**
* Lookup the L2 contract data for a contract address.
* Get the extended contract data for this contract.
* @param contractAddress - The contract data address.
* @returns The contract's public data.
* @returns The extended contract data or undefined if not found.
*/
public getContractDataAndBytecode(contractAddress: AztecAddress): Promise<ContractDataAndBytecode | undefined> {
const result = this.contractDataAndBytecode.get(contractAddress.toString());
getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
const result = this.extendedContractData.get(contractAddress.toString());
return Promise.resolve(result);
}

/**
* Lookup all contract data in an L2 block.
* @param blockNum - The block number to get all contract data from.
* @returns All contract data and bytecode in the block (if found).
* @returns All extended contract data in the block (if found).
*/
public getContractDataAndBytecodeInBlock(blockNum: number): Promise<ContractDataAndBytecode[]> {
public getExtendedContractDataInBlock(blockNum: number): Promise<ExtendedContractData[]> {
if (blockNum > this.l2Blocks.length) {
return Promise.resolve([]);
}
return Promise.resolve(this.contractDataAndBytecodeByBlock[blockNum] || []);
return Promise.resolve(this.extendedContractDataByBlock[blockNum] || []);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/archiver/src/archiver/data_retrieval.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { ContractDataAndBytecode, L1ToL2Message, L2Block } from '@aztec/types';
import { ExtendedContractData, L1ToL2Message, L2Block } from '@aztec/types';

import { PublicClient } from 'viem';

Expand Down Expand Up @@ -73,7 +73,7 @@ export async function retrieveBlocks(
* @param currentBlockNumber - Latest available block number in the ETH node.
* @param searchStartBlock - The block number to use for starting the search.
* @param blockHashMapping - A mapping from block number to relevant block hash.
* @returns An array of ContractDataAndBytecode and their equivalent L2 Block number along with the next eth block to search from..
* @returns An array of ExtendedContractData and their equivalent L2 Block number along with the next eth block to search from..
*/
export async function retrieveNewContractData(
publicClient: PublicClient,
Expand All @@ -82,8 +82,8 @@ export async function retrieveNewContractData(
currentBlockNumber: bigint,
searchStartBlock: bigint,
blockHashMapping: { [key: number]: Buffer | undefined },
): Promise<DataRetrieval<[ContractDataAndBytecode[], number]>> {
let retrievedNewContracts: [ContractDataAndBytecode[], number][] = [];
): Promise<DataRetrieval<[ExtendedContractData[], number]>> {
let retrievedNewContracts: [ExtendedContractData[], number][] = [];
do {
if (searchStartBlock > currentBlockNumber) {
break;
Expand Down
Loading