@aztec/txe 5.0.0-rc.1 → 5.0.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 (133) hide show
  1. package/dest/AuthRegistry-FSRZIMX6.js +3 -0
  2. package/dest/AuthRegistry-FSRZIMX6.js.map +7 -0
  3. package/dest/ContractClassRegistry-N6NA3SFA.js +3 -0
  4. package/dest/ContractClassRegistry-N6NA3SFA.js.map +7 -0
  5. package/dest/ContractInstanceRegistry-NADDSLGL.js +3 -0
  6. package/dest/ContractInstanceRegistry-NADDSLGL.js.map +7 -0
  7. package/dest/FeeJuice-QBH5JWJV.js +3 -0
  8. package/dest/FeeJuice-QBH5JWJV.js.map +7 -0
  9. package/dest/HandshakeRegistry-KKUEU7XW.js +3 -0
  10. package/dest/HandshakeRegistry-KKUEU7XW.js.map +7 -0
  11. package/dest/MultiCallEntrypoint-TGICA67H.js +3 -0
  12. package/dest/MultiCallEntrypoint-TGICA67H.js.map +7 -0
  13. package/dest/SchnorrAccount-J5T6OKR3.js +3 -0
  14. package/dest/SchnorrAccount-J5T6OKR3.js.map +7 -0
  15. package/dest/SchnorrInitializerlessAccount-OOES6Q4F.js +3 -0
  16. package/dest/SchnorrInitializerlessAccount-OOES6Q4F.js.map +7 -0
  17. package/dest/bin/index.js +1 -1
  18. package/dest/bin/oracle_test_server.js +2 -2
  19. package/dest/{chunk-UPW55EJX.js → chunk-PDOEF22H.js} +2 -2
  20. package/dest/{chunk-UPW55EJX.js.map → chunk-PDOEF22H.js.map} +3 -3
  21. package/dest/chunk-YP4ODNMQ.js +268 -0
  22. package/dest/chunk-YP4ODNMQ.js.map +7 -0
  23. package/dest/constants.d.ts +1 -1
  24. package/dest/constants.d.ts.map +1 -1
  25. package/dest/constants.js +1 -1
  26. package/dest/index.d.ts +1 -1
  27. package/dest/index.d.ts.map +1 -1
  28. package/dest/index.js +5 -3
  29. package/dest/metafile.json +9768 -8714
  30. package/dest/oracle/interfaces.d.ts +19 -10
  31. package/dest/oracle/interfaces.d.ts.map +1 -1
  32. package/dest/oracle/tagging_secret_strategy.d.ts +12 -0
  33. package/dest/oracle/tagging_secret_strategy.d.ts.map +1 -0
  34. package/dest/oracle/tagging_secret_strategy.js +12 -0
  35. package/dest/oracle/test-resolver/default_fixtures.d.ts +9 -0
  36. package/dest/oracle/test-resolver/default_fixtures.d.ts.map +1 -0
  37. package/dest/oracle/test-resolver/default_fixtures.js +207 -0
  38. package/dest/oracle/test-resolver/index.d.ts +1 -1
  39. package/dest/oracle/test-resolver/index.d.ts.map +1 -1
  40. package/dest/oracle/test-resolver/index.js +1 -2
  41. package/dest/oracle/test-resolver/resolver.d.ts +22 -8
  42. package/dest/oracle/test-resolver/resolver.d.ts.map +1 -1
  43. package/dest/oracle/test-resolver/resolver.js +100 -33
  44. package/dest/oracle/txe_oracle_public_context.d.ts +9 -9
  45. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  46. package/dest/oracle/txe_oracle_public_context.js +15 -9
  47. package/dest/oracle/txe_oracle_registry.d.ts +159 -3
  48. package/dest/oracle/txe_oracle_registry.d.ts.map +1 -1
  49. package/dest/oracle/txe_oracle_registry.js +221 -34
  50. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -8
  51. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  52. package/dest/oracle/txe_oracle_top_level_context.js +107 -49
  53. package/dest/oracle/txe_oracle_version.d.ts +3 -3
  54. package/dest/oracle/txe_oracle_version.js +3 -3
  55. package/dest/rpc_translator.d.ts +14 -4
  56. package/dest/rpc_translator.d.ts.map +1 -1
  57. package/dest/rpc_translator.js +91 -11
  58. package/dest/server.bundle.js +1 -1
  59. package/dest/state_machine/archiver.d.ts +1 -1
  60. package/dest/state_machine/archiver.d.ts.map +1 -1
  61. package/dest/state_machine/archiver.js +1 -2
  62. package/dest/state_machine/dummy_p2p_client.d.ts +4 -2
  63. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  64. package/dest/state_machine/dummy_p2p_client.js +6 -0
  65. package/dest/state_machine/global_variable_builder.d.ts +3 -4
  66. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  67. package/dest/state_machine/global_variable_builder.js +0 -3
  68. package/dest/state_machine/index.d.ts +8 -6
  69. package/dest/state_machine/index.d.ts.map +1 -1
  70. package/dest/state_machine/index.js +40 -12
  71. package/dest/state_machine/synchronizer.d.ts +5 -2
  72. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  73. package/dest/state_machine/synchronizer.js +6 -2
  74. package/dest/txe_session.d.ts +8 -6
  75. package/dest/txe_session.d.ts.map +1 -1
  76. package/dest/txe_session.js +72 -32
  77. package/dest/utils/block_creation.d.ts +2 -2
  78. package/dest/utils/block_creation.d.ts.map +1 -1
  79. package/dest/utils/block_creation.js +2 -2
  80. package/dest/utils/encoding.d.ts +4 -3
  81. package/dest/utils/encoding.d.ts.map +1 -1
  82. package/dest/utils/tx_effect_creation.d.ts +1 -1
  83. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  84. package/dest/utils/tx_effect_creation.js +0 -1
  85. package/dest/utils/txe_public_contract_data_source.d.ts +1 -1
  86. package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -1
  87. package/dest/utils/txe_public_contract_data_source.js +7 -4
  88. package/dest/worker.bundle.js +1 -1
  89. package/package.json +17 -17
  90. package/src/bin/oracle_test_server.ts +2 -2
  91. package/src/constants.ts +1 -1
  92. package/src/index.ts +5 -3
  93. package/src/oracle/interfaces.ts +21 -8
  94. package/src/oracle/tagging_secret_strategy.ts +25 -0
  95. package/src/oracle/test-resolver/default_fixtures.ts +282 -0
  96. package/src/oracle/test-resolver/index.ts +1 -2
  97. package/src/oracle/test-resolver/resolver.ts +122 -42
  98. package/src/oracle/txe_oracle_public_context.ts +16 -14
  99. package/src/oracle/txe_oracle_registry.ts +156 -18
  100. package/src/oracle/txe_oracle_top_level_context.ts +147 -50
  101. package/src/oracle/txe_oracle_version.ts +3 -3
  102. package/src/rpc_translator.ts +119 -11
  103. package/src/state_machine/archiver.ts +0 -1
  104. package/src/state_machine/dummy_p2p_client.ts +9 -0
  105. package/src/state_machine/global_variable_builder.ts +2 -16
  106. package/src/state_machine/index.ts +49 -30
  107. package/src/state_machine/synchronizer.ts +8 -2
  108. package/src/txe_session.ts +104 -27
  109. package/src/utils/block_creation.ts +2 -1
  110. package/src/utils/tx_effect_creation.ts +0 -2
  111. package/src/utils/txe_public_contract_data_source.ts +6 -4
  112. package/dest/AuthRegistry-CPGFQR26.js +0 -3
  113. package/dest/AuthRegistry-CPGFQR26.js.map +0 -7
  114. package/dest/ContractClassRegistry-EHVIHGEK.js +0 -3
  115. package/dest/ContractClassRegistry-EHVIHGEK.js.map +0 -7
  116. package/dest/ContractInstanceRegistry-DWZDXHRG.js +0 -3
  117. package/dest/ContractInstanceRegistry-DWZDXHRG.js.map +0 -7
  118. package/dest/FeeJuice-MI32ZO7B.js +0 -3
  119. package/dest/FeeJuice-MI32ZO7B.js.map +0 -7
  120. package/dest/HandshakeRegistry-3KSP3ITH.js +0 -3
  121. package/dest/HandshakeRegistry-3KSP3ITH.js.map +0 -7
  122. package/dest/MultiCallEntrypoint-IU7HYFYE.js +0 -3
  123. package/dest/MultiCallEntrypoint-IU7HYFYE.js.map +0 -7
  124. package/dest/SchnorrAccount-6TUE7JX4.js +0 -3
  125. package/dest/SchnorrAccount-6TUE7JX4.js.map +0 -7
  126. package/dest/SchnorrInitializerlessAccount-S3DU2DJK.js +0 -3
  127. package/dest/SchnorrInitializerlessAccount-S3DU2DJK.js.map +0 -7
  128. package/dest/chunk-5U25VAFR.js +0 -265
  129. package/dest/chunk-5U25VAFR.js.map +0 -7
  130. package/dest/oracle/test-resolver/fixtures.d.ts +0 -43
  131. package/dest/oracle/test-resolver/fixtures.d.ts.map +0 -1
  132. package/dest/oracle/test-resolver/fixtures.js +0 -39
  133. package/src/oracle/test-resolver/fixtures.ts +0 -84
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/txe",
3
- "version": "5.0.0-rc.1",
3
+ "version": "5.0.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./server": {
@@ -69,22 +69,22 @@
69
69
  ]
