@aztec/stdlib 0.83.1 → 0.84.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dest/abi/abi.d.ts +2 -2
  2. package/dest/abi/abi.d.ts.map +1 -1
  3. package/dest/abi/abi.js +1 -1
  4. package/dest/abi/contract_artifact.d.ts.map +1 -1
  5. package/dest/abi/contract_artifact.js +21 -9
  6. package/dest/avm/avm.d.ts +1203 -694
  7. package/dest/avm/avm.d.ts.map +1 -1
  8. package/dest/avm/avm.js +58 -6
  9. package/dest/avm/avm_circuit_public_inputs.d.ts +80 -80
  10. package/dest/avm/avm_proving_request.d.ts +672 -447
  11. package/dest/avm/avm_proving_request.d.ts.map +1 -1
  12. package/dest/config/config.d.ts +2 -1
  13. package/dest/config/config.d.ts.map +1 -1
  14. package/dest/contract/artifact_hash.d.ts +5 -5
  15. package/dest/contract/artifact_hash.d.ts.map +1 -1
  16. package/dest/contract/artifact_hash.js +8 -8
  17. package/dest/contract/index.d.ts +1 -1
  18. package/dest/contract/index.d.ts.map +1 -1
  19. package/dest/contract/index.js +1 -1
  20. package/dest/contract/interfaces/contract_class.d.ts +23 -19
  21. package/dest/contract/interfaces/contract_class.d.ts.map +1 -1
  22. package/dest/contract/interfaces/contract_class.js +4 -4
  23. package/dest/contract/interfaces/contract_instance.d.ts +2 -2
  24. package/dest/contract/private_function_membership_proof.d.ts +1 -1
  25. package/dest/contract/private_function_membership_proof.js +6 -6
  26. package/dest/contract/utility_function_membership_proof.d.ts +27 -0
  27. package/dest/contract/utility_function_membership_proof.d.ts.map +1 -0
  28. package/dest/contract/{unconstrained_function_membership_proof.js → utility_function_membership_proof.js} +13 -13
  29. package/dest/interfaces/allowed_element.d.ts +53 -0
  30. package/dest/interfaces/allowed_element.d.ts.map +1 -0
  31. package/dest/interfaces/allowed_element.js +18 -0
  32. package/dest/interfaces/configs.d.ts +17 -34
  33. package/dest/interfaces/configs.d.ts.map +1 -1
  34. package/dest/interfaces/configs.js +2 -17
  35. package/dest/interfaces/proving-job.d.ts +672 -447
  36. package/dest/interfaces/proving-job.d.ts.map +1 -1
  37. package/dest/interfaces/public_state_source.d.ts +8 -0
  38. package/dest/interfaces/public_state_source.d.ts.map +1 -0
  39. package/dest/interfaces/public_state_source.js +1 -0
  40. package/dest/interfaces/pxe.d.ts +7 -8
  41. package/dest/interfaces/pxe.d.ts.map +1 -1
  42. package/dest/interfaces/pxe.js +1 -1
  43. package/dest/interfaces/server.d.ts +1 -0
  44. package/dest/interfaces/server.d.ts.map +1 -1
  45. package/dest/interfaces/server.js +1 -0
  46. package/dest/logs/tx_scoped_l2_log.d.ts +1 -1
  47. package/dest/noir/index.d.ts +3 -1
  48. package/dest/noir/index.d.ts.map +1 -1
  49. package/dest/noir/index.js +1 -0
  50. package/dest/note/extended_note.d.ts +3 -3
  51. package/dest/proofs/proof.d.ts +0 -1
  52. package/dest/proofs/proof.d.ts.map +1 -1
  53. package/dest/proofs/proof.js +6 -11
  54. package/dest/tests/factories.d.ts +4 -3
  55. package/dest/tests/factories.d.ts.map +1 -1
  56. package/dest/tests/factories.js +15 -6
  57. package/dest/trees/database_public_state_source.d.ts +11 -0
  58. package/dest/trees/database_public_state_source.d.ts.map +1 -0
  59. package/dest/trees/database_public_state_source.js +18 -0
  60. package/dest/trees/index.d.ts +1 -0
  61. package/dest/trees/index.d.ts.map +1 -1
  62. package/dest/trees/index.js +1 -0
  63. package/dest/tx/call_context.d.ts +1 -1
  64. package/dest/tx/tree_snapshots.d.ts +6 -6
  65. package/package.json +6 -6
  66. package/src/abi/abi.ts +2 -2
  67. package/src/abi/contract_artifact.ts +22 -8
  68. package/src/avm/avm.ts +89 -5
  69. package/src/config/config.ts +2 -1
  70. package/src/contract/artifact_hash.ts +9 -9
  71. package/src/contract/index.ts +1 -1
  72. package/src/contract/interfaces/contract_class.ts +21 -17
  73. package/src/contract/private_function_membership_proof.ts +6 -6
  74. package/src/contract/{unconstrained_function_membership_proof.ts → utility_function_membership_proof.ts} +18 -18
  75. package/src/interfaces/allowed_element.ts +21 -0
  76. package/src/interfaces/configs.ts +3 -18
  77. package/src/interfaces/public_state_source.ts +9 -0
  78. package/src/interfaces/pxe.ts +8 -9
  79. package/src/interfaces/server.ts +1 -0
  80. package/src/noir/index.ts +2 -1
  81. package/src/proofs/proof.ts +6 -16
  82. package/src/tests/factories.ts +23 -6
  83. package/src/trees/database_public_state_source.ts +30 -0
  84. package/src/trees/index.ts +1 -0
  85. package/dest/contract/unconstrained_function_membership_proof.d.ts +0 -27
  86. package/dest/contract/unconstrained_function_membership_proof.d.ts.map +0 -1
