@aztec/simulator 0.40.1 → 0.42.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.
- package/dest/acvm/acvm.d.ts +2 -2
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +3 -3
- package/dest/acvm/oracle/oracle.d.ts +6 -2
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +31 -19
- package/dest/acvm/oracle/typed_oracle.d.ts +8 -11
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +17 -5
- package/dest/acvm/serialize.js +2 -2
- package/dest/avm/avm_execution_environment.d.ts +4 -3
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +7 -5
- package/dest/avm/avm_gas.d.ts +1 -5
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +67 -73
- package/dest/avm/avm_simulator.d.ts +5 -0
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +12 -4
- package/dest/avm/errors.d.ts +6 -0
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +10 -1
- package/dest/avm/fixtures/index.d.ts +3 -0
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +15 -3
- package/dest/avm/index.d.ts +2 -0
- package/dest/avm/index.d.ts.map +1 -0
- package/dest/avm/index.js +2 -0
- package/dest/avm/journal/host_storage.d.ts +1 -1
- package/dest/avm/journal/host_storage.d.ts.map +1 -1
- package/dest/avm/journal/journal.d.ts +4 -3
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +10 -11
- package/dest/avm/journal/nullifiers.d.ts +17 -5
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +27 -10
- package/dest/avm/journal/public_storage.d.ts +19 -6
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +30 -12
- package/dest/avm/journal/trace.d.ts +2 -0
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +7 -1
- package/dest/avm/journal/trace_types.d.ts +1 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/journal/trace_types.js +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +6 -7
- package/dest/avm/opcodes/arithmetic.d.ts +1 -7
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +1 -12
- package/dest/avm/opcodes/conversion.js +2 -2
- package/dest/avm/opcodes/external_calls.d.ts +2 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +25 -13
- package/dest/avm/opcodes/instruction.d.ts +1 -1
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +6 -4
- package/dest/avm/opcodes/memory.d.ts +0 -4
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -7
- package/dest/avm/opcodes/storage.d.ts +0 -12
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +3 -18
- package/dest/avm/serialization/bytecode_serialization.js +2 -2
- package/dest/client/client_execution_context.d.ts +30 -20
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +59 -39
- package/dest/client/db_oracle.d.ts +17 -12
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +2 -2
- package/dest/client/execution_result.d.ts +17 -2
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +32 -4
- package/dest/client/private_execution.d.ts +2 -3
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +22 -8
- package/dest/client/simulator.d.ts +0 -16
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +13 -30
- package/dest/client/unconstrained_execution.d.ts +2 -3
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +5 -7
- package/dest/client/view_data_oracle.d.ts +12 -10
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +17 -11
- package/dest/common/index.d.ts +1 -0
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +2 -1
- package/dest/common/return_values.d.ts +11 -0
- package/dest/common/return_values.d.ts.map +1 -0
- package/dest/common/return_values.js +13 -0
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +4 -2
- package/dest/mocks/fixtures.d.ts +15 -10
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +22 -17
- package/dest/{simulator → providers}/acvm_native.d.ts.map +1 -1
- package/dest/{simulator → providers}/acvm_native.js +13 -14
- package/dest/providers/acvm_wasm.d.ts.map +1 -0
- package/dest/providers/acvm_wasm.js +15 -0
- package/dest/providers/index.d.ts.map +1 -0
- package/dest/{simulator → providers}/index.js +1 -1
- package/dest/{simulator → providers}/simulation_provider.d.ts.map +1 -1
- package/dest/{simulator → providers}/simulation_provider.js +1 -1
- package/dest/public/abstract_phase_manager.d.ts +43 -42
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +81 -103
- package/dest/public/app_logic_phase_manager.d.ts +7 -8
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +14 -14
- package/dest/public/{db.d.ts → db_interfaces.d.ts} +3 -3
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +2 -0
- package/dest/public/execution.d.ts +17 -14
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts +3 -30
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +32 -279
- package/dest/public/fee_payment.d.ts +11 -0
- package/dest/public/fee_payment.d.ts.map +1 -0
- package/dest/public/fee_payment.js +24 -0
- package/dest/public/hints_builder.d.ts +3 -2
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +8 -4
- package/dest/public/index.d.ts +4 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +5 -3
- package/dest/public/phase_manager_factory.d.ts +1 -1
- package/dest/public/phase_manager_factory.d.ts.map +1 -1
- package/dest/public/{public_executor.d.ts → public_db_sources.d.ts} +3 -2
- package/dest/public/public_db_sources.d.ts.map +1 -0
- package/dest/public/public_db_sources.js +198 -0
- package/dest/public/public_kernel.js +14 -14
- package/dest/public/public_processor.d.ts +8 -6
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +48 -29
- package/dest/public/setup_phase_manager.d.ts +7 -9
- package/dest/public/setup_phase_manager.d.ts.map +1 -1
- package/dest/public/setup_phase_manager.js +11 -20
- package/dest/public/tail_phase_manager.d.ts +5 -11
- package/dest/public/tail_phase_manager.d.ts.map +1 -1
- package/dest/public/tail_phase_manager.js +16 -36
- package/dest/public/teardown_phase_manager.d.ts +7 -9
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +15 -21
- package/dest/public/transitional_adaptors.d.ts +3 -2
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +24 -8
- package/dest/public/utils.d.ts +2 -2
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +21 -14
- package/package.json +12 -9
- package/src/acvm/acvm.ts +0 -3
- package/src/acvm/oracle/oracle.ts +53 -27
- package/src/acvm/oracle/typed_oracle.ts +25 -16
- package/src/acvm/serialize.ts +1 -1
- package/src/avm/avm_execution_environment.ts +9 -5
- package/src/avm/avm_gas.ts +66 -73
- package/src/avm/avm_simulator.ts +14 -3
- package/src/avm/errors.ts +10 -0
- package/src/avm/fixtures/index.ts +22 -2
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/host_storage.ts +1 -1
- package/src/avm/journal/journal.ts +15 -14
- package/src/avm/journal/nullifiers.ts +27 -14
- package/src/avm/journal/public_storage.ts +30 -16
- package/src/avm/journal/trace.ts +12 -0
- package/src/avm/journal/trace_types.ts +1 -0
- package/src/avm/opcodes/accrued_substate.ts +5 -6
- package/src/avm/opcodes/arithmetic.ts +1 -14
- package/src/avm/opcodes/conversion.ts +1 -1
- package/src/avm/opcodes/external_calls.ts +26 -10
- package/src/avm/opcodes/instruction.ts +5 -3
- package/src/avm/opcodes/memory.ts +1 -8
- package/src/avm/opcodes/storage.ts +3 -20
- package/src/avm/serialization/bytecode_serialization.ts +1 -1
- package/src/client/client_execution_context.ts +70 -44
- package/src/client/db_oracle.ts +18 -12
- package/src/client/execution_note_cache.ts +1 -1
- package/src/client/execution_result.ts +41 -3
- package/src/client/private_execution.ts +38 -20
- package/src/client/simulator.ts +11 -32
- package/src/client/unconstrained_execution.ts +9 -12
- package/src/client/view_data_oracle.ts +20 -12
- package/src/common/index.ts +1 -0
- package/src/common/return_values.ts +18 -0
- package/src/index.ts +3 -1
- package/src/mocks/fixtures.ts +31 -33
- package/src/{simulator → providers}/acvm_native.ts +21 -19
- package/src/{simulator → providers}/acvm_wasm.ts +2 -16
- package/src/public/abstract_phase_manager.ts +146 -207
- package/src/public/app_logic_phase_manager.ts +23 -39
- package/src/public/{db.ts → db_interfaces.ts} +2 -2
- package/src/public/execution.ts +17 -14
- package/src/public/executor.ts +51 -391
- package/src/public/fee_payment.ts +26 -0
- package/src/public/hints_builder.ts +17 -3
- package/src/public/index.ts +4 -2
- package/src/public/phase_manager_factory.ts +1 -1
- package/src/public/{public_executor.ts → public_db_sources.ts} +3 -2
- package/src/public/public_kernel.ts +24 -24
- package/src/public/public_processor.ts +82 -38
- package/src/public/setup_phase_manager.ts +20 -45
- package/src/public/tail_phase_manager.ts +18 -68
- package/src/public/teardown_phase_manager.ts +22 -41
- package/src/public/transitional_adaptors.ts +24 -13
- package/src/public/utils.ts +20 -14
- package/dest/client/logs_cache.d.ts +0 -33
- package/dest/client/logs_cache.d.ts.map +0 -1
- package/dest/client/logs_cache.js +0 -59
- package/dest/public/db.d.ts.map +0 -1
- package/dest/public/db.js +0 -2
- package/dest/public/public_execution_context.d.ts +0 -121
- package/dest/public/public_execution_context.d.ts.map +0 -1
- package/dest/public/public_execution_context.js +0 -214
- package/dest/public/public_executor.d.ts.map +0 -1
- package/dest/public/public_executor.js +0 -197
- package/dest/public/state_actions.d.ts +0 -39
- package/dest/public/state_actions.d.ts.map +0 -1
- package/dest/public/state_actions.js +0 -80
- package/dest/simulator/acvm_wasm.d.ts.map +0 -1
- package/dest/simulator/acvm_wasm.js +0 -22
- package/dest/simulator/index.d.ts.map +0 -1
- package/src/client/logs_cache.ts +0 -65
- package/src/public/public_execution_context.ts +0 -289
- package/src/public/state_actions.ts +0 -102
- /package/dest/{simulator → providers}/acvm_native.d.ts +0 -0
- /package/dest/{simulator → providers}/acvm_wasm.d.ts +0 -0
- /package/dest/{simulator → providers}/index.d.ts +0 -0
- /package/dest/{simulator → providers}/simulation_provider.d.ts +0 -0
- /package/src/{simulator → providers}/index.ts +0 -0
- /package/src/{simulator → providers}/simulation_provider.ts +0 -0
|
@@ -12,21 +12,38 @@ import type { CommitmentsDB } from '../../index.js';
|
|
|
12
12
|
export class Nullifiers {
|
|
13
13
|
/** Cached nullifiers. */
|
|
14
14
|
public cache: NullifierCache;
|
|
15
|
-
/** Parent's nullifier cache. Checked on cache-miss. */
|
|
16
|
-
private readonly parentCache: NullifierCache | undefined;
|
|
17
|
-
/** Reference to node storage. Checked on parent cache-miss. */
|
|
18
|
-
private readonly hostNullifiers: CommitmentsDB;
|
|
19
15
|
|
|
20
|
-
constructor(
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
constructor(
|
|
17
|
+
/** Reference to node storage. Checked on parent cache-miss. */
|
|
18
|
+
private readonly hostNullifiers: CommitmentsDB,
|
|
19
|
+
/** Parent's nullifiers. Checked on this' cache-miss. */
|
|
20
|
+
private readonly parent?: Nullifiers | undefined,
|
|
21
|
+
) {
|
|
23
22
|
this.cache = new NullifierCache();
|
|
24
23
|
}
|
|
25
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Get a nullifier's existence in this' cache or parent's (recursively).
|
|
27
|
+
* DOES NOT CHECK HOST STORAGE!
|
|
28
|
+
* @param storageAddress - the address of the contract whose storage is being read from
|
|
29
|
+
* @param nullifier - the nullifier to check for
|
|
30
|
+
* @returns exists: whether the nullifier exists in cache here or in parent's
|
|
31
|
+
*/
|
|
32
|
+
private checkExistsHereOrParent(storageAddress: Fr, nullifier: Fr): boolean {
|
|
33
|
+
// First check this cache
|
|
34
|
+
let existsAsPending = this.cache.exists(storageAddress, nullifier);
|
|
35
|
+
// Then try parent's nullifier cache
|
|
36
|
+
if (!existsAsPending && this.parent) {
|
|
37
|
+
// Note: this will recurse to grandparent/etc until a cache-hit is encountered.
|
|
38
|
+
existsAsPending = this.parent.checkExistsHereOrParent(storageAddress, nullifier);
|
|
39
|
+
}
|
|
40
|
+
return existsAsPending;
|
|
41
|
+
}
|
|
42
|
+
|
|
26
43
|
/**
|
|
27
44
|
* Get a nullifier's existence status.
|
|
28
45
|
* 1. Check cache.
|
|
29
|
-
* 2. Check parent
|
|
46
|
+
* 2. Check parent cache.
|
|
30
47
|
* 3. Fall back to the host state.
|
|
31
48
|
* 4. Not found! Nullifier does not exist.
|
|
32
49
|
*
|
|
@@ -40,12 +57,8 @@ export class Nullifiers {
|
|
|
40
57
|
storageAddress: Fr,
|
|
41
58
|
nullifier: Fr,
|
|
42
59
|
): Promise<[/*exists=*/ boolean, /*isPending=*/ boolean, /*leafIndex=*/ Fr]> {
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
// Then check parent's cache
|
|
46
|
-
if (!existsAsPending && this.parentCache) {
|
|
47
|
-
existsAsPending = this.parentCache?.exists(storageAddress, nullifier);
|
|
48
|
-
}
|
|
60
|
+
// Check this cache and parent's (recursively)
|
|
61
|
+
const existsAsPending = this.checkExistsHereOrParent(storageAddress, nullifier);
|
|
49
62
|
// Finally try the host's Aztec state (a trip to the database)
|
|
50
63
|
// If the value is found in the database, it will be associated with a leaf index!
|
|
51
64
|
let leafIndex: bigint | undefined = undefined;
|
|
@@ -17,14 +17,13 @@ type PublicStorageReadResult = {
|
|
|
17
17
|
export class PublicStorage {
|
|
18
18
|
/** Cached storage writes. */
|
|
19
19
|
private cache: PublicStorageCache;
|
|
20
|
-
/** Parent's storage cache. Checked on cache-miss. */
|
|
21
|
-
private readonly parentCache: PublicStorageCache | undefined;
|
|
22
|
-
/** Reference to node storage. Checked on parent cache-miss. */
|
|
23
|
-
private readonly hostPublicStorage: PublicStateDB;
|
|
24
20
|
|
|
25
|
-
constructor(
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
constructor(
|
|
22
|
+
/** Reference to node storage. Checked on parent cache-miss. */
|
|
23
|
+
private readonly hostPublicStorage: PublicStateDB,
|
|
24
|
+
/** Parent's storage. Checked on this' cache-miss. */
|
|
25
|
+
private readonly parent?: PublicStorage,
|
|
26
|
+
) {
|
|
28
27
|
this.cache = new PublicStorageCache();
|
|
29
28
|
}
|
|
30
29
|
|
|
@@ -35,10 +34,29 @@ export class PublicStorage {
|
|
|
35
34
|
return this.cache;
|
|
36
35
|
}
|
|
37
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Read a storage value from this' cache or parent's (recursively).
|
|
39
|
+
* DOES NOT CHECK HOST STORAGE!
|
|
40
|
+
*
|
|
41
|
+
* @param storageAddress - the address of the contract whose storage is being read from
|
|
42
|
+
* @param slot - the slot in the contract's storage being read from
|
|
43
|
+
* @returns value: the latest value written according to this cache or the parent's. undefined on cache miss.
|
|
44
|
+
*/
|
|
45
|
+
public readHereOrParent(storageAddress: Fr, slot: Fr): Fr | undefined {
|
|
46
|
+
// First try check this storage cache
|
|
47
|
+
let value = this.cache.read(storageAddress, slot);
|
|
48
|
+
// Then try parent's storage cache
|
|
49
|
+
if (!value && this.parent) {
|
|
50
|
+
// Note: this will recurse to grandparent/etc until a cache-hit is encountered.
|
|
51
|
+
value = this.parent.readHereOrParent(storageAddress, slot);
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
|
|
38
56
|
/**
|
|
39
57
|
* Read a value from storage.
|
|
40
58
|
* 1. Check cache.
|
|
41
|
-
* 2. Check parent
|
|
59
|
+
* 2. Check parent cache.
|
|
42
60
|
* 3. Fall back to the host state.
|
|
43
61
|
* 4. Not found! Value has never been written to before. Flag it as non-existent and return value zero.
|
|
44
62
|
*
|
|
@@ -48,12 +66,8 @@ export class PublicStorage {
|
|
|
48
66
|
*/
|
|
49
67
|
public async read(storageAddress: Fr, slot: Fr): Promise<PublicStorageReadResult> {
|
|
50
68
|
let cached = false;
|
|
51
|
-
//
|
|
52
|
-
let value = this.
|
|
53
|
-
// Then try parent's storage cache (if it exists / written to earlier in this TX)
|
|
54
|
-
if (!value && this.parentCache) {
|
|
55
|
-
value = this.parentCache?.read(storageAddress, slot);
|
|
56
|
-
}
|
|
69
|
+
// Check this cache and parent's (recursively)
|
|
70
|
+
let value = this.readHereOrParent(storageAddress, slot);
|
|
57
71
|
// Finally try the host's Aztec state (a trip to the database)
|
|
58
72
|
if (!value) {
|
|
59
73
|
value = await this.hostPublicStorage.storageRead(storageAddress, slot);
|
|
@@ -73,8 +87,8 @@ export class PublicStorage {
|
|
|
73
87
|
* @param slot - the slot in the contract's storage being written to
|
|
74
88
|
* @param value - the value being written to the slot
|
|
75
89
|
*/
|
|
76
|
-
public write(storageAddress: Fr,
|
|
77
|
-
this.cache.write(storageAddress,
|
|
90
|
+
public write(storageAddress: Fr, slot: Fr, value: Fr) {
|
|
91
|
+
this.cache.write(storageAddress, slot, value);
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
/**
|
package/src/avm/journal/trace.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AvmExecutionHints, AvmHint, Vector } from '@aztec/circuits.js';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
|
|
3
4
|
import {
|
|
@@ -131,6 +132,7 @@ export class WorldStateAccessTrace {
|
|
|
131
132
|
leafIndex: msgLeafIndex,
|
|
132
133
|
msgHash: msgHash,
|
|
133
134
|
exists: exists,
|
|
135
|
+
counter: new Fr(this.accessCounter),
|
|
134
136
|
//endLifetime: Fr.ZERO, // FIXME
|
|
135
137
|
};
|
|
136
138
|
this.l1ToL2MessageChecks.push(traced);
|
|
@@ -169,4 +171,14 @@ export class WorldStateAccessTrace {
|
|
|
169
171
|
// it is assumed that the incoming trace was initialized with this as parent, so accept counter
|
|
170
172
|
this.accessCounter = incomingTrace.accessCounter;
|
|
171
173
|
}
|
|
174
|
+
|
|
175
|
+
// TODO(dbanks12): should only return hints for one call.... shouldn't include nested calls (merged in traces)
|
|
176
|
+
public toHints(): AvmExecutionHints {
|
|
177
|
+
return new AvmExecutionHints(
|
|
178
|
+
new Vector(this.publicStorageReads.map(read => new AvmHint(read.counter, read.value))),
|
|
179
|
+
new Vector(this.noteHashChecks.map(check => new AvmHint(check.counter, new Fr(check.exists ? 1 : 0)))),
|
|
180
|
+
new Vector(this.nullifierChecks.map(check => new AvmHint(check.counter, new Fr(check.exists ? 1 : 0)))),
|
|
181
|
+
new Vector(this.l1ToL2MessageChecks.map(check => new AvmHint(check.counter, new Fr(check.exists ? 1 : 0)))),
|
|
182
|
+
);
|
|
183
|
+
}
|
|
172
184
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { AvmContext } from '../avm_context.js';
|
|
2
2
|
import { Uint8 } from '../avm_memory_types.js';
|
|
3
|
-
import { InstructionExecutionError } from '../errors.js';
|
|
3
|
+
import { InstructionExecutionError, StaticCallAlterationError } from '../errors.js';
|
|
4
4
|
import { NullifierCollisionError } from '../journal/nullifiers.js';
|
|
5
5
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
6
6
|
import { Addressing } from './addressing_mode.js';
|
|
7
7
|
import { Instruction } from './instruction.js';
|
|
8
|
-
import { StaticCallStorageAlterError } from './storage.js';
|
|
9
8
|
|
|
10
9
|
export class NoteHashExists extends Instruction {
|
|
11
10
|
static type: string = 'NOTEHASHEXISTS';
|
|
@@ -65,7 +64,7 @@ export class EmitNoteHash extends Instruction {
|
|
|
65
64
|
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
66
65
|
|
|
67
66
|
if (context.environment.isStaticCall) {
|
|
68
|
-
throw new
|
|
67
|
+
throw new StaticCallAlterationError();
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
const noteHash = memory.get(this.noteHashOffset).toFr();
|
|
@@ -125,7 +124,7 @@ export class EmitNullifier extends Instruction {
|
|
|
125
124
|
|
|
126
125
|
public async execute(context: AvmContext): Promise<void> {
|
|
127
126
|
if (context.environment.isStaticCall) {
|
|
128
|
-
throw new
|
|
127
|
+
throw new StaticCallAlterationError();
|
|
129
128
|
}
|
|
130
129
|
|
|
131
130
|
const memoryOperations = { reads: 1, indirect: this.indirect };
|
|
@@ -210,7 +209,7 @@ export class EmitUnencryptedLog extends Instruction {
|
|
|
210
209
|
|
|
211
210
|
public async execute(context: AvmContext): Promise<void> {
|
|
212
211
|
if (context.environment.isStaticCall) {
|
|
213
|
-
throw new
|
|
212
|
+
throw new StaticCallAlterationError();
|
|
214
213
|
}
|
|
215
214
|
|
|
216
215
|
const memoryOperations = { reads: 1 + this.logSize, indirect: this.indirect };
|
|
@@ -244,7 +243,7 @@ export class SendL2ToL1Message extends Instruction {
|
|
|
244
243
|
|
|
245
244
|
public async execute(context: AvmContext): Promise<void> {
|
|
246
245
|
if (context.environment.isStaticCall) {
|
|
247
|
-
throw new
|
|
246
|
+
throw new StaticCallAlterationError();
|
|
248
247
|
}
|
|
249
248
|
|
|
250
249
|
const memoryOperations = { reads: 2, indirect: this.indirect };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AvmContext } from '../avm_context.js';
|
|
2
|
-
import {
|
|
3
|
-
import { type Field, type MemoryOperations, type MemoryValue, TypeTag } from '../avm_memory_types.js';
|
|
2
|
+
import { type Field, type MemoryValue, TypeTag } from '../avm_memory_types.js';
|
|
4
3
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
5
4
|
import { Instruction } from './instruction.js';
|
|
6
5
|
import { ThreeOperandInstruction } from './instruction_impl.js';
|
|
@@ -23,12 +22,6 @@ export abstract class ThreeOperandArithmeticInstruction extends ThreeOperandInst
|
|
|
23
22
|
context.machineState.incrementPc();
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
protected override gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }>) {
|
|
27
|
-
const baseGasCost = getGasCostForTypeTag(this.inTag, getBaseGasCost(this.opcode));
|
|
28
|
-
const memoryGasCost = getMemoryGasCost(memoryOps);
|
|
29
|
-
return sumGas(baseGasCost, memoryGasCost);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
25
|
protected abstract compute(a: MemoryValue, b: MemoryValue): MemoryValue;
|
|
33
26
|
}
|
|
34
27
|
|
|
@@ -101,10 +94,4 @@ export class FieldDiv extends Instruction {
|
|
|
101
94
|
memory.assert(memoryOperations);
|
|
102
95
|
context.machineState.incrementPc();
|
|
103
96
|
}
|
|
104
|
-
|
|
105
|
-
protected override gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }>) {
|
|
106
|
-
const baseGasCost = getGasCostForTypeTag(TypeTag.FIELD, getBaseGasCost(this.opcode));
|
|
107
|
-
const memoryGasCost = getMemoryGasCost(memoryOps);
|
|
108
|
-
return sumGas(baseGasCost, memoryGasCost);
|
|
109
|
-
}
|
|
110
97
|
}
|
|
@@ -50,7 +50,7 @@ export class ToRadixLE extends Instruction {
|
|
|
50
50
|
value /= radixBN;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const res =
|
|
53
|
+
const res = limbArray.map(byte => new Uint8(byte));
|
|
54
54
|
memory.setSlice(dstOffset, res);
|
|
55
55
|
|
|
56
56
|
memory.assert(memoryOperations);
|
|
@@ -3,7 +3,7 @@ import { padArrayEnd } from '@aztec/foundation/collection';
|
|
|
3
3
|
|
|
4
4
|
import { convertAvmResultsToPxResult, createPublicExecution } from '../../public/transitional_adaptors.js';
|
|
5
5
|
import type { AvmContext } from '../avm_context.js';
|
|
6
|
-
import { gasLeftToGas
|
|
6
|
+
import { gasLeftToGas } from '../avm_gas.js';
|
|
7
7
|
import { Field, Uint8 } from '../avm_memory_types.js';
|
|
8
8
|
import { type AvmContractCallResults } from '../avm_message_call_result.js';
|
|
9
9
|
import { AvmSimulator } from '../avm_simulator.js';
|
|
@@ -40,7 +40,7 @@ abstract class ExternalCall extends Instruction {
|
|
|
40
40
|
// Function selector is temporary since eventually public contract bytecode will be one blob
|
|
41
41
|
// containing all functions, and function selector will become an application-level mechanism
|
|
42
42
|
// (e.g. first few bytes of calldata + compiler-generated jump table)
|
|
43
|
-
private
|
|
43
|
+
private functionSelectorOffset: number,
|
|
44
44
|
) {
|
|
45
45
|
super();
|
|
46
46
|
}
|
|
@@ -57,33 +57,44 @@ abstract class ExternalCall extends Instruction {
|
|
|
57
57
|
const callAddress = memory.getAs<Field>(addrOffset);
|
|
58
58
|
const calldataSize = memory.get(argsSizeOffset).toNumber();
|
|
59
59
|
const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const
|
|
60
|
+
const functionSelector = memory.getAs<Field>(this.functionSelectorOffset).toFr();
|
|
61
|
+
// If we are already in a static call, we propagate the environment.
|
|
62
|
+
const callType = context.environment.isStaticCall ? 'STATICCALL' : this.type;
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
// First we consume the gas for this operation.
|
|
65
65
|
const memoryOperations = { reads: calldataSize + 5, writes: 1 + this.retSize, indirect: this.indirect };
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
67
|
+
// Then we consume the gas allocated for the nested call. The excess will be refunded later.
|
|
68
|
+
// Gas allocation is capped by the amount of gas left in the current context.
|
|
69
|
+
// We have to do some dancing here because the gas allocation is a field,
|
|
70
|
+
// but in the machine state we track gas as a number.
|
|
71
|
+
const allocatedL2Gas = Number(BigIntMin(memory.get(gasOffset).toBigInt(), BigInt(context.machineState.l2GasLeft)));
|
|
72
|
+
const allocatedDaGas = Number(
|
|
73
|
+
BigIntMin(memory.get(gasOffset + 1).toBigInt(), BigInt(context.machineState.daGasLeft)),
|
|
74
|
+
);
|
|
75
|
+
const allocatedGas = { l2Gas: allocatedL2Gas, daGas: allocatedDaGas };
|
|
76
|
+
context.machineState.consumeGas(allocatedGas);
|
|
68
77
|
|
|
69
78
|
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
70
79
|
const nestedContext = context.createNestedContractCallContext(
|
|
71
80
|
callAddress.toFr(),
|
|
72
81
|
calldata,
|
|
73
82
|
allocatedGas,
|
|
74
|
-
|
|
83
|
+
callType,
|
|
75
84
|
FunctionSelector.fromField(functionSelector),
|
|
76
85
|
);
|
|
77
86
|
const startSideEffectCounter = nestedContext.persistableState.trace.accessCounter;
|
|
78
87
|
|
|
79
88
|
const oldStyleExecution = createPublicExecution(startSideEffectCounter, nestedContext.environment, calldata);
|
|
80
|
-
const
|
|
89
|
+
const simulator = new AvmSimulator(nestedContext);
|
|
90
|
+
const nestedCallResults: AvmContractCallResults = await simulator.execute();
|
|
81
91
|
const pxResults = convertAvmResultsToPxResult(
|
|
82
92
|
nestedCallResults,
|
|
83
93
|
startSideEffectCounter,
|
|
84
94
|
oldStyleExecution,
|
|
85
95
|
Gas.from(allocatedGas),
|
|
86
96
|
nestedContext,
|
|
97
|
+
simulator.getBytecode(),
|
|
87
98
|
);
|
|
88
99
|
// store the old PublicExecutionResult object to maintain a recursive data structure for the old kernel
|
|
89
100
|
context.persistableState.transitionalExecutionResult.nestedExecutions.push(pxResults);
|
|
@@ -215,3 +226,8 @@ export class Revert extends Instruction {
|
|
|
215
226
|
memory.assert(memoryOperations);
|
|
216
227
|
}
|
|
217
228
|
}
|
|
229
|
+
|
|
230
|
+
/** Returns the smaller of two bigints. */
|
|
231
|
+
function BigIntMin(a: bigint, b: bigint): bigint {
|
|
232
|
+
return a < b ? a : b;
|
|
233
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { strict as assert } from 'assert';
|
|
2
2
|
|
|
3
3
|
import type { AvmContext } from '../avm_context.js';
|
|
4
|
-
import { getBaseGasCost,
|
|
4
|
+
import { getBaseGasCost, sumGas } from '../avm_gas.js';
|
|
5
5
|
import { type MemoryOperations } from '../avm_memory_types.js';
|
|
6
6
|
import { type BufferCursor } from '../serialization/buffer_cursor.js';
|
|
7
7
|
import { Opcode, type OperandType, deserialize, serialize } from '../serialization/instruction_serialization.js';
|
|
@@ -67,9 +67,11 @@ export abstract class Instruction {
|
|
|
67
67
|
* @param memoryOps Memory operations performed by the instruction.
|
|
68
68
|
* @returns Gas cost.
|
|
69
69
|
*/
|
|
70
|
-
protected gasCost(
|
|
70
|
+
protected gasCost(_memoryOps: Partial<MemoryOperations & { indirect: number }> = {}) {
|
|
71
71
|
const baseGasCost = getBaseGasCost(this.opcode);
|
|
72
|
-
|
|
72
|
+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/6861): reconsider.
|
|
73
|
+
// const memoryGasCost = getMemoryGasCost(memoryOps);
|
|
74
|
+
const memoryGasCost = { l2Gas: 0, daGas: 0 };
|
|
73
75
|
return sumGas(baseGasCost, memoryGasCost);
|
|
74
76
|
}
|
|
75
77
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AvmContext } from '../avm_context.js';
|
|
2
|
-
import {
|
|
3
|
-
import { Field, type MemoryOperations, TaggedMemory, TypeTag } from '../avm_memory_types.js';
|
|
2
|
+
import { Field, TaggedMemory, TypeTag } from '../avm_memory_types.js';
|
|
4
3
|
import { InstructionExecutionError } from '../errors.js';
|
|
5
4
|
import { BufferCursor } from '../serialization/buffer_cursor.js';
|
|
6
5
|
import { Opcode, OperandType, deserialize, serialize } from '../serialization/instruction_serialization.js';
|
|
@@ -216,10 +215,4 @@ export class CalldataCopy extends Instruction {
|
|
|
216
215
|
memory.assert(memoryOperations);
|
|
217
216
|
context.machineState.incrementPc();
|
|
218
217
|
}
|
|
219
|
-
|
|
220
|
-
protected override gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }> = {}) {
|
|
221
|
-
const baseGasCost = getBaseGasCost(this.opcode);
|
|
222
|
-
const memoryGasCost = getMemoryGasCost(memoryOps);
|
|
223
|
-
return sumGas(baseGasCost, memoryGasCost);
|
|
224
|
-
}
|
|
225
218
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
|
|
3
3
|
import type { AvmContext } from '../avm_context.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { InstructionExecutionError } from '../errors.js';
|
|
4
|
+
import { Field } from '../avm_memory_types.js';
|
|
5
|
+
import { StaticCallAlterationError } from '../errors.js';
|
|
7
6
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
8
7
|
import { Addressing } from './addressing_mode.js';
|
|
9
8
|
import { Instruction } from './instruction.js';
|
|
@@ -26,12 +25,6 @@ abstract class BaseStorageInstruction extends Instruction {
|
|
|
26
25
|
) {
|
|
27
26
|
super();
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
protected override gasCost(memoryOps: Partial<MemoryOperations & { indirect: number }>): Gas {
|
|
31
|
-
const baseGasCost = mulGas(getBaseGasCost(this.opcode), this.size);
|
|
32
|
-
const memoryGasCost = getMemoryGasCost(memoryOps);
|
|
33
|
-
return sumGas(baseGasCost, memoryGasCost);
|
|
34
|
-
}
|
|
35
28
|
}
|
|
36
29
|
|
|
37
30
|
export class SStore extends BaseStorageInstruction {
|
|
@@ -44,7 +37,7 @@ export class SStore extends BaseStorageInstruction {
|
|
|
44
37
|
|
|
45
38
|
public async execute(context: AvmContext): Promise<void> {
|
|
46
39
|
if (context.environment.isStaticCall) {
|
|
47
|
-
throw new
|
|
40
|
+
throw new StaticCallAlterationError();
|
|
48
41
|
}
|
|
49
42
|
|
|
50
43
|
const memoryOperations = { reads: this.size + 1, indirect: this.indirect };
|
|
@@ -100,13 +93,3 @@ export class SLoad extends BaseStorageInstruction {
|
|
|
100
93
|
memory.assert(memoryOperations);
|
|
101
94
|
}
|
|
102
95
|
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Error is thrown when a static call attempts to alter storage
|
|
106
|
-
*/
|
|
107
|
-
export class StaticCallStorageAlterError extends InstructionExecutionError {
|
|
108
|
-
constructor() {
|
|
109
|
-
super('Static calls cannot alter storage');
|
|
110
|
-
this.name = 'StaticCallStorageAlterError';
|
|
111
|
-
}
|
|
112
|
-
}
|