70
70
  },
71
71
  "dependencies": {
72
- "@aztec/accounts": "5.0.0-rc.1",
73
- "@aztec/archiver": "5.0.0-rc.1",
74
- "@aztec/aztec-node": "5.0.0-rc.1",
75
- "@aztec/aztec.js": "5.0.0-rc.1",
76
- "@aztec/bb-prover": "5.0.0-rc.1",
77
- "@aztec/bb.js": "5.0.0-rc.1",
78
- "@aztec/constants": "5.0.0-rc.1",
79
- "@aztec/foundation": "5.0.0-rc.1",
80
- "@aztec/key-store": "5.0.0-rc.1",
81
- "@aztec/kv-store": "5.0.0-rc.1",
82
- "@aztec/protocol-contracts": "5.0.0-rc.1",
83
- "@aztec/pxe": "5.0.0-rc.1",
84
- "@aztec/simulator": "5.0.0-rc.1",
85
- "@aztec/standard-contracts": "5.0.0-rc.1",
86
- "@aztec/stdlib": "5.0.0-rc.1",
87
- "@aztec/world-state": "5.0.0-rc.1",
72
+ "@aztec/accounts": "5.0.0",
73
+ "@aztec/archiver": "5.0.0",
74
+ "@aztec/aztec-node": "5.0.0",
75
+ "@aztec/aztec.js": "5.0.0",
76
+ "@aztec/bb-prover": "5.0.0",
77
+ "@aztec/bb.js": "5.0.0",
78
+ "@aztec/constants": "5.0.0",
79
+ "@aztec/foundation": "5.0.0",
80
+ "@aztec/key-store": "5.0.0",
81
+ "@aztec/kv-store": "5.0.0",
82
+ "@aztec/protocol-contracts": "5.0.0",
83
+ "@aztec/pxe": "5.0.0",
84
+ "@aztec/simulator": "5.0.0",
85
+ "@aztec/standard-contracts": "5.0.0",
86
+ "@aztec/stdlib": "5.0.0",
87
+ "@aztec/world-state": "5.0.0",
88
88
  "msgpackr": "^1.11.2",
89
89
  "zod": "^4"
90
90
  },
