Skip to content

Commit b3fa010

Browse files
committed
WIP
1 parent d01600f commit b3fa010

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+306
-324
lines changed

yarn-project/archiver/src/archiver/archiver.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { InboxAbi } from '@aztec/l1-artifacts';
1010
import {
1111
ContractClassRegisteredEvent,
1212
PrivateFunctionBroadcastedEvent,
13-
UnconstrainedFunctionBroadcastedEvent,
13+
UtilityFunctionBroadcastedEvent,
1414
} from '@aztec/protocol-contracts/class-registerer';
1515
import {
1616
ContractInstanceDeployedEvent,
@@ -31,10 +31,10 @@ import {
3131
type ContractDataSource,
3232
type ContractInstanceWithAddress,
3333
type ExecutablePrivateFunctionWithMembershipProof,
34-
type UnconstrainedFunctionWithMembershipProof,
34+
type UtilityFunctionWithMembershipProof,
3535
computePublicBytecodeCommitment,
3636
isValidPrivateFunctionMembershipProof,
37-
isValidUnconstrainedFunctionMembershipProof,
37+
isValidUtilityFunctionMembershipProof,
3838
} from '@aztec/stdlib/contract';
3939
import {
4040
type L1RollupConstants,
@@ -984,7 +984,7 @@ class ArchiverStoreHelper
984984
}
985985

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

10051005
// Group all events by contract class id
10061006
for (const [classIdString, classEvents] of Object.entries(
1007-
groupBy([...privateFnEvents, ...unconstrainedFnEvents], e => e.contractClassId.toString()),
1007+
groupBy([...privateFnEvents, ...utilityFnEvents], e => e.contractClassId.toString()),
10081008
)) {
10091009
const contractClassId = Fr.fromHexString(classIdString);
10101010
const contractClass = await this.getContractClass(contractClassId);
@@ -1013,27 +1013,27 @@ class ArchiverStoreHelper
10131013
continue;
10141014
}
10151015

1016-
// Split private and unconstrained functions, and filter out invalid ones
1016+
// Split private and utility functions, and filter out invalid ones
10171017
const allFns = classEvents.map(e => e.toFunctionWithMembershipProof());
10181018
const privateFns = allFns.filter(
1019-
(fn): fn is ExecutablePrivateFunctionWithMembershipProof => 'unconstrainedFunctionsArtifactTreeRoot' in fn,
1019+
(fn): fn is ExecutablePrivateFunctionWithMembershipProof => 'utilityFunctionsTreeRoot' in fn,
10201020
);
1021-
const unconstrainedFns = allFns.filter(
1022-
(fn): fn is UnconstrainedFunctionWithMembershipProof => 'privateFunctionsArtifactTreeRoot' in fn,
1021+
const utilityFns = allFns.filter(
1022+
(fn): fn is UtilityFunctionWithMembershipProof => 'privateFunctionsArtifactTreeRoot' in fn,
10231023
);
10241024

10251025
const privateFunctionsWithValidity = await Promise.all(
10261026
privateFns.map(async fn => ({ fn, valid: await isValidPrivateFunctionMembershipProof(fn, contractClass) })),
10271027
);
10281028
const validPrivateFns = privateFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
1029-
const unconstrainedFunctionsWithValidity = await Promise.all(
1030-
unconstrainedFns.map(async fn => ({
1029+
const utilityFunctionsWithValidity = await Promise.all(
1030+
utilityFns.map(async fn => ({
10311031
fn,
1032-
valid: await isValidUnconstrainedFunctionMembershipProof(fn, contractClass),
1032+
valid: await isValidUtilityFunctionMembershipProof(fn, contractClass),
10331033
})),
10341034
);
1035-
const validUnconstrainedFns = unconstrainedFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
1036-
const validFnCount = validPrivateFns.length + validUnconstrainedFns.length;
1035+
const validUtilityFns = utilityFunctionsWithValidity.filter(({ valid }) => valid).map(({ fn }) => fn);
1036+
const validFnCount = validPrivateFns.length + validUtilityFns.length;
10371037
if (validFnCount !== allFns.length) {
10381038
this.#log.warn(`Skipping ${allFns.length - validFnCount} invalid functions`);
10391039
}
@@ -1042,7 +1042,7 @@ class ArchiverStoreHelper
10421042
if (validFnCount > 0) {
10431043
this.#log.verbose(`Storing ${validFnCount} functions for contract class ${contractClassId.toString()}`);
10441044
}
1045-
return await this.store.addFunctions(contractClassId, validPrivateFns, validUnconstrainedFns);
1045+
return await this.store.addFunctions(contractClassId, validPrivateFns, validUtilityFns);
10461046
}
10471047
return true;
10481048
}

yarn-project/archiver/src/archiver/archiver_store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
ContractInstanceUpdateWithAddress,
88
ContractInstanceWithAddress,
99
ExecutablePrivateFunctionWithMembershipProof,
10-
UnconstrainedFunctionWithMembershipProof,
10+
UtilityFunctionWithMembershipProof,
1111
} from '@aztec/stdlib/contract';
1212
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
1313
import type { LogFilter, PrivateLog, TxScopedL2Log } from '@aztec/stdlib/logs';
@@ -221,7 +221,7 @@ export interface ArchiverDataStore {
221221
addFunctions(
222222
contractClassId: Fr,
223223
privateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
224-
unconstrainedFunctions: UnconstrainedFunctionWithMembershipProof[],
224+
utilityFunctions: UtilityFunctionWithMembershipProof[],
225225
): Promise<boolean>;
226226

227227
/**

yarn-project/archiver/src/archiver/archiver_store_test_suite.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { InboxLeaf } from '@aztec/stdlib/messaging';
2222
import {
2323
makeContractClassPublic,
2424
makeExecutablePrivateFunctionWithMembershipProof,
25-
makeUnconstrainedFunctionWithMembershipProof,
25+
makeUtilityFunctionWithMembershipProof,
2626
} from '@aztec/stdlib/testing';
2727
import '@aztec/stdlib/testing/jest';
2828
import { TxEffect, TxHash } from '@aztec/stdlib/tx';
@@ -433,19 +433,19 @@ export function describeArchiverDataStore(
433433
expect(stored?.privateFunctions).toEqual(fns);
434434
});
435435

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

443-
it('does not duplicate unconstrained functions', async () => {
444-
const fns = times(3, makeUnconstrainedFunctionWithMembershipProof);
443+
it('does not duplicate utility functions', async () => {
444+
const fns = times(3, makeUtilityFunctionWithMembershipProof);
445445
await store.addFunctions(contractClass.id, [], fns.slice(0, 1));
446446
await store.addFunctions(contractClass.id, [], fns);
447447
const stored = await store.getContractClass(contractClass.id);
448-
expect(stored?.unconstrainedFunctions).toEqual(fns);
448+
expect(stored?.utilityFunctions).toEqual(fns);
449449
});
450450
});
451451

yarn-project/archiver/src/archiver/kv_archiver_store/contract_class_store.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
ContractClassPublic,
88
ContractClassPublicWithBlockNumber,
99
ExecutablePrivateFunctionWithMembershipProof,
10-
UnconstrainedFunctionWithMembershipProof,
10+
UtilityFunctionWithMembershipProof,
1111
} from '@aztec/stdlib/contract';
1212
import { Vector } from '@aztec/stdlib/types';
1313

@@ -60,7 +60,7 @@ export class ContractClassStore {
6060
async addFunctions(
6161
contractClassId: Fr,
6262
newPrivateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
63-
newUnconstrainedFunctions: UnconstrainedFunctionWithMembershipProof[],
63+
newUtilityFunctions: UtilityFunctionWithMembershipProof[],
6464
): Promise<boolean> {
6565
await this.db.transactionAsync(async () => {
6666
const existingClassBuffer = await this.#contractClasses.getAsync(contractClassId.toString());
@@ -69,19 +69,17 @@ export class ContractClassStore {
6969
}
7070

7171
const existingClass = deserializeContractClassPublic(existingClassBuffer);
72-
const { privateFunctions: existingPrivateFns, unconstrainedFunctions: existingUnconstrainedFns } = existingClass;
72+
const { privateFunctions: existingPrivateFns, utilityFunctions: existingUtilityFns } = existingClass;
7373

7474
const updatedClass: Omit<ContractClassPublicWithBlockNumber, 'id'> = {
7575
...existingClass,
7676
privateFunctions: [
7777
...existingPrivateFns,
7878
...newPrivateFunctions.filter(newFn => !existingPrivateFns.some(f => f.selector.equals(newFn.selector))),
7979
],
80-
unconstrainedFunctions: [
81-
...existingUnconstrainedFns,
82-
...newUnconstrainedFunctions.filter(
83-
newFn => !existingUnconstrainedFns.some(f => f.selector.equals(newFn.selector)),
84-
),
80+
utilityFunctions: [
81+
...existingUtilityFns,
82+
...newUtilityFunctions.filter(newFn => !existingUtilityFns.some(f => f.selector.equals(newFn.selector))),
8583
],
8684
};
8785
await this.#contractClasses.set(contractClassId.toString(), serializeContractClassPublic(updatedClass));
@@ -98,8 +96,8 @@ function serializeContractClassPublic(contractClass: Omit<ContractClassPublicWit
9896
contractClass.artifactHash,
9997
contractClass.privateFunctions.length,
10098
contractClass.privateFunctions.map(serializePrivateFunction),
101-
contractClass.unconstrainedFunctions.length,
102-
contractClass.unconstrainedFunctions.map(serializeUnconstrainedFunction),
99+
contractClass.utilityFunctions.length,
100+
contractClass.utilityFunctions.map(serializeUtilityFunction),
103101
contractClass.packedBytecode.length,
104102
contractClass.packedBytecode,
105103
contractClass.privateFunctionsRoot,
@@ -114,15 +112,15 @@ function serializePrivateFunction(fn: ExecutablePrivateFunctionWithMembershipPro
114112
fn.bytecode,
115113
fn.functionMetadataHash,
116114
fn.artifactMetadataHash,
117-
fn.unconstrainedFunctionsArtifactTreeRoot,
115+
fn.utilityFunctionsTreeRoot,
118116
new Vector(fn.privateFunctionTreeSiblingPath),
119117
fn.privateFunctionTreeLeafIndex,
120118
new Vector(fn.artifactTreeSiblingPath),
121119
fn.artifactTreeLeafIndex,
122120
);
123121
}
124122

125-
function serializeUnconstrainedFunction(fn: UnconstrainedFunctionWithMembershipProof): Buffer {
123+
function serializeUtilityFunction(fn: UtilityFunctionWithMembershipProof): Buffer {
126124
return serializeToBuffer(
127125
fn.selector,
128126
fn.bytecode.length,
@@ -142,7 +140,7 @@ function deserializeContractClassPublic(buffer: Buffer): Omit<ContractClassPubli
142140
version: reader.readUInt8() as 1,
143141
artifactHash: reader.readObject(Fr),
144142
privateFunctions: reader.readVector({ fromBuffer: deserializePrivateFunction }),
145-
unconstrainedFunctions: reader.readVector({ fromBuffer: deserializeUnconstrainedFunction }),
143+
utilityFunctions: reader.readVector({ fromBuffer: deserializeUtilityFunction }),
146144
packedBytecode: reader.readBuffer(),
147145
privateFunctionsRoot: reader.readObject(Fr),
148146
};
@@ -156,15 +154,15 @@ function deserializePrivateFunction(buffer: Buffer | BufferReader): ExecutablePr
156154
bytecode: reader.readBuffer(),
157155
functionMetadataHash: reader.readObject(Fr),
158156
artifactMetadataHash: reader.readObject(Fr),
159-
unconstrainedFunctionsArtifactTreeRoot: reader.readObject(Fr),
157+
utilityFunctionsTreeRoot: reader.readObject(Fr),
160158
privateFunctionTreeSiblingPath: reader.readVector(Fr),
161159
privateFunctionTreeLeafIndex: reader.readNumber(),
162160
artifactTreeSiblingPath: reader.readVector(Fr),
163161
artifactTreeLeafIndex: reader.readNumber(),
164162
};
165163
}
166164

167-
function deserializeUnconstrainedFunction(buffer: Buffer | BufferReader): UnconstrainedFunctionWithMembershipProof {
165+
function deserializeUtilityFunction(buffer: Buffer | BufferReader): UtilityFunctionWithMembershipProof {
168166
const reader = BufferReader.asReader(buffer);
169167
return {
170168
selector: reader.readObject(FunctionSelector),

yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
ContractInstanceUpdateWithAddress,
1111
ContractInstanceWithAddress,
1212
ExecutablePrivateFunctionWithMembershipProof,
13-
UnconstrainedFunctionWithMembershipProof,
13+
UtilityFunctionWithMembershipProof,
1414
} from '@aztec/stdlib/contract';
1515
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
1616
import { type LogFilter, PrivateLog, type TxScopedL2Log } from '@aztec/stdlib/logs';
@@ -117,9 +117,9 @@ export class KVArchiverDataStore implements ArchiverDataStore {
117117
addFunctions(
118118
contractClassId: Fr,
119119
privateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
120-
unconstrainedFunctions: UnconstrainedFunctionWithMembershipProof[],
120+
utilityFunctions: UtilityFunctionWithMembershipProof[],
121121
): Promise<boolean> {
122-
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, unconstrainedFunctions);
122+
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
123123
}
124124

125125
async addContractInstances(data: ContractInstanceWithAddress[], _blockNumber: number): Promise<boolean> {

yarn-project/archiver/src/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async function registerProtocolContracts(store: KVArchiverDataStore) {
7474
const contractClassPublic: ContractClassPublic = {
7575
...contract.contractClass,
7676
privateFunctions: [],
77-
unconstrainedFunctions: [],
77+
utilityFunctions: [],
7878
};
7979

8080
const publicFunctionSignatures = contract.artifact.functions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { registerContractClass } from '../deployment/register_class.js';
2-
export { broadcastPrivateFunction, broadcastUnconstrainedFunction } from '../deployment/broadcast_function.js';
2+
export { broadcastPrivateFunction, broadcastUtilityFunction } from '../deployment/broadcast_function.js';
33
export { deployInstance } from '../deployment/deploy_instance.js';
44
export { ContractDeployer } from '../deployment/contract_deployer.js';

yarn-project/aztec.js/src/contract/base_contract_interaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export abstract class BaseContractInteraction {
6868
// docs:start:send
6969
/**
7070
* Sends a transaction to the contract function with the specified options.
71-
* This function throws an error if called on an unconstrained function.
71+
* This function throws an error if called on a utility function.
7272
* It creates and signs the transaction if necessary, and returns a SentTx instance,
7373
* which can be used to track the transaction status, receipt, and events.
7474
* @param options - An optional object containing 'from' property representing

yarn-project/aztec.js/src/contract/batch_call.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,26 @@ export class BatchCall extends BaseContractInteraction {
4747
* Simulate a transaction and get its return values
4848
* Differs from prove in a few important ways:
4949
* 1. It returns the values of the function execution
50-
* 2. It supports `unconstrained`, `private` and `public` functions
50+
* 2. It supports `utility`, `private` and `public` functions
5151
*
5252
* @param options - An optional object containing additional configuration for the transaction.
5353
* @returns The result of the transaction as returned by the contract function.
5454
*/
5555
public async simulate(options: SimulateMethodOptions = {}): Promise<any> {
56-
const { indexedExecutionPayloads, unconstrained } = (await this.getRequests()).reduce<{
56+
const { indexedExecutionPayloads, utility } = (await this.getRequests()).reduce<{
5757
/** Keep track of the number of private calls to retrieve the return values */
5858
privateIndex: 0;
5959
/** Keep track of the number of public calls to retrieve the return values */
6060
publicIndex: 0;
6161
/** The public and private function execution requests in the batch */
6262
indexedExecutionPayloads: [ExecutionPayload, number, number][];
63-
/** The unconstrained function calls in the batch. */
64-
unconstrained: [FunctionCall, number][];
63+
/** The utility function calls in the batch. */
64+
utility: [FunctionCall, number][];
6565
}>(
6666
(acc, current, index) => {
6767
const call = current.calls[0];
68-
if (call.type === FunctionType.UNCONSTRAINED) {
69-
acc.unconstrained.push([call, index]);
68+
if (call.type === FunctionType.UTILITY) {
69+
acc.utility.push([call, index]);
7070
} else {
7171
acc.indexedExecutionPayloads.push([
7272
current,
@@ -76,7 +76,7 @@ export class BatchCall extends BaseContractInteraction {
7676
}
7777
return acc;
7878
},
79-
{ indexedExecutionPayloads: [], unconstrained: [], publicIndex: 0, privateIndex: 0 },
79+
{ indexedExecutionPayloads: [], utility: [], publicIndex: 0, privateIndex: 0 },
8080
);
8181

8282
const payloads = indexedExecutionPayloads.map(([request]) => request);
@@ -91,22 +91,22 @@ export class BatchCall extends BaseContractInteraction {
9191
const fee = await this.getFeeOptions(requestWithoutFee, userFee, {});
9292
const txRequest = await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable });
9393

94-
const unconstrainedCalls = unconstrained.map(
94+
const utilityCalls = utility.map(
9595
async ([call, index]) =>
9696
[
97-
await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.authWitnesses, options?.from),
97+
await this.wallet.simulateUtility(call.name, call.args, call.to, options?.authWitnesses, options?.from),
9898
index,
9999
] as const,
100100
);
101101

102-
const [unconstrainedResults, simulatedTx] = await Promise.all([
103-
Promise.all(unconstrainedCalls),
102+
const [utilityResults, simulatedTx] = await Promise.all([
103+
Promise.all(utilityCalls),
104104
this.wallet.simulateTx(txRequest, true, options?.from, options?.skipTxValidation),
105105
]);
106106

107107
const results: any[] = [];
108108

109-
unconstrainedResults.forEach(([result, index]) => {
109+
utilityResults.forEach(([result, index]) => {
110110
results[index] = result;
111111
});
112112
indexedExecutionPayloads.forEach(([request, callIndex, resultIndex]) => {

0 commit comments

Comments
 (0)