@aztec/simulator 0.32.1 → 0.34.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/README.md +5 -3
- package/dest/acvm/acvm.js +2 -2
- package/dest/acvm/oracle/index.d.ts +0 -1
- package/dest/acvm/oracle/index.d.ts.map +1 -1
- package/dest/acvm/oracle/index.js +1 -2
- package/dest/acvm/oracle/oracle.d.ts +1 -1
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +4 -5
- package/dest/avm/avm_context.d.ts +4 -14
- package/dest/avm/avm_context.d.ts.map +1 -1
- package/dest/avm/avm_context.js +10 -22
- 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 +8 -7
- package/dest/avm/avm_gas.d.ts +71 -0
- package/dest/avm/avm_gas.d.ts.map +1 -0
- package/dest/avm/avm_gas.js +161 -0
- package/dest/avm/avm_machine_state.d.ts +4 -2
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +8 -2
- package/dest/avm/avm_memory_types.d.ts +53 -1
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +99 -6
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +15 -13
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +3 -3
- package/dest/avm/journal/journal.d.ts +14 -13
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +5 -5
- package/dest/avm/journal/trace.d.ts +8 -19
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +48 -116
- package/dest/avm/journal/trace_types.d.ts +23 -4
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +45 -17
- package/dest/avm/opcodes/addressing_mode.d.ts +5 -3
- package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/avm/opcodes/addressing_mode.js +5 -1
- package/dest/avm/opcodes/arithmetic.d.ts +7 -3
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +27 -16
- package/dest/avm/opcodes/bitwise.d.ts +21 -20
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +43 -65
- package/dest/avm/opcodes/comparators.d.ts +12 -9
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +22 -32
- package/dest/avm/opcodes/context_getters.d.ts +20 -0
- package/dest/avm/opcodes/context_getters.d.ts.map +1 -0
- package/dest/avm/opcodes/context_getters.js +26 -0
- package/dest/avm/opcodes/contract.d.ts +14 -0
- package/dest/avm/opcodes/contract.d.ts.map +1 -0
- package/dest/avm/opcodes/contract.js +49 -0
- package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/avm/opcodes/control_flow.js +12 -2
- package/dest/avm/opcodes/environment_getters.d.ts +30 -33
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +34 -43
- package/dest/avm/opcodes/external_calls.d.ts +13 -19
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +69 -72
- package/dest/avm/opcodes/hashing.d.ts +2 -1
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +37 -18
- package/dest/avm/opcodes/index.d.ts +1 -0
- package/dest/avm/opcodes/index.d.ts.map +1 -1
- package/dest/avm/opcodes/index.js +2 -1
- package/dest/avm/opcodes/instruction.d.ts +10 -15
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +12 -22
- package/dest/avm/opcodes/instruction_impl.d.ts +14 -0
- package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction_impl.js +37 -16
- package/dest/avm/opcodes/memory.d.ts +4 -3
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +38 -19
- package/dest/avm/opcodes/storage.d.ts +5 -0
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +21 -7
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +7 -5
- package/dest/avm/serialization/instruction_serialization.d.ts +12 -11
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +13 -12
- package/dest/client/client_execution_context.d.ts +2 -2
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +6 -6
- package/dest/client/private_execution.d.ts +1 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +8 -4
- package/dest/client/unconstrained_execution.d.ts +1 -1
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +2 -2
- package/dest/client/view_data_oracle.d.ts +2 -2
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +2 -2
- package/dest/public/executor.d.ts +2 -8
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +101 -69
- package/dest/public/index.d.ts +1 -1
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/public_execution_context.d.ts +6 -6
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +8 -12
- package/dest/public/transitional_adaptors.d.ts +32 -0
- package/dest/public/transitional_adaptors.d.ts.map +1 -0
- package/dest/public/transitional_adaptors.js +161 -0
- package/package.json +15 -9
- package/src/acvm/acvm.ts +1 -1
- package/src/acvm/oracle/index.ts +0 -1
- package/src/acvm/oracle/oracle.ts +3 -4
- package/src/avm/avm_context.ts +11 -33
- package/src/avm/avm_execution_environment.ts +9 -17
- package/src/avm/{avm_gas_cost.ts → avm_gas.ts} +75 -21
- package/src/avm/avm_machine_state.ts +9 -2
- package/src/avm/avm_memory_types.ts +134 -6
- package/src/avm/avm_simulator.ts +14 -12
- package/src/avm/fixtures/index.ts +2 -1
- package/src/avm/journal/journal.ts +24 -17
- package/src/avm/journal/trace.ts +59 -121
- package/src/avm/journal/trace_types.ts +39 -39
- package/src/avm/opcodes/accrued_substate.ts +58 -23
- package/src/avm/opcodes/addressing_mode.ts +8 -3
- package/src/avm/opcodes/arithmetic.ts +32 -22
- package/src/avm/opcodes/bitwise.ts +49 -83
- package/src/avm/opcodes/comparators.ts +28 -43
- package/src/avm/opcodes/context_getters.ts +32 -0
- package/src/avm/opcodes/contract.ts +58 -0
- package/src/avm/opcodes/control_flow.ts +23 -5
- package/src/avm/opcodes/environment_getters.ts +35 -44
- package/src/avm/opcodes/external_calls.ts +90 -89
- package/src/avm/opcodes/hashing.ts +45 -22
- package/src/avm/opcodes/index.ts +1 -0
- package/src/avm/opcodes/instruction.ts +14 -26
- package/src/avm/opcodes/instruction_impl.ts +45 -15
- package/src/avm/opcodes/memory.ts +48 -28
- package/src/avm/opcodes/storage.ts +26 -12
- package/src/avm/serialization/bytecode_serialization.ts +6 -3
- package/src/avm/serialization/instruction_serialization.ts +1 -0
- package/src/client/client_execution_context.ts +5 -5
- package/src/client/private_execution.ts +10 -4
- package/src/client/unconstrained_execution.ts +1 -1
- package/src/client/view_data_oracle.ts +1 -1
- package/src/public/executor.ts +123 -75
- package/src/public/index.ts +2 -2
- package/src/public/public_execution_context.ts +14 -19
- package/src/public/transitional_adaptors.ts +240 -0
- package/dest/acvm/oracle/debug.d.ts +0 -19
- package/dest/acvm/oracle/debug.d.ts.map +0 -1
- package/dest/acvm/oracle/debug.js +0 -95
- package/dest/avm/avm_gas_cost.d.ts +0 -322
- package/dest/avm/avm_gas_cost.d.ts.map +0 -1
- package/dest/avm/avm_gas_cost.js +0 -118
- package/dest/avm/temporary_executor_migration.d.ts +0 -25
- package/dest/avm/temporary_executor_migration.d.ts.map +0 -1
- package/dest/avm/temporary_executor_migration.js +0 -83
- package/src/acvm/oracle/debug.ts +0 -109
- package/src/avm/temporary_executor_migration.ts +0 -122
package/src/acvm/oracle/debug.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { type ForeignCallInput } from '@noir-lang/acvm_js';
|
|
2
|
-
|
|
3
|
-
import { type ACVMField } from '../acvm_types.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Convert an array of ACVMFields to a string.
|
|
7
|
-
*
|
|
8
|
-
* @param msg - array of ACVMFields where each represents a single ascii character
|
|
9
|
-
* @returns string representation of the message
|
|
10
|
-
*/
|
|
11
|
-
export function acvmFieldMessageToString(msg: ACVMField[]): string {
|
|
12
|
-
let msgStr = '';
|
|
13
|
-
for (const msgChar of msg) {
|
|
14
|
-
const asciiCode = Number(msgChar);
|
|
15
|
-
const asciiChar = String.fromCharCode(asciiCode);
|
|
16
|
-
msgStr = msgStr.concat(asciiChar);
|
|
17
|
-
}
|
|
18
|
-
// cut off string in case of preemptive null termination
|
|
19
|
-
const nullCharIndex = msgStr.indexOf('\\0');
|
|
20
|
-
if (nullCharIndex >= 0) {
|
|
21
|
-
msgStr = msgStr.substring(0, nullCharIndex);
|
|
22
|
-
}
|
|
23
|
-
return msgStr.replaceAll('\\n', '\n').replaceAll('\\t', '\t');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Format a debug string for Aztec.nr filling in `'{0}'` entries with their
|
|
28
|
-
* corresponding values from the args array.
|
|
29
|
-
*
|
|
30
|
-
* @param formatStr - str of form `'this is a string with some entries like {0} and {1}'`
|
|
31
|
-
* @param args - array of fields to fill in the string format entries with
|
|
32
|
-
* @returns formatted string
|
|
33
|
-
*/
|
|
34
|
-
function applyStringFormatting(formatStr: string, args: ACVMField[]): string {
|
|
35
|
-
const matches = formatStr.match(/{\d+}/g);
|
|
36
|
-
if (matches == null) {
|
|
37
|
-
return formatStr;
|
|
38
|
-
}
|
|
39
|
-
// Get the numeric values within the curly braces, convert them to numbers,
|
|
40
|
-
// and find the maximum value.
|
|
41
|
-
const maxIndex = Math.max(...matches.map(match => Number(match.slice(1, -1))));
|
|
42
|
-
const argsPadded = args.concat(Array.from({ length: Math.max(0, maxIndex - args.length) }, () => '0xBAD'));
|
|
43
|
-
|
|
44
|
-
return formatStr.replace(/{(\d+)}/g, function (match, index) {
|
|
45
|
-
return typeof args[index] != 'undefined' ? argsPadded[index] : match;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Convert an array of ACVMFields from ACVM to a formatted string.
|
|
51
|
-
*
|
|
52
|
-
* @param parameters - either one parameter representing a simple field or array, or two parameters when
|
|
53
|
-
* It's a message without args or three parameters when it's a message with arguments.
|
|
54
|
-
*
|
|
55
|
-
* @returns formatted string
|
|
56
|
-
*/
|
|
57
|
-
export function oracleDebugCallToFormattedStr(parameters: ForeignCallInput[]): string {
|
|
58
|
-
if (parameters.length === 1) {
|
|
59
|
-
return processFieldOrArray(parameters[0]);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let formatArgs: string[] = [];
|
|
63
|
-
|
|
64
|
-
if (parameters.length > 2) {
|
|
65
|
-
formatArgs = parameters[1];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const formattedMsg = applyStringFormatting(acvmFieldMessageToString(parameters[0]), formatArgs);
|
|
69
|
-
|
|
70
|
-
return formattedMsg;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Processes a field or an array and returns a string representation.
|
|
75
|
-
* @param fieldOrArray - The field or array to be processed.
|
|
76
|
-
* @returns Returns the processed string representation of the field or array.
|
|
77
|
-
*/
|
|
78
|
-
function processFieldOrArray(fieldOrArray: string[]) {
|
|
79
|
-
if (fieldOrArray.length === 1) {
|
|
80
|
-
return `${fieldOrArray[0]}`;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Check if all the elements start with 63 zero bytes
|
|
84
|
-
// --> if yes, we have an array of bytes and we print as hex
|
|
85
|
-
if (onlyBytes(fieldOrArray)) {
|
|
86
|
-
const decimalArray = fieldOrArray.map(element => parseInt(element, 16));
|
|
87
|
-
return '0x' + Buffer.from(decimalArray).toString('hex');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return '[' + fieldOrArray.join(', ') + ']';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Checks if all elements in the array are valid byte representations.
|
|
95
|
-
* @param array - The array to be checked.
|
|
96
|
-
* @returns Returns `true` if all elements are valid byte representations, `false` otherwise.
|
|
97
|
-
* @throws Throws an error if any element has an invalid length.
|
|
98
|
-
*/
|
|
99
|
-
function onlyBytes(array: string[]): boolean {
|
|
100
|
-
for (const element of array) {
|
|
101
|
-
if (element.length != 66) {
|
|
102
|
-
throw new Error('Invalid element length. Expected 66 chars, got ' + element.length + ' chars.');
|
|
103
|
-
}
|
|
104
|
-
if (!element.startsWith('0x00000000000000000000000000000000000000000000000000000000000000')) {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// All code in this file needs to die once the public executor is phased out.
|
|
2
|
-
import { UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
|
|
3
|
-
import {
|
|
4
|
-
ContractStorageRead,
|
|
5
|
-
ContractStorageUpdateRequest,
|
|
6
|
-
type GlobalVariables,
|
|
7
|
-
L2ToL1Message,
|
|
8
|
-
type ReadRequest,
|
|
9
|
-
SideEffect,
|
|
10
|
-
type SideEffectLinkedToNoteHash,
|
|
11
|
-
} from '@aztec/circuits.js';
|
|
12
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
13
|
-
|
|
14
|
-
import { createSimulationError } from '../common/errors.js';
|
|
15
|
-
import { type PublicExecution, type PublicExecutionResult } from '../public/execution.js';
|
|
16
|
-
import { AvmExecutionEnvironment } from './avm_execution_environment.js';
|
|
17
|
-
import { type AvmContractCallResults } from './avm_message_call_result.js';
|
|
18
|
-
import { type JournalData } from './journal/journal.js';
|
|
19
|
-
|
|
20
|
-
/** Temporary Method
|
|
21
|
-
*
|
|
22
|
-
* Convert a PublicExecution(Environment) object to an AvmExecutionEnvironment
|
|
23
|
-
*
|
|
24
|
-
* @param current
|
|
25
|
-
* @param globalVariables
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
export function temporaryCreateAvmExecutionEnvironment(
|
|
29
|
-
current: PublicExecution,
|
|
30
|
-
globalVariables: GlobalVariables,
|
|
31
|
-
): AvmExecutionEnvironment {
|
|
32
|
-
// Function selector is included temporarily until noir codegens public contract bytecode in a single blob
|
|
33
|
-
return new AvmExecutionEnvironment(
|
|
34
|
-
current.contractAddress,
|
|
35
|
-
current.callContext.storageContractAddress,
|
|
36
|
-
current.callContext.msgSender, // TODO: origin is not available
|
|
37
|
-
current.callContext.msgSender,
|
|
38
|
-
current.callContext.portalContractAddress,
|
|
39
|
-
/*feePerL1Gas=*/ Fr.zero(),
|
|
40
|
-
/*feePerL2Gas=*/ Fr.zero(),
|
|
41
|
-
/*feePerDaGas=*/ Fr.zero(),
|
|
42
|
-
/*contractCallDepth=*/ Fr.zero(),
|
|
43
|
-
globalVariables,
|
|
44
|
-
current.callContext.isStaticCall,
|
|
45
|
-
current.callContext.isDelegateCall,
|
|
46
|
-
current.args,
|
|
47
|
-
current.functionData.selector,
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Temporary Method
|
|
52
|
-
*
|
|
53
|
-
* Convert the result of an AVM contract call to a PublicExecutionResult for the public kernel
|
|
54
|
-
*
|
|
55
|
-
* @param execution
|
|
56
|
-
* @param newWorldState
|
|
57
|
-
* @param result
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
export function temporaryConvertAvmResults(
|
|
61
|
-
execution: PublicExecution,
|
|
62
|
-
newWorldState: JournalData,
|
|
63
|
-
result: AvmContractCallResults,
|
|
64
|
-
): PublicExecutionResult {
|
|
65
|
-
const newNoteHashes = newWorldState.newNoteHashes.map(noteHash => new SideEffect(noteHash, Fr.zero()));
|
|
66
|
-
|
|
67
|
-
const contractStorageReads: ContractStorageRead[] = [];
|
|
68
|
-
const reduceStorageReadRequests = (contractAddress: bigint, storageReads: Map<bigint, Fr[]>) => {
|
|
69
|
-
return storageReads.forEach((innerArray, key) => {
|
|
70
|
-
innerArray.forEach(value => {
|
|
71
|
-
contractStorageReads.push(new ContractStorageRead(new Fr(key), new Fr(value), 0));
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
newWorldState.storageReads.forEach((storageMap: Map<bigint, Fr[]>, address: bigint) =>
|
|
76
|
-
reduceStorageReadRequests(address, storageMap),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
|
|
80
|
-
const reduceStorageUpdateRequests = (contractAddress: bigint, storageUpdateRequests: Map<bigint, Fr[]>) => {
|
|
81
|
-
return storageUpdateRequests.forEach((innerArray, key) => {
|
|
82
|
-
innerArray.forEach(value => {
|
|
83
|
-
contractStorageUpdateRequests.push(new ContractStorageUpdateRequest(new Fr(key), new Fr(value), 0));
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
newWorldState.storageWrites.forEach((storageMap: Map<bigint, Fr[]>, address: bigint) =>
|
|
88
|
-
reduceStorageUpdateRequests(address, storageMap),
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const returnValues = result.output;
|
|
92
|
-
|
|
93
|
-
// TODO(follow up in pr tree): NOT SUPPORTED YET, make sure hashing and log resolution is done correctly
|
|
94
|
-
// Disabled.
|
|
95
|
-
const nestedExecutions: PublicExecutionResult[] = [];
|
|
96
|
-
const nullifierReadRequests: ReadRequest[] = [];
|
|
97
|
-
const nullifierNonExistentReadRequests: ReadRequest[] = [];
|
|
98
|
-
const newNullifiers: SideEffectLinkedToNoteHash[] = [];
|
|
99
|
-
const unencryptedLogs = UnencryptedFunctionL2Logs.empty();
|
|
100
|
-
const newL2ToL1Messages = newWorldState.newL1Messages.map(() => L2ToL1Message.empty());
|
|
101
|
-
// TODO keep track of side effect counters
|
|
102
|
-
const startSideEffectCounter = Fr.ZERO;
|
|
103
|
-
const endSideEffectCounter = Fr.ZERO;
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
execution,
|
|
107
|
-
nullifierReadRequests,
|
|
108
|
-
nullifierNonExistentReadRequests,
|
|
109
|
-
newNoteHashes,
|
|
110
|
-
newL2ToL1Messages,
|
|
111
|
-
startSideEffectCounter,
|
|
112
|
-
endSideEffectCounter,
|
|
113
|
-
newNullifiers,
|
|
114
|
-
contractStorageReads,
|
|
115
|
-
contractStorageUpdateRequests,
|
|
116
|
-
returnValues,
|
|
117
|
-
nestedExecutions,
|
|
118
|
-
unencryptedLogs,
|
|
119
|
-
reverted: result.reverted,
|
|
120
|
-
revertReason: result.revertReason ? createSimulationError(result.revertReason) : undefined,
|
|
121
|
-
};
|
|
122
|
-
}
|