@@ -5,8 +5,8 @@ import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
5
5
  import { createOracleTestRpcServer } from '../oracle/test-resolver/index.js';
6
6
 
7
7
  /**
8
- * Starts an HTTP RPC server that resolves oracle foreign calls using hardcoded fixture scenarios.
9
- * Used by `nargo test --oracle-resolver` to run `#[oracle_test]` roundtrip tests with a dedicated oracle resolver.
8
+ * Starts an HTTP RPC server that resolves oracle foreign calls using auto-synthesized fixture scenarios. Used by
9
+ * `nargo test --oracle-resolver` to run `#[generate_oracle_tests]` serialization tests against a dedicated resolver.
10
10
  * Logs fixture coverage on shutdown.
11
11
  */
12
12
  async function main() {
package/src/constants.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PRIVATE_LOG_CIPHERTEXT_LEN } from '@aztec/constants';
2
2
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
 
4
- export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
4
+ export const DEFAULT_ADDRESS = AztecAddress.fromNumberUnsafe(42);
5
5
 
6
6
  // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
7
7
  export const MAX_PRIVATE_EVENT_LEN = 10;
package/src/index.ts CHANGED
@@ -21,9 +21,11 @@ import {
21
21
  } from './utils/encoding.js';
22
22
  import { TXEArtifactResolver } from './utils/txe_artifact_resolver.js';
23
23
 
24
- // Protocol contracts TXE registers in its contract store. Only AuthRegistry is needed for the
25
- // current test suites; add a contract here if a lookup against a `0x000…00X` address fails.
26
- export const TXE_REQUIRED_PROTOCOL_CONTRACTS: ProtocolContractName[] = [];
24
+ export const TXE_REQUIRED_PROTOCOL_CONTRACTS: ProtocolContractName[] = [
25
+ 'ContractClassRegistry',
26
+ 'ContractInstanceRegistry',
27
+ 'FeeJuice',
28
+ ];
27
29
 