package/src/noir/index.ts CHANGED
@@ -10,6 +10,7 @@ import type {
10
10
 
11
11
  export const AZTEC_PRIVATE_ATTRIBUTE = 'private';
12
12
  export const AZTEC_PUBLIC_ATTRIBUTE = 'public';
13
+ export const AZTEC_UTILITY_ATTRIBUTE = 'utility';
13
14
  export const AZTEC_INTERNAL_ATTRIBUTE = 'internal';
14
15
  export const AZTEC_INITIALIZER_ATTRIBUTE = 'initializer';
15
16
  export const AZTEC_VIEW_ATTRIBUTE = 'view';
@@ -36,7 +37,7 @@ export interface NoirFunctionAbi {
36
37
  /**
37
38
  * The compilation result of an Aztec.nr function.
38
39
  */
39
- export interface NoirFunctionEntry {
40
+ interface NoirFunctionEntry {
40
41
  /** The name of the function. */
41
42
  name: string;
42
43
  /** Whether the function is unconstrained. */
@@ -17,11 +17,6 @@ export class Proof {
17
17
  // Make sure this type is not confused with other buffer wrappers
18
18
  readonly __proofBrand: any;
19
19
 
20
- // Honk proofs start with a 4 byte length prefix
21
- // the proof metadata starts immediately after
22
- // TODO(https://github.com/AztecProtocol/barretenberg/issues/1312): Get rid of if possible.
23
- private readonly metadataOffset = 4;
24
-
25
20
  constructor(
26
21
  /**
27
22
  * Holds the serialized proof data in a binary buffer format.
@@ -69,14 +64,14 @@ export class Proof {
69
64
  return this.buffer;
70
65
  }
71
66
  // We are indexing to this particular size because we are assuming the proof buffer looks like:
72
- // [4 bytes of metadata for public inputs, binary public inputs, 4 bytes of metadata for proof, binary proof]
73
- const proofStart = this.metadataOffset + Fr.SIZE_IN_BYTES * this.numPublicInputs + this.metadataOffset;
67
+ // [binary public inputs, binary proof]
68
+ const proofStart = Fr.SIZE_IN_BYTES * this.numPublicInputs;
74
69
  assert(this.buffer.length >= proofStart, 'Proof buffer is not appropriately sized to call withoutPublicInputs()');
75
70
  return this.buffer.subarray(proofStart);
76
71
  }
77
72
 
78
73
  // This function assumes that the proof will contain an aggregation object and look something like:
79
- // [4 bytes of metadata for public inputs, binary public inputs, 4 bytes of metadata for proof, aggregation object, rest of proof]
74
+ // [binary public inputs, aggregation object, rest of proof]
80
75
  // We are extracting the binary public inputs and reading them as Frs, and also extracting the aggregation object.
81
76
  public extractPublicInputs(): Fr[] {
82
77
  if (this.isEmpty()) {
@@ -85,9 +80,7 @@ export class Proof {
85
80
  }
86
81
  assert(this.numPublicInputs >= AGGREGATION_OBJECT_LENGTH, 'Proof does not contain an aggregation object');
87
82
  const numInnerPublicInputs = this.numPublicInputs - AGGREGATION_OBJECT_LENGTH;
88
- const reader = BufferReader.asReader(
89
- this.buffer.subarray(this.metadataOffset, this.metadataOffset + Fr.SIZE_IN_BYTES * numInnerPublicInputs),
90
- );
83
+ const reader = BufferReader.asReader(this.buffer.subarray(0, Fr.SIZE_IN_BYTES * numInnerPublicInputs));
91
84
  let publicInputs = reader.readArray(numInnerPublicInputs, Fr);
92
85
  // concatenate Fr[] with aggregation object
93
86
  publicInputs = publicInputs.concat(this.extractAggregationObject());
@@ -101,12 +94,9 @@ export class Proof {
101
94
  }
102
95
  assert(this.numPublicInputs >= AGGREGATION_OBJECT_LENGTH, 'Proof does not contain an aggregation object');
103
96
  const numInnerPublicInputs = this.numPublicInputs - AGGREGATION_OBJECT_LENGTH;
104
- // The aggregation object is currently stored after the initial inner public inputs and after the 4 byte proof metadata.
97
+ // The aggregation object is currently stored after the initial inner public inputs.
105
98
  const reader = BufferReader.asReader(
106
- this.buffer.subarray(
107
- this.metadataOffset + Fr.SIZE_IN_BYTES * numInnerPublicInputs + this.metadataOffset,
108
- this.metadataOffset + Fr.SIZE_IN_BYTES * this.numPublicInputs + this.metadataOffset,
109
- ),
99
+ this.buffer.subarray(Fr.SIZE_IN_BYTES * numInnerPublicInputs, Fr.SIZE_IN_BYTES * this.numPublicInputs),
110
100
  );
111
101
  return reader.readArray(AGGREGATION_OBJECT_LENGTH, Fr);
112
102
  }
@@ -69,6 +69,7 @@ import {
69
69
  AvmGetSiblingPathHint,
70
70
  AvmSequentialInsertHintNullifierTree,
71
71
  AvmSequentialInsertHintPublicDataTree,
72
+ AvmTxHint,
72
73
  RevertCode,
73
74
  } from '../avm/index.js';
74
75
  import { PublicDataHint } from '../avm/public_data_hint.js';
@@ -81,7 +82,7 @@ import {
81
82
  type ExecutablePrivateFunctionWithMembershipProof,
82
83
  type PrivateFunction,
83
84
  SerializableContractInstance,
84
- type UnconstrainedFunctionWithMembershipProof,
85
+ type UtilityFunctionWithMembershipProof,
85
86
  computeContractClassId,
86
87
  computePublicBytecodeCommitment,
87
88
  } from '../contract/index.js';
@@ -1168,12 +1169,12 @@ export function makeExecutablePrivateFunctionWithMembershipProof(
1168
1169
  privateFunctionTreeLeafIndex: seed + 3,
1169
1170
  artifactMetadataHash: fr(seed + 4),
1170
1171
  functionMetadataHash: fr(seed + 5),
1171
- unconstrainedFunctionsArtifactTreeRoot: fr(seed + 6),
1172
+ utilityFunctionsTreeRoot: fr(seed + 6),
1172
1173
  vkHash: fr(seed + 7),
1173
1174
  };
1174
1175
  }
1175
1176
 
1176
- export function makeUnconstrainedFunctionWithMembershipProof(seed = 0): UnconstrainedFunctionWithMembershipProof {
1177
+ export function makeUtilityFunctionWithMembershipProof(seed = 0): UtilityFunctionWithMembershipProof {
1177
1178
  return {
1178
1179
  selector: makeSelector(seed),
1179
1180
  bytecode: makeBytes(100, seed + 1),
@@ -1197,7 +1198,7 @@ export async function makeContractClassPublic(seed = 0, publicBytecode?: Buffer)
1197
1198
  packedBytecode,
1198
1199
  privateFunctionsRoot,
1199
1200
  privateFunctions: [],
1200
- unconstrainedFunctions: [],
1201
+ utilityFunctions: [],
1201
1202
  version: 1,
1202
1203
  };
1203
1204
  }
@@ -1427,6 +1428,22 @@ export function makeAvmEnqueuedCallHint(seed = 0): AvmEnqueuedCallHint {
1427
1428
  );
1428
1429
  }
1429
1430
 
1431
+ export function makeAvmTxHint(seed = 0): AvmTxHint {
1432
+ return new AvmTxHint(
1433
+ {
1434
+ noteHashes: makeArray((seed % 20) + 4, i => new Fr(i), seed + 0x1000),
1435
+ nullifiers: makeArray((seed % 20) + 4, i => new Fr(i), seed + 0x2000),
1436
+ },
1437
+ {
1438
+ noteHashes: makeArray((seed % 20) + 4, i => new Fr(i), seed + 0x3000),
1439
+ nullifiers: makeArray((seed % 20) + 4, i => new Fr(i), seed + 0x4000),
1440
+ },
1441
+ makeArray((seed % 20) + 4, i => makeAvmEnqueuedCallHint(i), seed + 0x5000), // setupEnqueuedCalls
1442
+ makeArray((seed % 20) + 4, i => makeAvmEnqueuedCallHint(i), seed + 0x6000), // appLogicEnqueuedCalls
1443
+ makeAvmEnqueuedCallHint(seed + 0x7000), // teardownEnqueuedCall
1444
+ );
1445
+ }
1446
+
1430
1447
  /**
1431
1448
  * Creates arbitrary AvmExecutionHints.
1432
1449
  * @param seed - The seed to use for generating the hints.
@@ -1441,7 +1458,7 @@ export async function makeAvmExecutionHints(
1441
1458
  const baseLength = lengthOffset + (seed % lengthSeedMod);
1442
1459
 
1443
1460
  const fields = {
1444
- enqueuedCalls: makeArray(baseLength, makeAvmEnqueuedCallHint, seed + 0x4100),
1461
+ tx: makeAvmTxHint(seed + 0x4100),
1445
1462
  contractInstances: makeArray(baseLength + 2, makeAvmContractInstanceHint, seed + 0x4700),
1446
1463
  contractClasses: makeArray(baseLength + 5, makeAvmContractClassHint, seed + 0x4900),
1447
1464
  bytecodeCommitments: await makeArrayAsync(baseLength + 5, makeAvmBytecodeCommitmentHint, seed + 0x4900),
@@ -1468,7 +1485,7 @@ export async function makeAvmExecutionHints(
1468
1485
  };
1469
1486
 
1470
1487
  return new AvmExecutionHints(
1471
- fields.enqueuedCalls,
1488
+ fields.tx,
1472
1489
  fields.contractInstances,
1473
1490
  fields.contractClasses,
1474
1491
  fields.bytecodeCommitments,
@@ -0,0 +1,30 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+
3
+ import type { AztecAddress } from '../aztec-address/index.js';
4
+ import { computePublicDataTreeLeafSlot } from '../hash/hash.js';
5
+ import type { MerkleTreeReadOperations } from '../interfaces/merkle_tree_operations.js';
6
+ import type { PublicStateSource } from '../interfaces/public_state_source.js';
7
+ import { MerkleTreeId } from './merkle_tree_id.js';
8
+ import type { PublicDataTreeLeafPreimage } from './public_data_leaf.js';
9
+
10
+ export type { PublicStateSource };
11
+
12
+ export class DatabasePublicStateSource implements PublicStateSource {
13
+ constructor(private db: MerkleTreeReadOperations) {}
14
+
15
+ async storageRead(contractAddress: AztecAddress, slot: Fr): Promise<Fr> {
16
+ const leafSlot = (await computePublicDataTreeLeafSlot(contractAddress, slot)).toBigInt();
17
+
18
+ const lowLeafResult = await this.db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
19
+ if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
20
+ return Fr.ZERO;
21
+ }
22
+
23
+ const preimage = (await this.db.getLeafPreimage(
24
+ MerkleTreeId.PUBLIC_DATA_TREE,
25
+ lowLeafResult.index,
26
+ )) as PublicDataTreeLeafPreimage;
27
+
28
+ return preimage.leaf.value;
29
+ }
30
+ }
@@ -6,3 +6,4 @@ export * from './merkle_tree_id.js';
6
6
  export * from './nullifier_membership_witness.js';
7
7
  export * from './public_data_witness.js';
8
8
  export * from '../interfaces/merkle_tree_operations.js';
9
+ export * from './database_public_state_source.js';
@@ -1,27 +0,0 @@
1
- import { type ContractArtifact, FunctionSelector } from '../abi/index.js';
2
- import type { ContractClassPublic, UnconstrainedFunctionMembershipProof, UnconstrainedFunctionWithMembershipProof } from './interfaces/index.js';
3
- /**
4
- * Creates a membership proof for an unconstrained function in a contract class, to be verified via `isValidUnconstrainedFunctionMembershipProof`.
5
- * @param selector - Selector of the function to create the proof for.
6
- * @param artifact - Artifact of the contract class where the function is defined.
7
- */
8
- export declare function createUnconstrainedFunctionMembershipProof(selector: FunctionSelector, artifact: ContractArtifact): Promise<UnconstrainedFunctionMembershipProof>;
9
- /**
10
- * Verifies that an unconstrained function with a membership proof as emitted by the ClassRegisterer contract is valid,
11
- * as defined in the protocol specs at contract-deployment/classes:
12
- *
13
- * ```
14
- * // Load contract class from local db
15
- * contract_class = db.get_contract_class(contract_class_id)
16
- *
17
- * // Compute artifact leaf and assert it belongs to the artifact
18
- * artifact_function_leaf = sha256(selector, metadata_hash, sha256(bytecode))
19
- * computed_artifact_unconstrained_function_tree_root = compute_root(artifact_function_leaf, artifact_function_tree_sibling_path, artifact_function_tree_leaf_index)
20
- * computed_artifact_hash = sha256(private_functions_artifact_tree_root, computed_artifact_unconstrained_function_tree_root, artifact_metadata_hash)
21
- * assert computed_artifact_hash == contract_class.artifact_hash
22
- * ```
23
- * @param fn - Function to check membership proof for.
24
- * @param contractClass - In which contract class the function is expected to be.
25
- */
26
- export declare function isValidUnconstrainedFunctionMembershipProof(fn: UnconstrainedFunctionWithMembershipProof, contractClass: Pick<ContractClassPublic, 'artifactHash'>): Promise<boolean>;
27
- //# sourceMappingURL=unconstrained_function_membership_proof.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unconstrained_function_membership_proof.d.ts","sourceRoot":"","sources":["../../src/contract/unconstrained_function_membership_proof.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAgB,MAAM,iBAAiB,CAAC;AASxF,OAAO,KAAK,EACV,mBAAmB,EACnB,oCAAoC,EACpC,wCAAwC,EACzC,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,wBAAsB,0CAA0C,CAC9D,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,oCAAoC,CAAC,CAsC/C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,2CAA2C,CAC/D,EAAE,EAAE,wCAAwC,EAC5C,aAAa,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,oBA+BzD"}