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
8 changes: 4 additions & 4 deletions boxes/boxes/react/src/pages/contract.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState } from 'react';
import { Contract } from '@aztec/aztec.js';
import { Contract, FunctionType } from '@aztec/aztec.js';
import { useNumber } from '../hooks/useNumber';

const IGNORE_FUNCTIONS = ['constructor', 'process_log', 'sync_notes'];
const IGNORE_FUNCTIONS = ['constructor', 'sync_notes'];

export function ContractComponent({ contract }: { contract: Contract }) {
const [showInput, setShowInput] = useState(true);
Expand All @@ -18,7 +18,7 @@ export function ContractComponent({ contract }: { contract: Contract }) {
<select name="viewFunctions" id="viewFunctions">
{filteredInterface.map(
(fn, index) =>
fn.functionType === 'unconstrained' && (
fn.functionType === FunctionType.UTILITY && (
<option key={index} value={index}>
{fn.name}
</option>
Expand All @@ -35,7 +35,7 @@ export function ContractComponent({ contract }: { contract: Contract }) {
<select name="functions" id="functions" onChange={() => setShowInput(true)}>
{filteredInterface.map(
(fn, index) =>
fn.functionType !== 'unconstrained' && (
fn.functionType !== FunctionType.UTILITY && (
<option key={index} value={index}>
{fn.name}
</option>
Expand Down
8 changes: 4 additions & 4 deletions boxes/boxes/vite/src/pages/contract.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState } from "react";
import { Contract } from "@aztec/aztec.js";
import { Contract, FunctionType } from "@aztec/aztec.js";
import { useNumber } from "../hooks/useNumber";

const IGNORE_FUNCTIONS = ["constructor", "process_log", "sync_notes"];
const IGNORE_FUNCTIONS = ["constructor", "sync_notes"];

export function ContractComponent({ contract }: { contract: Contract }) {
const [showInput, setShowInput] = useState(true);
Expand All @@ -20,7 +20,7 @@ export function ContractComponent({ contract }: { contract: Contract }) {
<select name="viewFunctions" id="viewFunctions">
{filteredInterface.map(
(fn, index) =>
fn.functionType === "unconstrained" && (
fn.functionType === FunctionType.UTILITY && (
<option key={index} value={index}>
{fn.name}
</option>
Expand All @@ -41,7 +41,7 @@ export function ContractComponent({ contract }: { contract: Contract }) {
>
{filteredInterface.map(
(fn, index) =>
fn.functionType !== "unconstrained" && (
fn.functionType !== FunctionType.UTILITY && (
<option key={index} value={index}>
{fn.name}
</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl UtilityContext {
pub unconstrained fn new() -> Self {
// We could call these oracles on the getters instead of at creation, which makes sense given that they might
// not even be accessed. However any performance gains are minimal, and we'd rather fail early if a user
// incorrectly attempts to create an UtilityContext in an environment in which these oracles are not
// incorrectly attempts to create a UtilityContext in an environment in which these oracles are not
// available.
let block_number = get_block_number();
let contract_address = get_contract_address();
Expand Down
23 changes: 12 additions & 11 deletions playground/src/components/contract/contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
loadContractArtifact,
getAllFunctionAbis,
type FunctionAbi,
FunctionType,
} from '@aztec/aztec.js';
import { AztecContext } from '../../aztecEnv';
import Button from '@mui/material/Button';
Expand Down Expand Up @@ -131,7 +132,7 @@ export function ContractComponent() {
searchTerm: '',
private: true,
public: true,
unconstrained: true,
utility: true,
});

const [isLoadingArtifact, setIsLoadingArtifact] = useState(false);
Expand Down Expand Up @@ -173,7 +174,7 @@ export function ContractComponent() {
searchTerm: '',
private: true,
public: true,
unconstrained: true,
utility: true,
});
setIsLoadingArtifact(false);
};
Expand Down Expand Up @@ -417,16 +418,16 @@ export function ContractComponent() {
control={
<Checkbox
sx={{ padding: 0 }}
checked={filters.unconstrained}
checked={filters.utility}
onChange={e =>
setFilters({
...filters,
unconstrained: e.target.checked,
utility: e.target.checked,
})
}
/>
}
label="Unconstrained"
label="Utility"
/>
</div>
</FormGroup>
Expand All @@ -437,9 +438,9 @@ export function ContractComponent() {
fn =>
!fn.isInternal &&
!FORBIDDEN_FUNCTIONS.includes(fn.name) &&
((filters.private && fn.functionType === 'private') ||
(filters.public && fn.functionType === 'public') ||
(filters.unconstrained && fn.functionType === 'unconstrained')) &&
((filters.private && fn.functionType === FunctionType.PRIVATE) ||
(filters.public && fn.functionType === FunctionType.PUBLIC) ||
(filters.utility && fn.functionType === FunctionType.UTILITY)) &&
(filters.searchTerm === '' || fn.name.includes(filters.searchTerm)),
)
.map(fn => (
Expand Down Expand Up @@ -517,7 +518,7 @@ export function ContractComponent() {
Simulate
</Button>
<Button
disabled={!wallet || !currentContract || isWorking || fn.functionType === 'unconstrained'}
disabled={!wallet || !currentContract || isWorking || fn.functionType === FunctionType.UTILITY}
size="small"
color="secondary"
variant="contained"
Expand All @@ -527,12 +528,12 @@ export function ContractComponent() {
Send
</Button>
<Button
disabled={!wallet || !currentContract || isWorking || fn.functionType === 'unconstrained'}
disabled={!wallet || !currentContract || isWorking || fn.functionType === FunctionType.UTILITY}
size="small"
color="secondary"
variant="contained"
onClick={() =>
handleAuthwitFnDataChanged(fn.name, parameters[fn.name], fn.functionType === 'private')
handleAuthwitFnDataChanged(fn.name, parameters[fn.name], fn.functionType === FunctionType.PRIVATE)
}
endIcon={<VpnKeyIcon />}
>
Expand Down
38 changes: 19 additions & 19 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { InboxAbi } from '@aztec/l1-artifacts';
import {
ContractClassRegisteredEvent,
PrivateFunctionBroadcastedEvent,
UnconstrainedFunctionBroadcastedEvent,
UtilityFunctionBroadcastedEvent,
} from '@aztec/protocol-contracts/class-registerer';
import {
ContractInstanceDeployedEvent,
Expand All @@ -31,10 +31,10 @@ import {
type ContractDataSource,
type ContractInstanceWithAddress,
type ExecutablePrivateFunctionWithMembershipProof,
type UnconstrainedFunctionWithMembershipProof,
type UtilityFunctionWithMembershipProof,
computePublicBytecodeCommitment,
isValidPrivateFunctionMembershipProof,
isValidUnconstrainedFunctionMembershipProof,
isValidUtilityFunctionMembershipProof,
} from '@aztec/stdlib/contract';
import {
type L1RollupConstants,
Expand Down Expand Up @@ -991,7 +991,7 @@ class ArchiverStoreHelper
}

/**
* Stores the functions that was broadcasted individually
* Stores the functions that were broadcasted individually
*
* @dev Beware that there is not a delete variant of this, since they are added to contract classes
* and will be deleted as part of the class if needed.
Expand All @@ -1001,17 +1001,17 @@ class ArchiverStoreHelper
* @returns
*/
async #storeBroadcastedIndividualFunctions(allLogs: ContractClassLog[], _blockNum: number) {
// Filter out private and unconstrained function broadcast events
// Filter out private and utility function broadcast events
const privateFnEvents = allLogs
.filter(log => PrivateFunctionBroadcastedEvent.isPrivateFunctionBroadcastedEvent(log))
.map(log => PrivateFunctionBroadcastedEvent.fromLog(log));
const unconstrainedFnEvents = allLogs
.filter(log => UnconstrainedFunctionBroadcastedEvent.isUnconstrainedFunctionBroadcastedEvent(log))
.map(log => UnconstrainedFunctionBroadcastedEvent.fromLog(log));
const utilityFnEvents = allLogs
.filter(log => UtilityFunctionBroadcastedEvent.isUtilityFunctionBroadcastedEvent(log))
.map(log => UtilityFunctionBroadcastedEvent.fromLog(log));

// Group all events by contract class id
for (const [classIdString, classEvents] of Object.entries(
groupBy([...privateFnEvents, ...unconstrainedFnEvents], e => e.contractClassId.toString()),
groupBy([...privateFnEvents, ...utilityFnEvents], e => e.contractClassId.toString()),
)) {
const contractClassId = Fr.fromHexString(classIdString);
const contractClass = await this.getContractClass(contractClassId);
Expand All @@ -1020,27 +1020,27 @@ class ArchiverStoreHelper
continue;
}

// Split private and unconstrained functions, and filter out invalid ones
// Split private and utility functions, and filter out invalid ones
const allFns = classEvents.map(e => e.toFunctionWithMembershipProof());
const privateFns = allFns.filter(
(fn): fn is ExecutablePrivateFunctionWithMembershipProof => 'unconstrainedFunctionsArtifactTreeRoot' in fn,
(fn): fn is ExecutablePrivateFunctionWithMembershipProof => 'utilityFunctionsTreeRoot' in fn,
);
const unconstrainedFns = allFns.filter(
(fn): fn is UnconstrainedFunctionWithMembershipProof => 'privateFunctionsArtifactTreeRoot' in fn,
const utilityFns = allFns.filter(
(fn): fn is UtilityFunctionWithMembershipProof => 'privateFunctionsArtifactTreeRoot' in fn,
);

const privateFunctionsWithValidity = await Promise.all(
privateFns.map(async fn => ({ fn, valid: await isValidPrivateFunctionMembershipProof(fn, contractClass) })),
);
const validPrivateFns = privateFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
const unconstrainedFunctionsWithValidity = await Promise.all(
unconstrainedFns.map(async fn => ({
const utilityFunctionsWithValidity = await Promise.all(
utilityFns.map(async fn => ({
fn,
valid: await isValidUnconstrainedFunctionMembershipProof(fn, contractClass),
valid: await isValidUtilityFunctionMembershipProof(fn, contractClass),
})),
);
const validUnconstrainedFns = unconstrainedFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
const validFnCount = validPrivateFns.length + validUnconstrainedFns.length;
const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
const validFnCount = validPrivateFns.length + validUtilityFns.length;
if (validFnCount !== allFns.length) {
this.#log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
}
Expand All @@ -1049,7 +1049,7 @@ class ArchiverStoreHelper
if (validFnCount > 0) {
this.#log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
}
return await this.store.addFunctions(contractClassId, validPrivateFns, validUnconstrainedFns);
return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
ContractInstanceUpdateWithAddress,
ContractInstanceWithAddress,
ExecutablePrivateFunctionWithMembershipProof,
UnconstrainedFunctionWithMembershipProof,
UtilityFunctionWithMembershipProof,
} from '@aztec/stdlib/contract';
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
import type { LogFilter, PrivateLog, TxScopedL2Log } from '@aztec/stdlib/logs';
Expand Down Expand Up @@ -221,7 +221,7 @@ export interface ArchiverDataStore {
addFunctions(
contractClassId: Fr,
privateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
unconstrainedFunctions: UnconstrainedFunctionWithMembershipProof[],
utilityFunctions: UtilityFunctionWithMembershipProof[],
): Promise<boolean>;

/**
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/archiver/src/archiver/archiver_store_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { InboxLeaf } from '@aztec/stdlib/messaging';
import {
makeContractClassPublic,
makeExecutablePrivateFunctionWithMembershipProof,
makeUnconstrainedFunctionWithMembershipProof,
makeUtilityFunctionWithMembershipProof,
} from '@aztec/stdlib/testing';
import '@aztec/stdlib/testing/jest';
import { TxEffect, TxHash } from '@aztec/stdlib/tx';
Expand Down Expand Up @@ -433,19 +433,19 @@ export function describeArchiverDataStore(
expect(stored?.privateFunctions).toEqual(fns);
});

it('adds new unconstrained functions', async () => {
const fns = times(3, makeUnconstrainedFunctionWithMembershipProof);
it('adds new utility functions', async () => {
const fns = times(3, makeUtilityFunctionWithMembershipProof);
await store.addFunctions(contractClass.id, [], fns);
const stored = await store.getContractClass(contractClass.id);
expect(stored?.unconstrainedFunctions).toEqual(fns);
expect(stored?.utilityFunctions).toEqual(fns);
});

it('does not duplicate unconstrained functions', async () => {
const fns = times(3, makeUnconstrainedFunctionWithMembershipProof);
it('does not duplicate utility functions', async () => {
const fns = times(3, makeUtilityFunctionWithMembershipProof);
await store.addFunctions(contractClass.id, [], fns.slice(0, 1));
await store.addFunctions(contractClass.id, [], fns);
const stored = await store.getContractClass(contractClass.id);
expect(stored?.unconstrainedFunctions).toEqual(fns);
expect(stored?.utilityFunctions).toEqual(fns);
});
});

Expand Down
Loading
Loading