28
30
  const sessions = new Map<number, TXESession>();
29
31
 
@@ -2,6 +2,9 @@ import { CompleteAddress } from '@aztec/aztec.js/addresses';
2
2
  import { TxHash } from '@aztec/aztec.js/tx';
3
3
  import { BlockNumber } from '@aztec/foundation/branded-types';
4
4
  import type { Fr } from '@aztec/foundation/curves/bn254';
5
+ import type { EthAddress } from '@aztec/foundation/eth-address';
6
+ import type { TaggingSecretStrategy } from '@aztec/pxe/server';
7
+ import type { Option } from '@aztec/pxe/simulator';
5
8
  import type { EventSelector, FunctionSelector } from '@aztec/stdlib/abi';
6
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
10
  import type { GasSettings } from '@aztec/stdlib/gas';
@@ -36,15 +39,15 @@ export interface IAvmExecutionOracle {
36
39
  nullifierExists(siloedNullifier: Fr): Promise<boolean>;
37
40
  storageWrite(slot: Fr, value: Fr): Promise<void>;
38
41
  storageRead(slot: Fr, contractAddress: AztecAddress): Promise<Fr>;
39
- getContractInstanceDeployer(address: AztecAddress): Promise<{ member: Fr; exists: boolean }>;
40
- getContractInstanceClassId(address: AztecAddress): Promise<{ member: Fr; exists: boolean }>;
41
- getContractInstanceInitializationHash(address: AztecAddress): Promise<{ member: Fr; exists: boolean }>;
42
- getContractInstanceImmutablesHash(address: AztecAddress): Promise<{ member: Fr; exists: boolean }>;
43
- returndataSize(): Promise<Fr>;
42
+ getContractInstanceDeployer(address: AztecAddress): Promise<{ member: Fr; exists: boolean }[]>;
43
+ getContractInstanceClassId(address: AztecAddress): Promise<{ member: Fr; exists: boolean }[]>;
44
+ getContractInstanceInitializationHash(address: AztecAddress): Promise<{ member: Fr; exists: boolean }[]>;
45
+ getContractInstanceImmutablesHash(address: AztecAddress): Promise<{ member: Fr; exists: boolean }[]>;
46
+ returndataSize(): Promise<number>;
44
47
  returndataCopy(rdOffset: number, copySize: number): Promise<Fr[]>;
45
- call(l2Gas: number, daGas: number, address: AztecAddress, argsLength: number, args: Fr[]): Promise<Fr[]>;
46
- staticCall(l2Gas: number, daGas: number, address: AztecAddress, argsLength: number, args: Fr[]): Promise<Fr[]>;
47
- successCopy(): Promise<Fr>;
48
+ call(l2Gas: number, daGas: number, address: AztecAddress, argsLength: number, args: Fr[]): Promise<void>;
49
+ staticCall(l2Gas: number, daGas: number, address: AztecAddress, argsLength: number, args: Fr[]): Promise<void>;
50
+ successCopy(): Promise<boolean>;
48
51
  }
49
52
 
50
53
  /**
@@ -69,6 +72,15 @@ export interface ITxeExecutionOracle {
69
72
  createAccount(secret: Fr): Promise<CompleteAddress>;
70
73
  addAccount(secret: Fr): Promise<CompleteAddress>;
71
74
  addAuthWitness(address: AztecAddress, messageHash: Fr): Promise<void>;
75
+ sendL1ToL2Message(content: Fr, secretHash: Fr, sender: EthAddress, recipient: AztecAddress): Promise<Fr>;
76
+ /**
77
+ * Configures the tagging secret strategy the test's simulated wallet resolves for each delivery mode. A `none`
78
+ * clears that mode, so it falls back to the default strategy (or, when both modes end up unset, to no hook at all).
79
+ */
80
+ setTaggingSecretStrategies(
81
+ unconstrainedStrategy: Option<TaggingSecretStrategy>,
82
+ constrainedStrategy: Option<TaggingSecretStrategy>,
83
+ ): void;
72
84
  getLastBlockTimestamp(): Promise<bigint>;
