Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Nov 6, 2024
1 parent 9d3b351 commit 62ad893
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ContractArtifactDatabase {
* Adds a new contract artifact to the database or updates an existing one.
* @param id - Id of the corresponding contract class.
* @param contract - Contract artifact to add.
* @throws - If there are duplicate private function selectors.
*/
addContractArtifact(id: Fr, contract: ContractArtifact): Promise<void>;
/**
Expand Down
12 changes: 11 additions & 1 deletion yarn-project/pxe/src/database/kv_pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type TaggingSecret,
computePoint,
} from '@aztec/circuits.js';
import { type ContractArtifact } from '@aztec/foundation/abi';
import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/foundation/abi';
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
import { Fr } from '@aztec/foundation/fields';
import {
Expand Down Expand Up @@ -129,6 +129,16 @@ export class KVPxeDatabase implements PxeDatabase {
}

public async addContractArtifact(id: Fr, contract: ContractArtifact): Promise<void> {
const privateSelectors = contract.functions
.filter(functionArtifact => functionArtifact.functionType === FunctionType.PRIVATE)
.map(privateFunctionArtifact =>
FunctionSelector.fromNameAndParameters(privateFunctionArtifact.name, privateFunctionArtifact.parameters),
);

if (privateSelectors.length !== new Set(privateSelectors).size) {
throw new Error('Repeated function selectors of private functions');
}

await this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract));
}

Expand Down

0 comments on commit 62ad893

Please sign in to comment.