@aztec/simulator 0.31.0 → 0.32.1
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 +5 -5
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm_types.d.ts +1 -1
- package/dest/acvm/acvm_types.d.ts.map +1 -1
- package/dest/acvm/deserialize.d.ts +1 -1
- package/dest/acvm/deserialize.d.ts.map +1 -1
- package/dest/acvm/oracle/debug.d.ts +2 -2
- package/dest/acvm/oracle/debug.d.ts.map +1 -1
- package/dest/acvm/oracle/index.d.ts +1 -1
- package/dest/acvm/oracle/index.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.d.ts +2 -2
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.d.ts +6 -6
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/serialize.d.ts +4 -4
- package/dest/acvm/serialize.d.ts.map +1 -1
- package/dest/acvm/serialize.js +1 -1
- package/dest/avm/avm_context.d.ts +4 -4
- package/dest/avm/avm_context.d.ts.map +1 -1
- package/dest/avm/avm_context.js +1 -1
- package/dest/avm/avm_execution_environment.d.ts +4 -4
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +3 -3
- package/dest/avm/avm_gas_cost.d.ts +307 -3
- package/dest/avm/avm_gas_cost.d.ts.map +1 -1
- package/dest/avm/avm_gas_cost.js +42 -8
- package/dest/avm/avm_machine_state.d.ts +2 -2
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +1 -1
- package/dest/avm/avm_memory_types.d.ts +1 -1
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +1 -1
- package/dest/avm/avm_message_call_result.d.ts +1 -1
- package/dest/avm/avm_message_call_result.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +1 -1
- package/dest/avm/errors.d.ts +1 -1
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/fixtures/index.d.ts +1 -1
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +5 -5
- 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 +2 -2
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/trace.d.ts +1 -1
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace_types.d.ts +1 -1
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/opcodes/addressing_mode.d.ts +2 -2
- package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/avm/opcodes/addressing_mode.js +1 -1
- package/dest/avm/opcodes/arithmetic.d.ts +15 -12
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +25 -36
- package/dest/avm/opcodes/environment_getters.d.ts +1 -1
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.d.ts +1 -1
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +2 -2
- package/dest/avm/opcodes/instruction.d.ts +4 -4
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +7 -3
- package/dest/avm/opcodes/memory.d.ts +3 -0
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +8 -1
- package/dest/avm/temporary_executor_migration.d.ts +4 -4
- package/dest/avm/temporary_executor_migration.d.ts.map +1 -1
- package/dest/avm/temporary_executor_migration.js +3 -3
- package/dest/client/client_execution_context.d.ts +13 -13
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +5 -5
- package/dest/client/db_oracle.d.ts +9 -9
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/execution_note_cache.d.ts +2 -2
- package/dest/client/execution_note_cache.d.ts.map +1 -1
- package/dest/client/execution_result.d.ts +9 -9
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +1 -1
- package/dest/client/pick_notes.d.ts +1 -1
- package/dest/client/pick_notes.d.ts.map +1 -1
- package/dest/client/pick_notes.js +1 -1
- package/dest/client/private_execution.d.ts +5 -5
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +1 -1
- package/dest/client/simulator.d.ts +6 -6
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +1 -1
- package/dest/client/unconstrained_execution.d.ts +5 -5
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +1 -1
- package/dest/client/view_data_oracle.d.ts +6 -6
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +1 -1
- package/dest/common/errors.d.ts +1 -1
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +1 -1
- package/dest/public/db.d.ts +6 -6
- package/dest/public/db.d.ts.map +1 -1
- package/dest/public/execution.d.ts +4 -4
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts +3 -3
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +3 -3
- package/dest/public/public_execution_context.d.ts +8 -8
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +4 -4
- package/dest/public/state_actions.d.ts +2 -2
- package/dest/public/state_actions.d.ts.map +1 -1
- package/dest/simulator/acvm_native.d.ts +3 -3
- package/dest/simulator/acvm_native.d.ts.map +1 -1
- package/dest/simulator/acvm_wasm.d.ts +3 -3
- package/dest/simulator/acvm_wasm.d.ts.map +1 -1
- package/dest/simulator/acvm_wasm.js +2 -2
- package/dest/simulator/simulation_provider.d.ts +2 -2
- package/dest/simulator/simulation_provider.d.ts.map +1 -1
- package/dest/test/utils.d.ts +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +2 -3
- package/dest/utils.d.ts +1 -1
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +2 -2
- package/package.json +5 -5
- package/src/acvm/acvm.ts +8 -8
- package/src/acvm/acvm_types.ts +1 -1
- package/src/acvm/deserialize.ts +1 -1
- package/src/acvm/oracle/debug.ts +2 -2
- package/src/acvm/oracle/index.ts +1 -1
- package/src/acvm/oracle/oracle.ts +2 -2
- package/src/acvm/oracle/typed_oracle.ts +18 -18
- package/src/acvm/serialize.ts +4 -4
- package/src/avm/avm_context.ts +4 -4
- package/src/avm/avm_execution_environment.ts +6 -9
- package/src/avm/avm_gas_cost.ts +46 -8
- package/src/avm/avm_machine_state.ts +2 -2
- package/src/avm/avm_memory_types.ts +1 -1
- package/src/avm/avm_message_call_result.ts +1 -1
- package/src/avm/avm_simulator.ts +1 -1
- package/src/avm/errors.ts +1 -1
- package/src/avm/fixtures/index.ts +9 -4
- package/src/avm/journal/host_storage.ts +1 -1
- package/src/avm/journal/journal.ts +2 -2
- package/src/avm/journal/trace.ts +1 -1
- package/src/avm/journal/trace_types.ts +1 -1
- package/src/avm/opcodes/addressing_mode.ts +2 -2
- package/src/avm/opcodes/arithmetic.ts +34 -47
- package/src/avm/opcodes/bitwise.ts +1 -1
- package/src/avm/opcodes/control_flow.ts +1 -1
- package/src/avm/opcodes/environment_getters.ts +1 -1
- package/src/avm/opcodes/hashing.ts +2 -2
- package/src/avm/opcodes/instruction.ts +9 -5
- package/src/avm/opcodes/memory.ts +9 -0
- package/src/avm/temporary_executor_migration.ts +8 -8
- package/src/client/client_execution_context.ts +22 -20
- package/src/client/db_oracle.ts +16 -10
- package/src/client/execution_note_cache.ts +2 -2
- package/src/client/execution_result.ts +13 -9
- package/src/client/pick_notes.ts +1 -1
- package/src/client/private_execution.ts +5 -5
- package/src/client/simulator.ts +8 -8
- package/src/client/unconstrained_execution.ts +5 -5
- package/src/client/view_data_oracle.ts +11 -11
- package/src/common/errors.ts +1 -1
- package/src/public/db.ts +6 -6
- package/src/public/execution.ts +12 -12
- package/src/public/executor.ts +5 -5
- package/src/public/public_execution_context.ts +18 -8
- package/src/public/state_actions.ts +2 -2
- package/src/simulator/acvm_native.ts +3 -3
- package/src/simulator/acvm_wasm.ts +8 -4
- package/src/simulator/simulation_provider.ts +2 -2
- package/src/test/utils.ts +2 -3
- package/src/utils.ts +2 -2
package/src/avm/avm_gas_cost.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TypeTag } from './avm_memory_types.js';
|
|
1
2
|
import { Opcode } from './serialization/instruction_serialization.js';
|
|
2
3
|
|
|
3
4
|
/** Gas cost in L1, L2, and DA for a given instruction. */
|
|
@@ -7,6 +8,11 @@ export type GasCost = {
|
|
|
7
8
|
daGas: number;
|
|
8
9
|
};
|
|
9
10
|
|
|
11
|
+
/** Creates a new instance with all values set to zero except the ones set. */
|
|
12
|
+
export function makeGasCost(gasCost: Partial<GasCost>) {
|
|
13
|
+
return { ...EmptyGasCost, ...gasCost };
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
/** Gas cost of zero across all gas dimensions. */
|
|
11
17
|
export const EmptyGasCost = {
|
|
12
18
|
l1Gas: 0,
|
|
@@ -14,18 +20,21 @@ export const EmptyGasCost = {
|
|
|
14
20
|
daGas: 0,
|
|
15
21
|
};
|
|
16
22
|
|
|
17
|
-
/** Dimensions of gas usage: L1, L2, and DA */
|
|
23
|
+
/** Dimensions of gas usage: L1, L2, and DA. */
|
|
18
24
|
export const GasDimensions = ['l1Gas', 'l2Gas', 'daGas'] as const;
|
|
19
25
|
|
|
26
|
+
/** Null object to represent a gas cost that's dynamic instead of fixed for a given instruction. */
|
|
27
|
+
export const DynamicGasCost = Symbol('DynamicGasCost');
|
|
28
|
+
|
|
20
29
|
/** Temporary default gas cost. We should eventually remove all usage of this variable in favor of actual gas for each opcode. */
|
|
21
30
|
const TemporaryDefaultGasCost = { l1Gas: 0, l2Gas: 10, daGas: 0 };
|
|
22
31
|
|
|
23
32
|
/** Gas costs for each instruction. */
|
|
24
|
-
export const GasCosts
|
|
25
|
-
[Opcode.ADD]:
|
|
26
|
-
[Opcode.SUB]:
|
|
27
|
-
[Opcode.MUL]:
|
|
28
|
-
[Opcode.DIV]:
|
|
33
|
+
export const GasCosts = {
|
|
34
|
+
[Opcode.ADD]: DynamicGasCost,
|
|
35
|
+
[Opcode.SUB]: DynamicGasCost,
|
|
36
|
+
[Opcode.MUL]: DynamicGasCost,
|
|
37
|
+
[Opcode.DIV]: DynamicGasCost,
|
|
29
38
|
[Opcode.FDIV]: TemporaryDefaultGasCost,
|
|
30
39
|
[Opcode.EQ]: TemporaryDefaultGasCost,
|
|
31
40
|
[Opcode.LT]: TemporaryDefaultGasCost,
|
|
@@ -55,7 +64,7 @@ export const GasCosts: Record<Opcode, GasCost> = {
|
|
|
55
64
|
[Opcode.BLOCKL1GASLIMIT]: TemporaryDefaultGasCost,
|
|
56
65
|
[Opcode.BLOCKL2GASLIMIT]: TemporaryDefaultGasCost,
|
|
57
66
|
[Opcode.BLOCKDAGASLIMIT]: TemporaryDefaultGasCost,
|
|
58
|
-
[Opcode.CALLDATACOPY]:
|
|
67
|
+
[Opcode.CALLDATACOPY]: DynamicGasCost,
|
|
59
68
|
// Gas
|
|
60
69
|
[Opcode.L1GASLEFT]: TemporaryDefaultGasCost,
|
|
61
70
|
[Opcode.L2GASLEFT]: TemporaryDefaultGasCost,
|
|
@@ -66,7 +75,7 @@ export const GasCosts: Record<Opcode, GasCost> = {
|
|
|
66
75
|
[Opcode.INTERNALCALL]: TemporaryDefaultGasCost,
|
|
67
76
|
[Opcode.INTERNALRETURN]: TemporaryDefaultGasCost,
|
|
68
77
|
// Memory
|
|
69
|
-
[Opcode.SET]:
|
|
78
|
+
[Opcode.SET]: DynamicGasCost,
|
|
70
79
|
[Opcode.MOV]: TemporaryDefaultGasCost,
|
|
71
80
|
[Opcode.CMOV]: TemporaryDefaultGasCost,
|
|
72
81
|
// World state
|
|
@@ -91,4 +100,33 @@ export const GasCosts: Record<Opcode, GasCost> = {
|
|
|
91
100
|
[Opcode.POSEIDON]: TemporaryDefaultGasCost,
|
|
92
101
|
[Opcode.SHA256]: TemporaryDefaultGasCost, // temp - may be removed, but alot of contracts rely on i: TemporaryDefaultGasCost,
|
|
93
102
|
[Opcode.PEDERSEN]: TemporaryDefaultGasCost, // temp - may be removed, but alot of contracts rely on i: TemporaryDefaultGasCost,t
|
|
103
|
+
} as const;
|
|
104
|
+
|
|
105
|
+
/** Constants used in base cost calculations. */
|
|
106
|
+
export const GasCostConstants = {
|
|
107
|
+
SET_COST_PER_BYTE: 100,
|
|
108
|
+
CALLDATACOPY_COST_PER_BYTE: 10,
|
|
109
|
+
ARITHMETIC_COST_PER_BYTE: 10,
|
|
110
|
+
ARITHMETIC_COST_PER_INDIRECT_ACCESS: 5,
|
|
94
111
|
};
|
|
112
|
+
|
|
113
|
+
/** Returns a multiplier based on the size of the type represented by the tag. Throws on uninitialized or invalid. */
|
|
114
|
+
export function getGasCostMultiplierFromTypeTag(tag: TypeTag) {
|
|
115
|
+
switch (tag) {
|
|
116
|
+
case TypeTag.UINT8:
|
|
117
|
+
return 1;
|
|
118
|
+
case TypeTag.UINT16:
|
|
119
|
+
return 2;
|
|
120
|
+
case TypeTag.UINT32:
|
|
121
|
+
return 4;
|
|
122
|
+
case TypeTag.UINT64:
|
|
123
|
+
return 8;
|
|
124
|
+
case TypeTag.UINT128:
|
|
125
|
+
return 16;
|
|
126
|
+
case TypeTag.FIELD:
|
|
127
|
+
return 32;
|
|
128
|
+
case TypeTag.INVALID:
|
|
129
|
+
case TypeTag.UNINITIALIZED:
|
|
130
|
+
throw new Error(`Invalid tag type for gas cost multiplier: ${TypeTag[tag]}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Fr } from '@aztec/circuits.js';
|
|
1
|
+
import { type Fr } from '@aztec/circuits.js';
|
|
2
2
|
|
|
3
|
-
import { GasCost, GasDimensions } from './avm_gas_cost.js';
|
|
3
|
+
import { type GasCost, GasDimensions } from './avm_gas_cost.js';
|
|
4
4
|
import { TaggedMemory } from './avm_memory_types.js';
|
|
5
5
|
import { AvmContractCallResults } from './avm_message_call_result.js';
|
|
6
6
|
import { OutOfGasError } from './errors.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
4
4
|
|
|
5
5
|
import { strict as assert } from 'assert';
|
|
6
6
|
|
package/src/avm/avm_simulator.ts
CHANGED
package/src/avm/errors.ts
CHANGED
|
@@ -8,7 +8,12 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
8
8
|
import { mock } from 'jest-mock-extended';
|
|
9
9
|
import merge from 'lodash.merge';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
type CommitmentsDB,
|
|
13
|
+
MessageLoadOracleInputs,
|
|
14
|
+
type PublicContractsDB,
|
|
15
|
+
type PublicStateDB,
|
|
16
|
+
} from '../../index.js';
|
|
12
17
|
import { AvmContext } from '../avm_context.js';
|
|
13
18
|
import { AvmContextInputs, AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
14
19
|
import { AvmMachineState } from '../avm_machine_state.js';
|
|
@@ -89,9 +94,9 @@ export function initGlobalVariables(overrides?: Partial<GlobalVariables>): Globa
|
|
|
89
94
|
*/
|
|
90
95
|
export function initMachineState(overrides?: Partial<AvmMachineState>): AvmMachineState {
|
|
91
96
|
return AvmMachineState.fromState({
|
|
92
|
-
l1GasLeft: overrides?.l1GasLeft ??
|
|
93
|
-
l2GasLeft: overrides?.l2GasLeft ??
|
|
94
|
-
daGasLeft: overrides?.daGasLeft ??
|
|
97
|
+
l1GasLeft: overrides?.l1GasLeft ?? 100e6,
|
|
98
|
+
l2GasLeft: overrides?.l2GasLeft ?? 100e6,
|
|
99
|
+
daGasLeft: overrides?.daGasLeft ?? 100e6,
|
|
95
100
|
});
|
|
96
101
|
}
|
|
97
102
|
|
|
@@ -3,11 +3,11 @@ import { AztecAddress, EthAddress, L2ToL1Message } from '@aztec/circuits.js';
|
|
|
3
3
|
import { EventSelector } from '@aztec/foundation/abi';
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
|
|
6
|
-
import { HostStorage } from './host_storage.js';
|
|
6
|
+
import { type HostStorage } from './host_storage.js';
|
|
7
7
|
import { Nullifiers } from './nullifiers.js';
|
|
8
8
|
import { PublicStorage } from './public_storage.js';
|
|
9
9
|
import { WorldStateAccessTrace } from './trace.js';
|
|
10
|
-
import { TracedL1toL2MessageCheck, TracedNoteHashCheck, TracedNullifierCheck } from './trace_types.js';
|
|
10
|
+
import { type TracedL1toL2MessageCheck, type TracedNoteHashCheck, type TracedNullifierCheck } from './trace_types.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Data held within the journal
|
package/src/avm/journal/trace.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
|
|
3
|
-
import { TracedL1toL2MessageCheck, TracedNoteHashCheck, TracedNullifierCheck } from './trace_types.js';
|
|
3
|
+
import { type TracedL1toL2MessageCheck, type TracedNoteHashCheck, type TracedNullifierCheck } from './trace_types.js';
|
|
4
4
|
|
|
5
5
|
export class WorldStateAccessTrace {
|
|
6
6
|
public accessCounter: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { strict as assert } from 'assert';
|
|
2
2
|
|
|
3
|
-
import { TaggedMemory } from '../avm_memory_types.js';
|
|
3
|
+
import { type TaggedMemory } from '../avm_memory_types.js';
|
|
4
4
|
|
|
5
5
|
export enum AddressingMode {
|
|
6
6
|
DIRECT,
|
|
@@ -12,7 +12,7 @@ export enum AddressingMode {
|
|
|
12
12
|
export class Addressing {
|
|
13
13
|
public constructor(
|
|
14
14
|
/** The addressing mode for each operand. The length of this array is the number of operands of the instruction. */
|
|
15
|
-
|
|
15
|
+
public readonly modePerOperand: AddressingMode[],
|
|
16
16
|
) {
|
|
17
17
|
assert(modePerOperand.length <= 8, 'At most 8 operands are supported');
|
|
18
18
|
}
|
|
@@ -1,84 +1,71 @@
|
|
|
1
1
|
import type { AvmContext } from '../avm_context.js';
|
|
2
|
-
import {
|
|
2
|
+
import { type GasCost, GasCostConstants, getGasCostMultiplierFromTypeTag, makeGasCost } from '../avm_gas_cost.js';
|
|
3
|
+
import { type Field, type MemoryValue, TypeTag } from '../avm_memory_types.js';
|
|
3
4
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
5
|
+
import { Addressing, AddressingMode } from './addressing_mode.js';
|
|
4
6
|
import { Instruction } from './instruction.js';
|
|
5
7
|
import { ThreeOperandInstruction } from './instruction_impl.js';
|
|
6
8
|
|
|
7
|
-
export class
|
|
8
|
-
static readonly type: string = 'ADD';
|
|
9
|
-
static readonly opcode = Opcode.ADD;
|
|
10
|
-
|
|
11
|
-
constructor(indirect: number, inTag: number, aOffset: number, bOffset: number, dstOffset: number) {
|
|
12
|
-
super(indirect, inTag, aOffset, bOffset, dstOffset);
|
|
13
|
-
}
|
|
14
|
-
|
|
9
|
+
export abstract class ThreeOperandArithmeticInstruction extends ThreeOperandInstruction {
|
|
15
10
|
async execute(context: AvmContext): Promise<void> {
|
|
16
11
|
context.machineState.memory.checkTags(this.inTag, this.aOffset, this.bOffset);
|
|
17
12
|
|
|
18
13
|
const a = context.machineState.memory.get(this.aOffset);
|
|
19
14
|
const b = context.machineState.memory.get(this.bOffset);
|
|
20
15
|
|
|
21
|
-
const dest =
|
|
16
|
+
const dest = this.compute(a, b);
|
|
22
17
|
context.machineState.memory.set(this.dstOffset, dest);
|
|
23
18
|
|
|
24
19
|
context.machineState.incrementPc();
|
|
25
20
|
}
|
|
26
|
-
}
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
protected gasCost(): GasCost {
|
|
23
|
+
const indirectCount = Addressing.fromWire(this.indirect).modePerOperand.filter(
|
|
24
|
+
mode => mode === AddressingMode.INDIRECT,
|
|
25
|
+
).length;
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
const l2Gas =
|
|
28
|
+
indirectCount * GasCostConstants.ARITHMETIC_COST_PER_INDIRECT_ACCESS +
|
|
29
|
+
getGasCostMultiplierFromTypeTag(this.inTag) * GasCostConstants.ARITHMETIC_COST_PER_BYTE;
|
|
30
|
+
return makeGasCost({ l2Gas });
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const b = context.machineState.memory.get(this.bOffset);
|
|
33
|
+
protected abstract compute(a: MemoryValue, b: MemoryValue): MemoryValue;
|
|
34
|
+
}
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
export class Add extends ThreeOperandArithmeticInstruction {
|
|
37
|
+
static readonly type: string = 'ADD';
|
|
38
|
+
static readonly opcode = Opcode.ADD;
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
protected compute(a: MemoryValue, b: MemoryValue): MemoryValue {
|
|
41
|
+
return a.add(b);
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
export class
|
|
48
|
-
static type: string = '
|
|
49
|
-
static readonly opcode = Opcode.
|
|
45
|
+
export class Sub extends ThreeOperandArithmeticInstruction {
|
|
46
|
+
static readonly type: string = 'SUB';
|
|
47
|
+
static readonly opcode = Opcode.SUB;
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
protected compute(a: MemoryValue, b: MemoryValue): MemoryValue {
|
|
50
|
+
return a.sub(b);
|
|
53
51
|
}
|
|
52
|
+
}
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const dest = a.mul(b);
|
|
60
|
-
context.machineState.memory.set(this.dstOffset, dest);
|
|
54
|
+
export class Mul extends ThreeOperandArithmeticInstruction {
|
|
55
|
+
static type: string = 'MUL';
|
|
56
|
+
static readonly opcode = Opcode.MUL;
|
|
61
57
|
|
|
62
|
-
|
|
58
|
+
protected compute(a: MemoryValue, b: MemoryValue): MemoryValue {
|
|
59
|
+
return a.mul(b);
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
export class Div extends
|
|
63
|
+
export class Div extends ThreeOperandArithmeticInstruction {
|
|
67
64
|
static type: string = 'DIV';
|
|
68
65
|
static readonly opcode = Opcode.DIV;
|
|
69
66
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async execute(context: AvmContext): Promise<void> {
|
|
75
|
-
const a = context.machineState.memory.get(this.aOffset);
|
|
76
|
-
const b = context.machineState.memory.get(this.bOffset);
|
|
77
|
-
|
|
78
|
-
const dest = a.div(b);
|
|
79
|
-
context.machineState.memory.set(this.dstOffset, dest);
|
|
80
|
-
|
|
81
|
-
context.machineState.incrementPc();
|
|
67
|
+
protected compute(a: MemoryValue, b: MemoryValue): MemoryValue {
|
|
68
|
+
return a.div(b);
|
|
82
69
|
}
|
|
83
70
|
}
|
|
84
71
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AvmContext } from '../avm_context.js';
|
|
2
|
-
import { IntegralValue } from '../avm_memory_types.js';
|
|
2
|
+
import { type IntegralValue } from '../avm_memory_types.js';
|
|
3
3
|
import { Opcode } from '../serialization/instruction_serialization.js';
|
|
4
4
|
import { ThreeOperandInstruction, TwoOperandInstruction } from './instruction_impl.js';
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AvmContext } from '../avm_context.js';
|
|
2
|
-
import { IntegralValue } from '../avm_memory_types.js';
|
|
2
|
+
import { type IntegralValue } from '../avm_memory_types.js';
|
|
3
3
|
import { InstructionExecutionError } from '../errors.js';
|
|
4
4
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
5
5
|
import { Instruction } from './instruction.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
|
|
2
2
|
import { keccak, pedersenHash, poseidonHash, sha256 } from '@aztec/foundation/crypto';
|
|
3
3
|
|
|
4
|
-
import { AvmContext } from '../avm_context.js';
|
|
4
|
+
import { type AvmContext } from '../avm_context.js';
|
|
5
5
|
import { Field } from '../avm_memory_types.js';
|
|
6
6
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
7
7
|
import { Addressing } from './addressing_mode.js';
|
|
@@ -166,7 +166,7 @@ export class Pedersen extends Instruction {
|
|
|
166
166
|
|
|
167
167
|
// We hash a set of field elements
|
|
168
168
|
const messageSize = Number(context.machineState.memory.get(messageSizeOffset).toBigInt());
|
|
169
|
-
const hashData = context.machineState.memory.getSlice(messageOffset, messageSize)
|
|
169
|
+
const hashData = context.machineState.memory.getSlice(messageOffset, messageSize);
|
|
170
170
|
|
|
171
171
|
// No domain sep for now
|
|
172
172
|
const hash = pedersenHash(hashData);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { strict as assert } from 'assert';
|
|
2
2
|
|
|
3
3
|
import type { AvmContext } from '../avm_context.js';
|
|
4
|
-
import {
|
|
5
|
-
import { BufferCursor } from '../serialization/buffer_cursor.js';
|
|
6
|
-
import { Opcode, OperandType, deserialize, serialize } from '../serialization/instruction_serialization.js';
|
|
4
|
+
import { DynamicGasCost, type GasCost, GasCosts } from '../avm_gas_cost.js';
|
|
5
|
+
import { type BufferCursor } from '../serialization/buffer_cursor.js';
|
|
6
|
+
import { Opcode, type OperandType, deserialize, serialize } from '../serialization/instruction_serialization.js';
|
|
7
7
|
|
|
8
8
|
type InstructionConstructor = {
|
|
9
9
|
new (...args: any[]): Instruction;
|
|
@@ -29,8 +29,12 @@ export abstract class Instruction {
|
|
|
29
29
|
* Loads default gas cost for the instruction from the GasCosts table.
|
|
30
30
|
* Instruction sub-classes can override this if their gas cost is not fixed.
|
|
31
31
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
protected gasCost(): GasCost {
|
|
33
|
+
const gasCost = GasCosts[this.opcode];
|
|
34
|
+
if (gasCost === DynamicGasCost) {
|
|
35
|
+
throw new Error(`Instruction ${this.type} must define its own gas cost`);
|
|
36
|
+
}
|
|
37
|
+
return gasCost;
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AvmContext } from '../avm_context.js';
|
|
2
|
+
import { type GasCost, GasCostConstants, getGasCostMultiplierFromTypeTag, makeGasCost } from '../avm_gas_cost.js';
|
|
2
3
|
import { Field, TaggedMemory, TypeTag } from '../avm_memory_types.js';
|
|
3
4
|
import { InstructionExecutionError } from '../errors.js';
|
|
4
5
|
import { BufferCursor } from '../serialization/buffer_cursor.js';
|
|
@@ -79,6 +80,10 @@ export class Set extends Instruction {
|
|
|
79
80
|
|
|
80
81
|
context.machineState.incrementPc();
|
|
81
82
|
}
|
|
83
|
+
|
|
84
|
+
protected gasCost(): GasCost {
|
|
85
|
+
return makeGasCost({ l2Gas: GasCostConstants.SET_COST_PER_BYTE * getGasCostMultiplierFromTypeTag(this.inTag) });
|
|
86
|
+
}
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
export class CMov extends Instruction {
|
|
@@ -193,4 +198,8 @@ export class CalldataCopy extends Instruction {
|
|
|
193
198
|
|
|
194
199
|
context.machineState.incrementPc();
|
|
195
200
|
}
|
|
201
|
+
|
|
202
|
+
protected gasCost(): GasCost {
|
|
203
|
+
return makeGasCost({ l2Gas: GasCostConstants.CALLDATACOPY_COST_PER_BYTE * this.copySize });
|
|
204
|
+
}
|
|
196
205
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
// All code in this file needs to die once the public executor is phased out.
|
|
2
|
-
import {
|
|
2
|
+
import { UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
|
|
3
3
|
import {
|
|
4
4
|
ContractStorageRead,
|
|
5
5
|
ContractStorageUpdateRequest,
|
|
6
|
-
GlobalVariables,
|
|
6
|
+
type GlobalVariables,
|
|
7
7
|
L2ToL1Message,
|
|
8
|
-
ReadRequest,
|
|
8
|
+
type ReadRequest,
|
|
9
9
|
SideEffect,
|
|
10
|
-
SideEffectLinkedToNoteHash,
|
|
10
|
+
type SideEffectLinkedToNoteHash,
|
|
11
11
|
} from '@aztec/circuits.js';
|
|
12
12
|
import { Fr } from '@aztec/foundation/fields';
|
|
13
13
|
|
|
14
14
|
import { createSimulationError } from '../common/errors.js';
|
|
15
|
-
import { PublicExecution, PublicExecutionResult } from '../public/execution.js';
|
|
15
|
+
import { type PublicExecution, type PublicExecutionResult } from '../public/execution.js';
|
|
16
16
|
import { AvmExecutionEnvironment } from './avm_execution_environment.js';
|
|
17
|
-
import { AvmContractCallResults } from './avm_message_call_result.js';
|
|
18
|
-
import { JournalData } from './journal/journal.js';
|
|
17
|
+
import { type AvmContractCallResults } from './avm_message_call_result.js';
|
|
18
|
+
import { type JournalData } from './journal/journal.js';
|
|
19
19
|
|
|
20
20
|
/** Temporary Method
|
|
21
21
|
*
|
|
@@ -96,7 +96,7 @@ export function temporaryConvertAvmResults(
|
|
|
96
96
|
const nullifierReadRequests: ReadRequest[] = [];
|
|
97
97
|
const nullifierNonExistentReadRequests: ReadRequest[] = [];
|
|
98
98
|
const newNullifiers: SideEffectLinkedToNoteHash[] = [];
|
|
99
|
-
const unencryptedLogs =
|
|
99
|
+
const unencryptedLogs = UnencryptedFunctionL2Logs.empty();
|
|
100
100
|
const newL2ToL1Messages = newWorldState.newL1Messages.map(() => L2ToL1Message.empty());
|
|
101
101
|
// TODO keep track of side effect counters
|
|
102
102
|
const startSideEffectCounter = Fr.ZERO;
|
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AuthWitness,
|
|
3
|
-
AztecNode,
|
|
4
|
-
|
|
2
|
+
type AuthWitness,
|
|
3
|
+
type AztecNode,
|
|
4
|
+
EncryptedFunctionL2Logs,
|
|
5
|
+
EncryptedL2Log,
|
|
5
6
|
L1NotePayload,
|
|
6
7
|
Note,
|
|
7
|
-
NoteStatus,
|
|
8
|
+
type NoteStatus,
|
|
8
9
|
TaggedNote,
|
|
9
|
-
|
|
10
|
+
UnencryptedFunctionL2Logs,
|
|
11
|
+
type UnencryptedL2Log,
|
|
10
12
|
} from '@aztec/circuit-types';
|
|
11
13
|
import {
|
|
12
14
|
CallContext,
|
|
13
15
|
FunctionData,
|
|
14
16
|
FunctionSelector,
|
|
15
|
-
Header,
|
|
17
|
+
type Header,
|
|
16
18
|
NoteHashReadRequestMembershipWitness,
|
|
17
19
|
PublicCallRequest,
|
|
18
|
-
SideEffect,
|
|
20
|
+
type SideEffect,
|
|
19
21
|
TxContext,
|
|
20
22
|
} from '@aztec/circuits.js';
|
|
21
|
-
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
23
|
+
import { type Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
22
24
|
import { computePublicDataTreeLeafSlot, computeUniqueCommitment, siloNoteHash } from '@aztec/circuits.js/hash';
|
|
23
|
-
import { FunctionAbi, FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi';
|
|
24
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
25
|
-
import { Fr, Point } from '@aztec/foundation/fields';
|
|
25
|
+
import { type FunctionAbi, type FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi';
|
|
26
|
+
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
27
|
+
import { Fr, type Point } from '@aztec/foundation/fields';
|
|
26
28
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
27
29
|
|
|
28
|
-
import { NoteData, toACVMWitness } from '../acvm/index.js';
|
|
29
|
-
import { PackedArgsCache } from '../common/packed_args_cache.js';
|
|
30
|
-
import { DBOracle } from './db_oracle.js';
|
|
31
|
-
import { ExecutionNoteCache } from './execution_note_cache.js';
|
|
32
|
-
import { ExecutionResult, NoteAndSlot } from './execution_result.js';
|
|
30
|
+
import { type NoteData, toACVMWitness } from '../acvm/index.js';
|
|
31
|
+
import { type PackedArgsCache } from '../common/packed_args_cache.js';
|
|
32
|
+
import { type DBOracle } from './db_oracle.js';
|
|
33
|
+
import { type ExecutionNoteCache } from './execution_note_cache.js';
|
|
34
|
+
import { type ExecutionResult, type NoteAndSlot } from './execution_result.js';
|
|
33
35
|
import { pickNotes } from './pick_notes.js';
|
|
34
36
|
import { executePrivateFunction } from './private_execution.js';
|
|
35
37
|
import { ViewDataOracle } from './view_data_oracle.js';
|
|
@@ -56,7 +58,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
56
58
|
* They should act as references for the read requests output by an app circuit via public inputs.
|
|
57
59
|
*/
|
|
58
60
|
private gotNotes: Map<bigint, bigint> = new Map();
|
|
59
|
-
private encryptedLogs:
|
|
61
|
+
private encryptedLogs: EncryptedL2Log[] = [];
|
|
60
62
|
private unencryptedLogs: UnencryptedL2Log[] = [];
|
|
61
63
|
private nestedExecutions: ExecutionResult[] = [];
|
|
62
64
|
private enqueuedPublicFunctionCalls: PublicCallRequest[] = [];
|
|
@@ -144,14 +146,14 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
144
146
|
* Return the encrypted logs emitted during this execution.
|
|
145
147
|
*/
|
|
146
148
|
public getEncryptedLogs() {
|
|
147
|
-
return new
|
|
149
|
+
return new EncryptedFunctionL2Logs(this.encryptedLogs);
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
/**
|
|
151
153
|
* Return the encrypted logs emitted during this execution.
|
|
152
154
|
*/
|
|
153
155
|
public getUnencryptedLogs() {
|
|
154
|
-
return new
|
|
156
|
+
return new UnencryptedFunctionL2Logs(this.unencryptedLogs);
|
|
155
157
|
}
|
|
156
158
|
|
|
157
159
|
/**
|
|
@@ -304,7 +306,7 @@ export class ClientExecutionContext extends ViewDataOracle {
|
|
|
304
306
|
const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId);
|
|
305
307
|
const taggedNote = new TaggedNote(l1NotePayload);
|
|
306
308
|
const encryptedNote = taggedNote.toEncryptedBuffer(publicKey, this.curve);
|
|
307
|
-
this.encryptedLogs.push(encryptedNote);
|
|
309
|
+
this.encryptedLogs.push(new EncryptedL2Log(encryptedNote));
|
|
308
310
|
}
|
|
309
311
|
|
|
310
312
|
/**
|
package/src/client/db_oracle.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type L2Block,
|
|
3
|
+
type MerkleTreeId,
|
|
4
|
+
type NoteStatus,
|
|
5
|
+
type NullifierMembershipWitness,
|
|
6
|
+
type PublicDataWitness,
|
|
7
|
+
} from '@aztec/circuit-types';
|
|
8
|
+
import { type CompleteAddress, type Header } from '@aztec/circuits.js';
|
|
9
|
+
import { type FunctionArtifactWithDebugMetadata, type FunctionSelector } from '@aztec/foundation/abi';
|
|
10
|
+
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
11
|
+
import { type EthAddress } from '@aztec/foundation/eth-address';
|
|
12
|
+
import { type Fr } from '@aztec/foundation/fields';
|
|
13
|
+
import { type ContractInstance } from '@aztec/types/contracts';
|
|
14
|
+
|
|
15
|
+
import { type KeyPair, type NoteData } from '../acvm/index.js';
|
|
16
|
+
import { type CommitmentsDB } from '../public/db.js';
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
* Error thrown when a contract is not found in the database.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { siloNullifier } from '@aztec/circuits.js/hash';
|
|
2
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
2
|
+
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
|
|
5
|
-
import { NoteData } from '../acvm/index.js';
|
|
5
|
+
import { type NoteData } from '../acvm/index.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Data that's accessible by all the function calls in an execution.
|