73
85
  getLastTxEffects(): Promise<{
74
86
  txHash: TxHash;
@@ -90,6 +102,7 @@ export interface ITxeExecutionOracle {
90
102
  gasSettings: GasSettings,
91
103
  ): Promise<{ returnValues: Fr[]; offchainEffects: Fr[][] }>;
92
104
  executeUtilityFunction(
105
+ from: AztecAddress | undefined,
93
106
  targetContractAddress: AztecAddress,
94
107
  functionSelector: FunctionSelector,
95
108
  args: Fr[],
@@ -0,0 +1,25 @@
1
+ import {
2
+ DEFAULT_TAGGING_SECRET_STRATEGY,
3
+ type ResolveTaggingSecretStrategy,
4
+ type TaggingSecretStrategy,
5
+ } from '@aztec/pxe/server';
6
+ import type { AppTaggingSecretKind } from '@aztec/stdlib/logs';
7
+
8
+ /** The tagging secret strategies a TXE test has configured, keyed by delivery mode. Absence means "not configured". */
9
+ export type TXETaggingSecretStrategies = Map<AppTaggingSecretKind, TaggingSecretStrategy>;
10
+
11
+ /**
12
+ * Builds the `resolveTaggingSecretStrategy` hook backing the `aztec_txe_setTaggingSecretStrategies` oracle. Returns
13
+ * `undefined` when no strategy is configured, so PXE's own no-hook default path is exercised. When at least one mode
14
+ * is configured, modes without an entry resolve to {@link DEFAULT_TAGGING_SECRET_STRATEGY}, matching what PXE would
15
+ * apply without a hook.
16
+ */
17
+ export function makeResolveTaggingSecretStrategyHook(
18
+ strategies: TXETaggingSecretStrategies,
19
+ ): ResolveTaggingSecretStrategy | undefined {
20
+ if (strategies.size === 0) {
21
+ return undefined;
22
+ }
23
+
24
+ return ({ deliveryMode }) => Promise.resolve(strategies.get(deliveryMode) ?? DEFAULT_TAGGING_SECRET_STRATEGY);
25
+ }
@@ -0,0 +1,282 @@
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { EthAddress } from '@aztec/foundation/eth-address';
5
+ import {
6
+ AZTEC_ADDRESS,
7
+ BIGINT,
8
+ BLOCK_HASH,
9
+ BLOCK_NUMBER,
10
+ BOOL,
11
+ BYTE,
12
+ BoundedVec,
13
+ DELIVERY_MODE,
14
+ ETH_ADDRESS,
15
+ FIELD,
16
+ FUNCTION_SELECTOR,
17
+ NOTE_SELECTOR,
18
+ Option,
19
+ type OracleRegistryEntry,
20
+ SLOT_NUMBER,
21
+ type StructField,
22
+ type TypeMapping,
23
+ U32,
24
+ tryFieldWidth,
25
+ } from '@aztec/pxe/simulator';
26
+ import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
27
+ import { BlockHash } from '@aztec/stdlib/block';
28
+ import { AppTaggingSecretKind } from '@aztec/stdlib/logs';
29
+
30
+ import type { OracleTestScenario } from './resolver.js';
31
+
32
+ /**
33
+ * Synthesizes fixture scenarios for every oracle in the registry whose parameters and return are built from scalars,
34
+ * arrays/bounded vecs of them, `Option`s of them, or `STRUCT`s over them. The matching Noir serialization tests are
35
+ * auto-generated by `#[generate_oracle_tests]` from the same seed/scenario convention.
36
+ */
37
+ export function synthesizeDefaultFixtures(
38
+ registry: Record<string, OracleRegistryEntry>,
39
+ ): Record<string, OracleTestScenario[]> {
40
+ const synthesized: Record<string, OracleTestScenario[]> = {};
41
+
42
+ for (const [name, entry] of Object.entries(registry)) {
43
+ const scenarios = synthesizeScenarios(entry);
44
+ if (scenarios !== undefined) {
45
+ synthesized[name] = scenarios;
46
+ }
47
+ }
48
+
49
+ return synthesized;
50
+ }
51
+
52
+ /**
53
+ * The test-value implementations, one per oracle type, mirroring the Noir synthesizer tables (`scalars` and
54
+ * `synthesizers` in `noir-projects/aztec-nr/.../macros/oracle_testing.nr`) exactly.
55
+ */
56
+ const TEST_VALUE_IMPLS: TestValueImpl[] = [
57
+ scalar(FIELD, seed => new Fr(seed)),
58
+ scalar(U32, seed => seed),
59
+ scalar(BLOCK_NUMBER, seed => BlockNumber(seed)),
60
+ scalar(BIGINT, seed => BigInt(seed)),
61
+ scalar(BYTE, seed => seed),
62
+ scalar(BOOL, seed => seed % 2 !== 0),
63
+ scalar(AZTEC_ADDRESS, seed => AztecAddress.fromNumberUnsafe(seed)),
64
+ scalar(ETH_ADDRESS, seed => EthAddress.fromField(new Fr(seed))),
65
+ scalar(FUNCTION_SELECTOR, seed => FunctionSelector.fromField(new Fr(seed))),
66
+ scalar(NOTE_SELECTOR, seed => NoteSelector.fromField(new Fr(seed))),
67
+ scalar(BLOCK_HASH, seed => new BlockHash(new Fr(seed))),
68
+ scalar(SLOT_NUMBER, seed => SlotNumber(seed)),
69
+ // Only two delivery modes are valid for tagging, so the seed alternates between them, matching the Noir impl.
70
+ scalar(DELIVERY_MODE, seed =>
71
+ seed % 2 === 0 ? AppTaggingSecretKind.UNCONSTRAINED : AppTaggingSecretKind.CONSTRAINED,
72
+ ),
73
+ composite(isOption, (type, seed) => [
74
+ named(Option.some(firstValue(type.inner, seed)), 'some'),
75
+ named(Option.none(firstValue(type.inner, seed)), 'none'),
76
+ ]),
77
+ composite(isArray, (type, seed) => [unnamed(collectionData(type.inner, seed, DEFAULT_ARRAY_LENGTH))]),
78
+ composite(isBoundedVec, (type, seed) => [
79
+ unnamed(
80
+ BoundedVec.from({
81
+ data: collectionData(type.inner, seed, DEFAULT_ARRAY_LENGTH),
82
+ maxLength: BOUNDED_VEC_MAX_LENGTH,
83
+ }),
84
+ ),
85
+ ]),
86
+ composite(isStruct, (type, seed) => [unnamed(structValue(type, seed))]),
87
+ // A fixed-length array uses its real (signature) length, unlike the generic-length ARRAY which is pinned to
88
+ // DEFAULT_ARRAY_LENGTH.
89
+ composite(isFixedArray, (type, seed) => [unnamed(collectionData(type.inner, seed, type.length))]),
90
+ // Same for a fixed-capacity bounded vec: real capacity, DEFAULT_ARRAY_LENGTH elements (its value type is a plain
91
+ // element array, unlike the two-slot BOUNDED_VEC), clamped to the capacity so small vecs stay valid.
92
+ composite(isFixedBoundedVec, (type, seed) => [
93
+ unnamed(collectionData(type.inner, seed, Math.min(DEFAULT_ARRAY_LENGTH, type.maxLength))),
94
+ ]),
95
+ ];
96
+
97
+ /**
98
+ * The base every seed is offset by, applied once where a parameter's position becomes its seed, so generated values
99
+ * stay clear of 0. Must match `SEED_BASE` in the Noir `oracle_testing.nr`.
100
+ */
101
+ const SEED_BASE = 10;
102
+
103
+ /** Elements per synthesized array and bounded vec. Must match `TEST_COLLECTION_LEN` in the Noir `oracle_testing.nr`. */
104
+ const DEFAULT_ARRAY_LENGTH = 3;
105
+
106
+ /**
107
+ * Capacity of synthesized bounded vecs, deliberately larger than the data length so padding is exercised. Must match
108
+ * `TEST_BOUNDED_VEC_CAP` in the Noir `oracle_testing.nr`.
109
+ */
110
+ const BOUNDED_VEC_MAX_LENGTH = 5;
111
+
112
+ /**
113
+ * One canonical test case for a type: the `value` to put on the wire (or expect back), and the `name` of the
114
+ * serialization shape it exercises (unset for single-scenario types). Mirrors the Noir `Scenario<T>`.
115
+ */
116
+ interface Scenario {
117
+ value: unknown;
118
+ name?: string;
119
+ }
120
+
121
+ function unnamed(value: unknown): Scenario {
122
+ return { value };
123
+ }
124
+ function named(value: unknown, name: string): Scenario {
125
+ return { value, name };
126
+ }
127
+
128
+ /**
129
+ * One type's test-value implementation, mirroring a Noir `TestValueSynthesizer` entry: `match` selects the type and
130
+ * `scenarios` yields its [`Scenario`]s for `seed`, one per serialization shape, like the Noir entry's `scenarios`
131
+ * function.
132
+ */
133
+ interface TestValueImpl {
134
+ match: (type: TypeMapping<any>) => boolean;
135
+ scenarios: (type: TypeMapping<any>, seed: number) => Scenario[];
136
+ }
137
+
138
+ /** A scalar impl: matches the singleton `type` by identity and yields a single unnamed scenario. */
139
+ function scalar(type: TypeMapping<any>, value: (seed: number) => unknown): TestValueImpl {
140
+ return { match: t => t === type, scenarios: (_type, seed) => [unnamed(value(seed))] };
141
+ }
142
+
143
+ /** A composite impl: selected by the `kind` type guard, recursing through its element/inner mapping. */
144
+ function composite<K extends CompositeMapping>(
145
+ guard: (type: TypeMapping<any>) => type is K,
146
+ scenarios: (type: K, seed: number) => Scenario[],
147
+ ): TestValueImpl {
148
+ return { match: guard, scenarios: (type, seed) => scenarios(type as K, seed) };
149
+ }
150
+
151
+ /** Synthesized element values for a collection. */
152
+ function collectionData(element: TypeMapping<any>, seed: number, length: number): unknown[] {
153
+ return Array.from({ length }, (_, i) => firstValue(element, seed + i));
154
+ }
155
+
156
+ /**
157
+ * The synthesized prop bag for a struct: each field's first scenario, seeded at the field's flat wire offset so the
158
+ * values depend on the wire layout rather than on how each side groups its fields. Mirrors the Noir reflected impls.
159
+ */
160
+ function structValue(type: StructMapping, seed: number): Record<string, unknown> {
161
+ const value: Record<string, unknown> = {};
162
+ let offset = 0;
163
+ for (const field of type.fields) {
164
+ value[field.name] = firstValue(field.type, seed + offset);
165
+ const width = tryFieldWidth(field.type.shape);
166
+ if (width === undefined) {
167
+ // A variable-width field has no flat offset to seed the next field at, so only this oracle is unsynthesizable.
168
+ throw new UnsynthesizableTypeError(field.type, `struct field '${field.name}' has a variable-width shape`);
169
+ }
170
+ offset += width;
171
+ }
172
+ return value;
173
+ }
174
+
175
+ /**
176
+ * The [`Scenario`]s for `type` at `seed`, one per serialization *shape*, mirroring the Noir `scenarios_for`
177
+ * dispatcher. Throws if the type has no matching impl.
178
+ */
179
+ function scenariosForType(type: TypeMapping<any>, seed: number): Scenario[] {
180
+ const impl = TEST_VALUE_IMPLS.find(i => i.match(type));
181
+ if (!impl) {
182
+ throw new UnsynthesizableTypeError(type);
183
+ }
184
+ return impl.scenarios(type, seed);
185
+ }
186
+
187
+ /** The first (representative) test value of `type`, used for collection elements and `Option` inners. */
188
+ function firstValue(type: TypeMapping<any>, seed: number): unknown {
189
+ return scenariosForType(type, seed)[0].value;
190
+ }
191
+
192
+ class UnsynthesizableTypeError extends Error {
193
+ constructor(type: TypeMapping<any>, detail?: string) {
194
+ super(detail ?? `No test-value impl for type: ${JSON.stringify(Object.keys(type))}`);
195
+ this.name = 'UnsynthesizableTypeError';
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Synthesizes the scenarios for one oracle by zipping every position's [`Scenario`] list to one case per test (a
201
+ * shorter list wraps around via mod), mirroring the Noir macro. Returns `undefined` if any param or return type is
202
+ * unsynthesizable (ephemeral arrays, structs with a variable-width field).
203
+ */
204
+ function synthesizeScenarios(entry: OracleRegistryEntry): OracleTestScenario[] | undefined {
205
+ try {
206
+ return synthesizeScenariosOrThrow(entry);
207
+ } catch (e) {
208
+ if (e instanceof UnsynthesizableTypeError) {
209
+ return undefined;
210
+ }
211
+ throw e;
212
+ }
213
+ }
214
+
215
+ function synthesizeScenariosOrThrow(entry: OracleRegistryEntry): OracleTestScenario[] {
216
+ const params = entry.params.map((param, index) => ({
217
+ name: param.name,
218
+ scenarios: scenariosForType(param.type, SEED_BASE + index),
219
+ }));
220
+ // The return's seed is the slot right after the last parameter, so its value is distinct from every parameter.
221
+ const returnScenarios =
222
+ entry.returnType === undefined ? undefined : scenariosForType(entry.returnType, SEED_BASE + entry.params.length);
223
+
224
+ // Positions with more than one scenario drive the test count; their names are zipped together (joined with `+`) per
225
+ // test, matching the announcements the Noir tests emit and the resolver joins.
226
+ const positions = [...params.map(p => p.scenarios), ...(returnScenarios !== undefined ? [returnScenarios] : [])];
227
+ const namedPositions = positions.filter(s => s.length > 1);
228
+ const testCount = Math.max(1, ...positions.map(s => s.length));
229
+
230
+ const scenarios: OracleTestScenario[] = [];
231
+ for (let index = 0; index < testCount; index++) {
232
+ const inputs: Record<string, unknown> = {};
233
+ for (const { name, scenarios: cases } of params) {
234
+ inputs[name] = cases[index % cases.length].value;
235
+ }
236
+ const output = returnScenarios === undefined ? undefined : returnScenarios[index % returnScenarios.length].value;
237
+ const scenario =
238
+ namedPositions.length === 0
239
+ ? undefined
240
+ : namedPositions.map(cases => cases[index % cases.length].name!).join('+');
241
+ scenarios.push({ scenario, inputs, output });
242
+ }
243
+ return scenarios;
244
+ }
245
+
246
+ /**
247
+ * The composite `TypeMapping`s (`ARRAY`/`BOUNDED_VEC`/`OPTION`/`STRUCT`/`FIXED_ARRAY`/`FIXED_BOUNDED_VEC`),
248
+ * discriminated by `kind`. The combinators attach `kind` plus the inner mapping(s) at construction; the registry
249
+ * erases params to the base `TypeMapping`, so the guards below recover the structure for recursion.
250
+ */
251
+ type ArrayMapping = TypeMapping & { kind: 'array'; inner: TypeMapping };
252
+ type BoundedVecMapping = TypeMapping & { kind: 'bounded-vec'; inner: TypeMapping };
253
+ type OptionMapping = TypeMapping & { kind: 'option'; inner: TypeMapping };
254
+ type StructMapping = TypeMapping & { kind: 'struct'; fields: readonly StructField[] };
255
+ type FixedArrayMapping = TypeMapping & { kind: 'fixed-array'; inner: TypeMapping; length: number };
256
+ type FixedBoundedVecMapping = TypeMapping & { kind: 'fixed-bounded-vec'; inner: TypeMapping; maxLength: number };
257
+ type CompositeMapping =
258
+ | ArrayMapping
259
+ | BoundedVecMapping
260
+ | OptionMapping
261
+ | StructMapping
262
+ | FixedArrayMapping
263
+ | FixedBoundedVecMapping;
264
+
265
+ function isArray(type: TypeMapping<any>): type is ArrayMapping {
266
+ return 'kind' in type && type.kind === 'array';
267
+ }
268
+ function isBoundedVec(type: TypeMapping<any>): type is BoundedVecMapping {
269
+ return 'kind' in type && type.kind === 'bounded-vec';
270
+ }
271
+ function isOption(type: TypeMapping<any>): type is OptionMapping {
272
+ return 'kind' in type && type.kind === 'option';
273
+ }
274
+ function isStruct(type: TypeMapping<any>): type is StructMapping {
275
+ return 'kind' in type && type.kind === 'struct';
276
+ }
277
+ function isFixedArray(type: TypeMapping<any>): type is FixedArrayMapping {
278
+ return 'kind' in type && type.kind === 'fixed-array';
279
+ }
280
+ function isFixedBoundedVec(type: TypeMapping<any>): type is FixedBoundedVecMapping {
281
+ return 'kind' in type && type.kind === 'fixed-bounded-vec';
282
+ }
@@ -8,7 +8,6 @@ import { z } from 'zod';
8
8
 
9
9
  import { ForeignCallArgsSchema, type ForeignCallResult, ForeignCallResultSchema } from '../../utils/encoding.js';
10
10
  import { TXE_ORACLE_REGISTRY } from '../txe_oracle_registry.js';
11
- import { ORACLE_TEST_FIXTURES } from './fixtures.js';
12
11
  import { type OracleTestCallInput, OracleTestResolver } from './resolver.js';
13
12
 
14
13
  const OracleTestCallInputSchema = zodFor<OracleTestCallInput>()(
@@ -35,7 +34,7 @@ const OracleTestRpcHandlerSchema: ApiSchemaFor<OracleTestRpcHandler> = {
35
34
 
36
35
  /** Creates an RPC server backed by the oracle test resolver. */
37
36
  export function createOracleTestRpcServer(logger: Logger) {
38
- const resolver = new OracleTestResolver(TXE_ORACLE_REGISTRY, ORACLE_TEST_FIXTURES, logger);
37
+ const resolver = OracleTestResolver.fromRegistry(TXE_ORACLE_REGISTRY, logger);
39
38
  const server = createSafeJsonRpcServer<OracleTestRpcHandler>(resolver, OracleTestRpcHandlerSchema, {
40
39
  http200OnError: true,
41
40
  });