@aztec/txe 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa
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.
- package/dest/AuthRegistry-HMC7WEOJ.js +3 -0
- package/dest/AuthRegistry-HMC7WEOJ.js.map +7 -0
- package/dest/ContractClassRegistry-TXCDCFNC.js +3 -0
- package/dest/ContractClassRegistry-TXCDCFNC.js.map +7 -0
- package/dest/ContractInstanceRegistry-2TZHWOTT.js +3 -0
- package/dest/ContractInstanceRegistry-2TZHWOTT.js.map +7 -0
- package/dest/FeeJuice-FDF3J2Q5.js +3 -0
- package/dest/FeeJuice-FDF3J2Q5.js.map +7 -0
- package/dest/HandshakeRegistry-C7JF4R54.js +3 -0
- package/dest/HandshakeRegistry-C7JF4R54.js.map +7 -0
- package/dest/MultiCallEntrypoint-IGLO227K.js +3 -0
- package/dest/MultiCallEntrypoint-IGLO227K.js.map +7 -0
- package/dest/SchnorrAccount-KCIHUCXS.js +3 -0
- package/dest/SchnorrAccount-KCIHUCXS.js.map +7 -0
- package/dest/SchnorrInitializerlessAccount-PVR6XUSN.js +3 -0
- package/dest/SchnorrInitializerlessAccount-PVR6XUSN.js.map +7 -0
- package/dest/bin/check_txe_oracle_version.d.ts +2 -0
- package/dest/bin/check_txe_oracle_version.d.ts.map +1 -0
- package/dest/bin/check_txe_oracle_version.js +61 -0
- package/dest/bin/index.d.ts +1 -1
- package/dest/bin/index.js +3 -30
- package/dest/bin/index.js.map +7 -0
- package/dest/bin/oracle_test_server.d.ts +3 -0
- package/dest/bin/oracle_test_server.d.ts.map +1 -0
- package/dest/bin/oracle_test_server.js +41 -0
- package/dest/chunk-32UHX7YY.js +3 -0
- package/dest/chunk-32UHX7YY.js.map +7 -0
- package/dest/chunk-FRF5YZEO.js +304 -0
- package/dest/chunk-FRF5YZEO.js.map +7 -0
- package/dest/chunk-O57S6W5S.js +260 -0
- package/dest/chunk-O57S6W5S.js.map +7 -0
- package/dest/constants.d.ts +7 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +10 -0
- package/dest/dispatcher_pool.d.ts +67 -0
- package/dest/dispatcher_pool.d.ts.map +1 -0
- package/dest/dispatcher_pool.js +286 -0
- package/dest/index.d.ts +51 -7
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +75 -158
- package/dest/metafile.json +38497 -0
- package/dest/msgpackr_fr_extension.d.ts +2 -0
- package/dest/msgpackr_fr_extension.d.ts.map +1 -0
- package/dest/msgpackr_fr_extension.js +21 -0
- package/dest/oracle/interfaces.d.ts +65 -31
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/test-resolver/default_fixtures.d.ts +9 -0
- package/dest/oracle/test-resolver/default_fixtures.d.ts.map +1 -0
- package/dest/oracle/test-resolver/default_fixtures.js +207 -0
- package/dest/oracle/test-resolver/index.d.ts +9 -0
- package/dest/oracle/test-resolver/index.d.ts.map +1 -0
- package/dest/oracle/test-resolver/index.js +32 -0
- package/dest/oracle/test-resolver/resolver.d.ts +48 -0
- package/dest/oracle/test-resolver/resolver.d.ts.map +1 -0
- package/dest/oracle/test-resolver/resolver.js +181 -0
- package/dest/oracle/txe_oracle_public_context.d.ts +41 -17
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +69 -23
- package/dest/oracle/txe_oracle_registry.d.ts +169 -0
- package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_registry.js +745 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts +66 -30
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +630 -275
- package/dest/oracle/txe_oracle_version.d.ts +17 -0
- package/dest/oracle/txe_oracle_version.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_version.js +14 -0
- package/dest/oracle/txe_private_execution_oracle.d.ts +17 -0
- package/dest/oracle/txe_private_execution_oracle.d.ts.map +1 -0
- package/dest/oracle/txe_private_execution_oracle.js +15 -0
- package/dest/rpc_server.d.ts +14 -0
- package/dest/rpc_server.d.ts.map +1 -0
- package/dest/rpc_server.js +78 -0
- package/dest/rpc_translator.d.ts +112 -213
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +877 -550
- package/dest/server.bundle.js +3 -0
- package/dest/server.bundle.js.map +7 -0
- package/dest/state_machine/archiver.d.ts +23 -52
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +76 -99
- package/dest/state_machine/dummy_p2p_client.d.ts +31 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +63 -22
- package/dest/state_machine/global_variable_builder.d.ts +10 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +20 -5
- package/dest/state_machine/index.d.ts +14 -8
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +84 -27
- package/dest/state_machine/mock_epoch_cache.d.ts +29 -12
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +50 -15
- package/dest/state_machine/synchronizer.d.ts +15 -6
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +27 -13
- package/dest/txe_session.d.ts +102 -21
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +440 -76
- package/dest/utils/block_creation.d.ts +22 -7
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +40 -6
- package/dest/utils/encoding.d.ts +192 -0
- package/dest/utils/encoding.d.ts.map +1 -0
- package/dest/{util → utils}/encoding.js +8 -3
- package/dest/utils/expected_failure_error.d.ts +4 -0
- package/dest/utils/expected_failure_error.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.d.ts +3 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +3 -7
- package/dest/utils/txe_account_store.d.ts +10 -0
- package/dest/utils/txe_account_store.d.ts.map +1 -0
- package/dest/{util/txe_account_data_provider.js → utils/txe_account_store.js} +1 -1
- package/dest/utils/txe_artifact_resolver.d.ts +37 -0
- package/dest/utils/txe_artifact_resolver.d.ts.map +1 -0
- package/dest/utils/txe_artifact_resolver.js +161 -0
- package/dest/utils/txe_public_contract_data_source.d.ts +20 -0
- package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -0
- package/dest/utils/txe_public_contract_data_source.js +51 -0
- package/dest/worker.bundle.js +3 -0
- package/dest/worker.bundle.js.map +7 -0
- package/dest/worker.d.ts +2 -0
- package/dest/worker.d.ts.map +1 -0
- package/dest/worker.js +92 -0
- package/package.json +40 -22
- package/src/bin/check_txe_oracle_version.ts +70 -0
- package/src/bin/index.ts +11 -2
- package/src/bin/oracle_test_server.ts +51 -0
- package/src/constants.ts +13 -0
- package/src/dispatcher_pool.ts +317 -0
- package/src/index.ts +113 -201
- package/src/msgpackr_fr_extension.ts +23 -0
- package/src/oracle/interfaces.ts +68 -36
- package/src/oracle/test-resolver/default_fixtures.ts +282 -0
- package/src/oracle/test-resolver/index.ts +44 -0
- package/src/oracle/test-resolver/resolver.ts +245 -0
- package/src/oracle/txe_oracle_public_context.ts +83 -28
- package/src/oracle/txe_oracle_registry.ts +536 -0
- package/src/oracle/txe_oracle_top_level_context.ts +539 -199
- package/src/oracle/txe_oracle_version.ts +17 -0
- package/src/oracle/txe_private_execution_oracle.ts +30 -0
- package/src/rpc_server.ts +87 -0
- package/src/rpc_translator.ts +1086 -909
- package/src/state_machine/archiver.ts +82 -115
- package/src/state_machine/dummy_p2p_client.ts +96 -33
- package/src/state_machine/global_variable_builder.ts +28 -9
- package/src/state_machine/index.ts +118 -44
- package/src/state_machine/mock_epoch_cache.ts +63 -23
- package/src/state_machine/synchronizer.ts +36 -14
- package/src/txe_session.ts +719 -125
- package/src/utils/block_creation.ts +51 -15
- package/src/{util → utils}/encoding.ts +9 -3
- package/src/utils/tx_effect_creation.ts +4 -13
- package/src/{util/txe_account_data_provider.ts → utils/txe_account_store.ts} +1 -1
- package/src/utils/txe_artifact_resolver.ts +217 -0
- package/src/utils/txe_public_contract_data_source.ts +60 -0
- package/src/worker.ts +98 -0
- package/dest/util/encoding.d.ts +0 -121
- package/dest/util/encoding.d.ts.map +0 -1
- package/dest/util/expected_failure_error.d.ts +0 -4
- package/dest/util/expected_failure_error.d.ts.map +0 -1
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/dest/util/txe_public_contract_data_source.d.ts +0 -20
- package/dest/util/txe_public_contract_data_source.d.ts.map +0 -1
- package/dest/util/txe_public_contract_data_source.js +0 -67
- package/src/util/txe_contract_data_provider.ts +0 -36
- package/src/util/txe_public_contract_data_source.ts +0 -85
- /package/dest/{util → utils}/expected_failure_error.js +0 -0
- /package/src/{util → utils}/expected_failure_error.ts +0 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { withoutHexPrefix } from '@aztec/foundation/string';
|
|
5
|
+
import { BOUNDED_VEC, BYTE, BoundedVec, Option, type OracleRegistryEntry, makeEntry } from '@aztec/pxe/simulator';
|
|
6
|
+
|
|
7
|
+
import type { ForeignCallArgs, ForeignCallResult } from '../../utils/encoding.js';
|
|
8
|
+
import { toInputSlots } from '../txe_oracle_registry.js';
|
|
9
|
+
import { synthesizeDefaultFixtures } from './default_fixtures.js';
|
|
10
|
+
|
|
11
|
+
/** Name of the meta-oracle that Noir tests call to announce the next call's scenario by name. */
|
|
12
|
+
const SET_SCENARIO_ORACLE = 'aztec_oracle_test_set_scenario';
|
|
13
|
+
export const SET_SCENARIO_ENTRY = makeEntry({ params: [{ name: 'name', type: BOUNDED_VEC(BYTE) }] });
|
|
14
|
+
|
|
15
|
+
export type OracleTestCallInput = {
|
|
16
|
+
session_id: number;
|
|
17
|
+
function: string;
|
|
18
|
+
root_path: string;
|
|
19
|
+
package_name: string;
|
|
20
|
+
inputs: ForeignCallArgs;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One test case for an oracle: the expected deserialized `inputs`, the `output` to serialize back to Noir, and the
|
|
25
|
+
* `scenario` name (`some`/`none`) the matching Noir test announces. Single-scenario oracles leave `scenario` undefined
|
|
26
|
+
* and are selected automatically.
|
|
27
|
+
*/
|
|
28
|
+
export interface OracleTestScenario {
|
|
29
|
+
scenario?: string;
|
|
30
|
+
inputs: Record<string, unknown>;
|
|
31
|
+
output: unknown;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Oracle resolver for serialization tests. Selects a fixture scenario, verifies that the received inputs match, and
|
|
36
|
+
* returns the corresponding fixture output.
|
|
37
|
+
*
|
|
38
|
+
* For oracles with a single scenario, it is selected automatically. For oracles with multiple scenarios, the Noir test
|
|
39
|
+
* announces the scenario by name via the `aztec_oracle_test_set_scenario` meta-oracle before calling the real oracle.
|
|
40
|
+
*/
|
|
41
|
+
export class OracleTestResolver {
|
|
42
|
+
private readonly calledOracles = new Set<string>();
|
|
43
|
+
private readonly pendingScenario = new Map<number, string>();
|
|
44
|
+
private readonly logger: Logger;
|
|
45
|
+
|
|
46
|
+
constructor(
|
|
47
|
+
private readonly registry: Record<string, OracleRegistryEntry>,
|
|
48
|
+
private readonly fixtures: Record<string, OracleTestScenario[]>,
|
|
49
|
+
logger?: Logger,
|
|
50
|
+
) {
|
|
51
|
+
this.logger = logger ?? createLogger('txe:test-resolver');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Builds a resolver whose fixtures are the default scenarios synthesized from the registry's type mappings. The
|
|
56
|
+
* matching Noir serialization tests are auto-generated by `#[generate_oracle_tests]` from the same convention.
|
|
57
|
+
*/
|
|
58
|
+
static fromRegistry(registry: Record<string, OracleRegistryEntry>, logger?: Logger): OracleTestResolver {
|
|
59
|
+
return new OracleTestResolver(registry, synthesizeDefaultFixtures(registry), logger);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// eslint-disable-next-line require-await
|
|
63
|
+
async resolve_foreign_call(callData: OracleTestCallInput): Promise<ForeignCallResult> {
|
|
64
|
+
const oracleName = callData.function;
|
|
65
|
+
this.logger.debug('Resolving oracle', { oracleName });
|
|
66
|
+
|
|
67
|
+
if (oracleName === SET_SCENARIO_ORACLE) {
|
|
68
|
+
return this.#handleSetScenario(callData);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!(oracleName in this.registry)) {
|
|
72
|
+
throw new Error(`Oracle '${oracleName}' not found in registry`);
|
|
73
|
+
}
|
|
74
|
+
const entry = this.registry[oracleName];
|
|
75
|
+
|
|
76
|
+
const scenarios = this.fixtures[oracleName];
|
|
77
|
+
if (!scenarios || scenarios.length === 0) {
|
|
78
|
+
throw new Error(`No fixture defined for oracle '${oracleName}'`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const match = this.#selectScenario(callData.session_id, oracleName, scenarios);
|
|
82
|
+
this.#verifyInputs(callData.inputs, entry, match, oracleName);
|
|
83
|
+
this.calledOracles.add(oracleName);
|
|
84
|
+
|
|
85
|
+
this.logger.debug('Verified scenario for oracle', { oracleName });
|
|
86
|
+
|
|
87
|
+
const outputSlots = entry.serializeReturn(match.output);
|
|
88
|
+
return {
|
|
89
|
+
values: outputSlots.map(slot => (Array.isArray(slot) ? slot.map(withoutHexPrefix) : withoutHexPrefix(slot))),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Returns oracles that have a fixture defined but were never called during testing. */
|
|
94
|
+
getUncalledFixtures(): string[] {
|
|
95
|
+
return Object.keys(this.fixtures).filter(name => !this.calledOracles.has(name));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Returns oracles in the registry that have no fixture defined at all. */
|
|
99
|
+
getMissingFixtures(): string[] {
|
|
100
|
+
return Object.keys(this.registry).filter(name => !(name in this.fixtures));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Records the scenario name for the session's next oracle call. A test announces once per multi-scenario position
|
|
105
|
+
* (param or return), so successive announcements accumulate joined with `+`, matching the names the fixture
|
|
106
|
+
* synthesizer builds (e.g. `some+some`).
|
|
107
|
+
*/
|
|
108
|
+
#handleSetScenario(callData: { session_id: number; inputs: ForeignCallArgs }): ForeignCallResult {
|
|
109
|
+
const name = decodeScenarioName(callData.inputs);
|
|
110
|
+
const existing = this.pendingScenario.get(callData.session_id);
|
|
111
|
+
const scenario = existing !== undefined ? `${existing}+${name}` : name;
|
|
112
|
+
|
|
113
|
+
this.logger.debug('Setting scenario for next oracle call', { sessionId: callData.session_id, scenario });
|
|
114
|
+
this.pendingScenario.set(callData.session_id, scenario);
|
|
115
|
+
|
|
116
|
+
return { values: [] };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Selects the fixture by the announced scenario name (for multi-scenario oracles) or returns the single fixture. */
|
|
120
|
+
#selectScenario(sessionId: number, oracleName: string, fixtures: OracleTestScenario[]): OracleTestScenario {
|
|
121
|
+
const announced = this.pendingScenario.get(sessionId);
|
|
122
|
+
|
|
123
|
+
if (announced !== undefined) {
|
|
124
|
+
this.pendingScenario.delete(sessionId);
|
|
125
|
+
const match = fixtures.find(s => s.scenario === announced);
|
|
126
|
+
if (!match) {
|
|
127
|
+
const available = fixtures.map(s => s.scenario ?? '<default>').join(', ');
|
|
128
|
+
throw new Error(`No scenario '${announced}' for oracle '${oracleName}'. Available: ${available}`);
|
|
129
|
+
}
|
|
130
|
+
return match;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (fixtures.length === 1) {
|
|
134
|
+
return fixtures[0];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
throw new Error(`Oracle '${oracleName}' has ${fixtures.length} scenarios but none was announced before the call.`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Deserializes actual inputs and verifies they match the scenario's expected inputs. */
|
|
141
|
+
#verifyInputs(
|
|
142
|
+
rawInputs: ForeignCallArgs,
|
|
143
|
+
entry: OracleRegistryEntry,
|
|
144
|
+
fixture: OracleTestScenario,
|
|
145
|
+
oracleName: string,
|
|
146
|
+
): void {
|
|
147
|
+
const expectedInputs = fixture.inputs;
|
|
148
|
+
if (Object.keys(expectedInputs).length === 0) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const scenarioLabel = fixture.scenario ? ` (scenario '${fixture.scenario}')` : '';
|
|
153
|
+
const named = entry.deserializeParams(toInputSlots(rawInputs));
|
|
154
|
+
|
|
155
|
+
for (const param of named) {
|
|
156
|
+
if (!(param.name in expectedInputs)) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`Unexpected param '${param.name}' for oracle '${oracleName}'. ` +
|
|
159
|
+
`Expected: ${Object.keys(expectedInputs).join(', ')}`,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
if (!valuesEqual(param.value, expectedInputs[param.name])) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`Input mismatch for oracle '${oracleName}'${scenarioLabel}: ` +
|
|
165
|
+
`param '${param.name}' expected ${String(expectedInputs[param.name])} ` +
|
|
166
|
+
`but got ${String(param.value)}. ${versionBumpHint(oracleName)}`,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Decodes the scenario name announced by `set_oracle_test_scenario`, whose argument is a `BoundedVec<u8, N>`
|
|
175
|
+
*/
|
|
176
|
+
function decodeScenarioName(inputs: ForeignCallArgs): string {
|
|
177
|
+
const [{ value }] = SET_SCENARIO_ENTRY.deserializeParams(toInputSlots(inputs));
|
|
178
|
+
return String.fromCharCode(...value.data);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function valuesEqual(actual: unknown, expected: unknown): boolean {
|
|
182
|
+
if (!isNonNullObject(actual) || !isNonNullObject(expected)) {
|
|
183
|
+
// Primitive scalars; String() bridges bigint vs number representations of the same seed. A primitive compared
|
|
184
|
+
// against an object is never equal.
|
|
185
|
+
return isNonNullObject(actual) === isNonNullObject(expected) && String(actual) === String(expected);
|
|
186
|
+
}
|
|
187
|
+
if (actual instanceof Option && expected instanceof Option) {
|
|
188
|
+
return actual.equals(expected, valuesEqual);
|
|
189
|
+
}
|
|
190
|
+
if (actual instanceof BoundedVec && expected instanceof BoundedVec) {
|
|
191
|
+
return actual.equals(expected, valuesEqual);
|
|
192
|
+
}
|
|
193
|
+
if (Array.isArray(actual) && Array.isArray(expected)) {
|
|
194
|
+
return actual.length === expected.length && actual.every((v, i) => valuesEqual(v, expected[i]));
|
|
195
|
+
}
|
|
196
|
+
if (isPlainObject(actual) && isPlainObject(expected)) {
|
|
197
|
+
const expectedKeys = Object.keys(expected);
|
|
198
|
+
return (
|
|
199
|
+
Object.keys(actual).length === expectedKeys.length &&
|
|
200
|
+
expectedKeys.every(key => valuesEqual(actual[key], expected[key]))
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
if (actual.constructor !== expected.constructor) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
if (hasEquals(actual)) {
|
|
207
|
+
return actual.equals(expected);
|
|
208
|
+
}
|
|
209
|
+
const actualStr = customStringForm(actual);
|
|
210
|
+
const expectedStr = customStringForm(expected);
|
|
211
|
+
if (actualStr !== undefined && expectedStr !== undefined) {
|
|
212
|
+
return actualStr === expectedStr;
|
|
213
|
+
}
|
|
214
|
+
// Comparing blindly here could pass vacuously (e.g. two '[object Object]' strings), so refuse instead.
|
|
215
|
+
throw new Error(
|
|
216
|
+
`valuesEqual cannot compare a '${actual.constructor?.name}' against a '${expected.constructor?.name}'. Add a branch for the type.`,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function isNonNullObject(value: unknown): value is object {
|
|
221
|
+
return typeof value === 'object' && value !== null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
225
|
+
return isNonNullObject(value) && value.constructor === Object;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function hasEquals(value: object): value is { equals(other: unknown): boolean } {
|
|
229
|
+
return typeof (value as { equals?: unknown }).equals === 'function';
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** The value's string form when its class overrides `toString` (a meaningful representation), undefined otherwise. */
|
|
233
|
+
function customStringForm(value: object): string | undefined {
|
|
234
|
+
const { toString } = value;
|
|
235
|
+
if (typeof toString !== 'function' || toString === Object.prototype.toString) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
return toString.call(value);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function versionBumpHint(oracle: string): string {
|
|
242
|
+
return oracle.startsWith('aztec_txe_') || oracle.startsWith('aztec_avm_')
|
|
243
|
+
? 'If you changed this oracle, consider bumping the TXE oracle version in yarn-project/txe/src/oracle/txe_oracle_version.ts.'
|
|
244
|
+
: 'If you changed this oracle, consider bumping the PXE oracle version in yarn-project/pxe/src/oracle_version.ts.';
|
|
245
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import type { ContractStore } from '@aztec/pxe/server';
|
|
3
5
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
4
6
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import {
|
|
7
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
8
|
+
import type { ContractInstancePreimageWithAddress } from '@aztec/stdlib/contract';
|
|
6
9
|
import { computePublicDataTreeLeafSlot, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
|
|
7
|
-
import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
|
|
8
10
|
import {
|
|
9
11
|
MerkleTreeId,
|
|
10
12
|
type MerkleTreeWriteOperations,
|
|
@@ -12,9 +14,8 @@ import {
|
|
|
12
14
|
PublicDataTreeLeafPreimage,
|
|
13
15
|
} from '@aztec/stdlib/trees';
|
|
14
16
|
import { GlobalVariables, TxEffect, TxHash } from '@aztec/stdlib/tx';
|
|
15
|
-
import type { UInt32 } from '@aztec/stdlib/types';
|
|
16
17
|
|
|
17
|
-
import { insertTxEffectIntoWorldTrees,
|
|
18
|
+
import { insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
|
|
18
19
|
import type { IAvmExecutionOracle } from './interfaces.js';
|
|
19
20
|
|
|
20
21
|
export class TXEOraclePublicContext implements IAvmExecutionOracle {
|
|
@@ -30,6 +31,7 @@ export class TXEOraclePublicContext implements IAvmExecutionOracle {
|
|
|
30
31
|
private forkedWorldTrees: MerkleTreeWriteOperations,
|
|
31
32
|
private txRequestHash: Fr,
|
|
32
33
|
private globalVariables: GlobalVariables,
|
|
34
|
+
private contractStore: ContractStore,
|
|
33
35
|
) {
|
|
34
36
|
this.logger = createLogger('txe:public_context');
|
|
35
37
|
|
|
@@ -40,57 +42,55 @@ export class TXEOraclePublicContext implements IAvmExecutionOracle {
|
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
address(): Promise<AztecAddress> {
|
|
44
46
|
return Promise.resolve(this.contractAddress);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
sender(): Promise<AztecAddress> {
|
|
48
50
|
return Promise.resolve(AztecAddress.ZERO); // todo: change?
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
blockNumber(): Promise<BlockNumber> {
|
|
52
54
|
return Promise.resolve(this.globalVariables.blockNumber);
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
timestamp(): Promise<bigint> {
|
|
56
58
|
return Promise.resolve(this.globalVariables.timestamp);
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
isStaticCall(): Promise<boolean> {
|
|
60
62
|
return Promise.resolve(false);
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
chainId(): Promise<Fr> {
|
|
64
66
|
return Promise.resolve(this.globalVariables.chainId);
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
version(): Promise<Fr> {
|
|
68
70
|
return Promise.resolve(this.globalVariables.version);
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
async
|
|
73
|
+
async emitNullifier(nullifier: Fr) {
|
|
72
74
|
const siloedNullifier = await siloNullifier(this.contractAddress, nullifier);
|
|
73
75
|
this.transientSiloedNullifiers.push(siloedNullifier);
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
async
|
|
78
|
+
async emitNoteHash(noteHash: Fr) {
|
|
77
79
|
const siloedNoteHash = await siloNoteHash(this.contractAddress, noteHash);
|
|
78
80
|
// TODO: make the note hash unique - they are only siloed right now
|
|
79
81
|
this.transientUniqueNoteHashes.push(siloedNoteHash);
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
async
|
|
83
|
-
const nullifier = await siloNullifier(targetAddress, innerNullifier!);
|
|
84
|
-
|
|
84
|
+
async nullifierExists(siloedNullifier: Fr): Promise<boolean> {
|
|
85
85
|
const treeIndex = (
|
|
86
|
-
await this.forkedWorldTrees.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [
|
|
86
|
+
await this.forkedWorldTrees.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [siloedNullifier.toBuffer()])
|
|
87
87
|
)[0];
|
|
88
|
-
const transientIndex = this.transientSiloedNullifiers.find(n => n.equals(
|
|
88
|
+
const transientIndex = this.transientSiloedNullifiers.find(n => n.equals(siloedNullifier));
|
|
89
89
|
|
|
90
90
|
return treeIndex !== undefined || transientIndex !== undefined;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
async
|
|
93
|
+
async storageWrite(slot: Fr, value: Fr) {
|
|
94
94
|
this.logger.debug('AVM storage write', { slot, value });
|
|
95
95
|
|
|
96
96
|
const dataWrite = new PublicDataWrite(await computePublicDataTreeLeafSlot(this.contractAddress, slot), value);
|
|
@@ -102,8 +102,8 @@ export class TXEOraclePublicContext implements IAvmExecutionOracle {
|
|
|
102
102
|
]);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
async
|
|
106
|
-
const leafSlot = await computePublicDataTreeLeafSlot(
|
|
105
|
+
async storageRead(slot: Fr, contractAddress: AztecAddress): Promise<Fr> {
|
|
106
|
+
const leafSlot = await computePublicDataTreeLeafSlot(contractAddress, slot);
|
|
107
107
|
|
|
108
108
|
const lowLeafResult = await this.forkedWorldTrees.getPreviousValueIndex(
|
|
109
109
|
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
@@ -120,11 +120,70 @@ export class TXEOraclePublicContext implements IAvmExecutionOracle {
|
|
|
120
120
|
)) as PublicDataTreeLeafPreimage
|
|
121
121
|
).leaf.value;
|
|
122
122
|
|
|
123
|
-
this.logger.debug('AVM storage read', { slot, value });
|
|
123
|
+
this.logger.debug('AVM storage read', { slot, contractAddress, value });
|
|
124
124
|
|
|
125
125
|
return value;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
getContractInstanceDeployer(address: AztecAddress): Promise<{ member: Fr; exists: boolean }[]> {
|
|
129
|
+
return this.getContractInstanceMember(address, i => i.deployer.toField());
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
getContractInstanceClassId(address: AztecAddress): Promise<{ member: Fr; exists: boolean }[]> {
|
|
133
|
+
// TXE has no contract updates, so the current class always equals the original.
|
|
134
|
+
return this.getContractInstanceMember(address, i => i.originalContractClassId);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getContractInstanceInitializationHash(address: AztecAddress): Promise<{ member: Fr; exists: boolean }[]> {
|
|
138
|
+
return this.getContractInstanceMember(address, i => i.initializationHash);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
getContractInstanceImmutablesHash(address: AztecAddress): Promise<{ member: Fr; exists: boolean }[]> {
|
|
142
|
+
return this.getContractInstanceMember(address, i => i.immutablesHash);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// The one-element array mirrors the oracles' Noir return type, `[GetContractInstanceResult; 1]`.
|
|
146
|
+
private async getContractInstanceMember(
|
|
147
|
+
address: AztecAddress,
|
|
148
|
+
accessor: (instance: ContractInstancePreimageWithAddress) => Fr,
|
|
149
|
+
): Promise<{ member: Fr; exists: boolean }[]> {
|
|
150
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
151
|
+
if (!instance) {
|
|
152
|
+
return [{ member: Fr.ZERO, exists: false }];
|
|
153
|
+
}
|
|
154
|
+
return [{ member: accessor(instance), exists: true }];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
returndataSize(): Promise<number> {
|
|
158
|
+
throw new Error(
|
|
159
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
returndataCopy(_rdOffset: number, _copySize: number): Promise<Fr[]> {
|
|
164
|
+
throw new Error(
|
|
165
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
call(_l2Gas: number, _daGas: number, _address: AztecAddress, _argsLength: number, _args: Fr[]): Promise<void> {
|
|
170
|
+
throw new Error(
|
|
171
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
staticCall(_l2Gas: number, _daGas: number, _address: AztecAddress, _argsLength: number, _args: Fr[]): Promise<void> {
|
|
176
|
+
throw new Error(
|
|
177
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
successCopy(): Promise<boolean> {
|
|
182
|
+
throw new Error(
|
|
183
|
+
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
128
187
|
async close(): Promise<L2Block> {
|
|
129
188
|
this.logger.debug('Exiting Public Context, building block with collected side effects', {
|
|
130
189
|
blockNumber: this.globalVariables.blockNumber,
|
|
@@ -133,11 +192,7 @@ export class TXEOraclePublicContext implements IAvmExecutionOracle {
|
|
|
133
192
|
const txEffect = this.makeTxEffect();
|
|
134
193
|
await insertTxEffectIntoWorldTrees(txEffect, this.forkedWorldTrees);
|
|
135
194
|
|
|
136
|
-
const block =
|
|
137
|
-
makeAppendOnlyTreeSnapshot(),
|
|
138
|
-
await makeTXEBlockHeader(this.forkedWorldTrees, this.globalVariables),
|
|
139
|
-
new Body([txEffect]),
|
|
140
|
-
);
|
|
195
|
+
const block = await makeTXEBlock(this.forkedWorldTrees, this.globalVariables, [txEffect]);
|
|
141
196
|
|
|
142
197
|
await this.forkedWorldTrees.close();
|
|
143
198
|
|