@aztec/simulator 0.48.0 → 0.50.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 +2 -2
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +12 -7
- package/dest/avm/avm_gas.d.ts +1 -0
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +142 -79
- package/dest/avm/opcodes/accrued_substate.js +2 -2
- package/dest/avm/opcodes/conversion.js +2 -2
- package/dest/avm/opcodes/external_calls.js +4 -4
- package/dest/avm/opcodes/instruction.d.ts +2 -1
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +8 -5
- package/dest/avm/opcodes/memory.js +2 -2
- package/dest/avm/opcodes/storage.js +3 -3
- package/dest/providers/acvm_native.js +2 -2
- package/dest/public/public_processor.d.ts +3 -2
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +6 -5
- package/dest/public/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor_metrics.js +4 -2
- package/dest/rollup/rollup.d.ts +25 -1
- package/dest/rollup/rollup.d.ts.map +1 -1
- package/dest/rollup/rollup.js +24 -2
- package/package.json +9 -9
- package/src/acvm/acvm.ts +14 -5
- package/src/avm/avm_gas.ts +145 -79
- package/src/avm/opcodes/accrued_substate.ts +1 -1
- package/src/avm/opcodes/conversion.ts +1 -1
- package/src/avm/opcodes/external_calls.ts +3 -3
- package/src/avm/opcodes/instruction.ts +7 -4
- package/src/avm/opcodes/memory.ts +1 -1
- package/src/avm/opcodes/storage.ts +2 -2
- package/src/providers/acvm_native.ts +1 -1
- package/src/public/public_processor.ts +6 -5
- package/src/public/public_processor_metrics.ts +3 -1
- package/src/rollup/rollup.ts +56 -0
package/src/avm/avm_gas.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as c from '@aztec/circuits.js/constants';
|
|
2
|
+
|
|
1
3
|
import { TypeTag } from './avm_memory_types.js';
|
|
2
4
|
import { InstructionExecutionError } from './errors.js';
|
|
3
5
|
import { Addressing, AddressingMode } from './opcodes/addressing_mode.js';
|
|
@@ -46,90 +48,150 @@ export const EmptyGas: Gas = {
|
|
|
46
48
|
daGas: 0,
|
|
47
49
|
};
|
|
48
50
|
|
|
51
|
+
function makeCost(l2Gas: number, daGas: number): Gas {
|
|
52
|
+
return { l2Gas, daGas };
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
/** Dimensions of gas usage: L1, L2, and DA. */
|
|
50
56
|
export const GasDimensions = ['l2Gas', 'daGas'] as const;
|
|
51
57
|
|
|
52
|
-
/** Default gas cost for an opcode. */
|
|
53
|
-
const DefaultBaseGasCost: Gas = { l2Gas: 10, daGas: 0 };
|
|
54
|
-
|
|
55
58
|
/** Base gas costs for each instruction. Additional gas cost may be added on top due to memory or storage accesses, etc. */
|
|
56
59
|
const BaseGasCosts: Record<Opcode, Gas> = {
|
|
57
|
-
[Opcode.ADD]:
|
|
58
|
-
[Opcode.SUB]:
|
|
59
|
-
[Opcode.MUL]:
|
|
60
|
-
[Opcode.DIV]:
|
|
61
|
-
[Opcode.FDIV]:
|
|
62
|
-
[Opcode.EQ]:
|
|
63
|
-
[Opcode.LT]:
|
|
64
|
-
[Opcode.LTE]:
|
|
65
|
-
[Opcode.AND]:
|
|
66
|
-
[Opcode.OR]:
|
|
67
|
-
[Opcode.XOR]:
|
|
68
|
-
[Opcode.NOT]:
|
|
69
|
-
[Opcode.SHL]:
|
|
70
|
-
[Opcode.SHR]:
|
|
71
|
-
[Opcode.CAST]:
|
|
72
|
-
|
|
73
|
-
[Opcode.
|
|
74
|
-
[Opcode.
|
|
75
|
-
[Opcode.
|
|
76
|
-
[Opcode.
|
|
77
|
-
[Opcode.
|
|
78
|
-
[Opcode.
|
|
79
|
-
[Opcode.
|
|
80
|
-
[Opcode.
|
|
81
|
-
[Opcode.
|
|
82
|
-
[Opcode.
|
|
83
|
-
[Opcode.
|
|
84
|
-
[Opcode.
|
|
85
|
-
[Opcode.
|
|
86
|
-
[Opcode.
|
|
87
|
-
[Opcode.
|
|
88
|
-
|
|
89
|
-
[Opcode.
|
|
90
|
-
[Opcode.
|
|
91
|
-
|
|
92
|
-
[Opcode.
|
|
93
|
-
[Opcode.
|
|
94
|
-
[Opcode.
|
|
95
|
-
[Opcode.
|
|
96
|
-
|
|
97
|
-
[Opcode.
|
|
98
|
-
[Opcode.
|
|
99
|
-
[Opcode.
|
|
100
|
-
|
|
101
|
-
[Opcode.
|
|
102
|
-
[Opcode.
|
|
103
|
-
[Opcode.
|
|
104
|
-
[Opcode.
|
|
105
|
-
[Opcode.
|
|
106
|
-
[Opcode.
|
|
107
|
-
[Opcode.
|
|
108
|
-
[Opcode.
|
|
109
|
-
[Opcode.
|
|
110
|
-
[Opcode.
|
|
111
|
-
[Opcode.
|
|
112
|
-
|
|
113
|
-
[Opcode.
|
|
114
|
-
[Opcode.
|
|
115
|
-
[Opcode.
|
|
116
|
-
[Opcode.
|
|
117
|
-
[Opcode.
|
|
118
|
-
|
|
119
|
-
[Opcode.
|
|
120
|
-
|
|
121
|
-
[Opcode.
|
|
122
|
-
[Opcode.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
[Opcode.
|
|
127
|
-
[Opcode.
|
|
128
|
-
|
|
129
|
-
[Opcode.
|
|
130
|
-
|
|
131
|
-
[Opcode.
|
|
132
|
-
[Opcode.
|
|
60
|
+
[Opcode.ADD]: makeCost(c.AVM_ADD_BASE_L2_GAS, 0),
|
|
61
|
+
[Opcode.SUB]: makeCost(c.AVM_SUB_BASE_L2_GAS, 0),
|
|
62
|
+
[Opcode.MUL]: makeCost(c.AVM_MUL_BASE_L2_GAS, 0),
|
|
63
|
+
[Opcode.DIV]: makeCost(c.AVM_DIV_BASE_L2_GAS, 0),
|
|
64
|
+
[Opcode.FDIV]: makeCost(c.AVM_FDIV_BASE_L2_GAS, 0),
|
|
65
|
+
[Opcode.EQ]: makeCost(c.AVM_EQ_BASE_L2_GAS, 0),
|
|
66
|
+
[Opcode.LT]: makeCost(c.AVM_LT_BASE_L2_GAS, 0),
|
|
67
|
+
[Opcode.LTE]: makeCost(c.AVM_LTE_BASE_L2_GAS, 0),
|
|
68
|
+
[Opcode.AND]: makeCost(c.AVM_AND_BASE_L2_GAS, 0),
|
|
69
|
+
[Opcode.OR]: makeCost(c.AVM_OR_BASE_L2_GAS, 0),
|
|
70
|
+
[Opcode.XOR]: makeCost(c.AVM_XOR_BASE_L2_GAS, 0),
|
|
71
|
+
[Opcode.NOT]: makeCost(c.AVM_NOT_BASE_L2_GAS, 0),
|
|
72
|
+
[Opcode.SHL]: makeCost(c.AVM_SHL_BASE_L2_GAS, 0),
|
|
73
|
+
[Opcode.SHR]: makeCost(c.AVM_SHR_BASE_L2_GAS, 0),
|
|
74
|
+
[Opcode.CAST]: makeCost(c.AVM_CAST_BASE_L2_GAS, 0),
|
|
75
|
+
[Opcode.ADDRESS]: makeCost(c.AVM_ADDRESS_BASE_L2_GAS, 0),
|
|
76
|
+
[Opcode.STORAGEADDRESS]: makeCost(c.AVM_STORAGEADDRESS_BASE_L2_GAS, 0),
|
|
77
|
+
[Opcode.SENDER]: makeCost(c.AVM_SENDER_BASE_L2_GAS, 0),
|
|
78
|
+
[Opcode.FEEPERL2GAS]: makeCost(c.AVM_FEEPERL2GAS_BASE_L2_GAS, 0),
|
|
79
|
+
[Opcode.FEEPERDAGAS]: makeCost(c.AVM_FEEPERDAGAS_BASE_L2_GAS, 0),
|
|
80
|
+
[Opcode.TRANSACTIONFEE]: makeCost(c.AVM_TRANSACTIONFEE_BASE_L2_GAS, 0),
|
|
81
|
+
[Opcode.FUNCTIONSELECTOR]: makeCost(c.AVM_FUNCTIONSELECTOR_BASE_L2_GAS, 0),
|
|
82
|
+
[Opcode.CHAINID]: makeCost(c.AVM_CHAINID_BASE_L2_GAS, 0),
|
|
83
|
+
[Opcode.VERSION]: makeCost(c.AVM_VERSION_BASE_L2_GAS, 0),
|
|
84
|
+
[Opcode.BLOCKNUMBER]: makeCost(c.AVM_BLOCKNUMBER_BASE_L2_GAS, 0),
|
|
85
|
+
[Opcode.TIMESTAMP]: makeCost(c.AVM_TIMESTAMP_BASE_L2_GAS, 0),
|
|
86
|
+
[Opcode.COINBASE]: makeCost(c.AVM_COINBASE_BASE_L2_GAS, 0),
|
|
87
|
+
[Opcode.BLOCKL2GASLIMIT]: makeCost(c.AVM_BLOCKL2GASLIMIT_BASE_L2_GAS, 0),
|
|
88
|
+
[Opcode.BLOCKDAGASLIMIT]: makeCost(c.AVM_BLOCKDAGASLIMIT_BASE_L2_GAS, 0),
|
|
89
|
+
[Opcode.CALLDATACOPY]: makeCost(c.AVM_CALLDATACOPY_BASE_L2_GAS, 0),
|
|
90
|
+
[Opcode.L2GASLEFT]: makeCost(c.AVM_L2GASLEFT_BASE_L2_GAS, 0),
|
|
91
|
+
[Opcode.DAGASLEFT]: makeCost(c.AVM_DAGASLEFT_BASE_L2_GAS, 0),
|
|
92
|
+
[Opcode.JUMP]: makeCost(c.AVM_JUMP_BASE_L2_GAS, 0),
|
|
93
|
+
[Opcode.JUMPI]: makeCost(c.AVM_JUMPI_BASE_L2_GAS, 0),
|
|
94
|
+
[Opcode.INTERNALCALL]: makeCost(c.AVM_INTERNALCALL_BASE_L2_GAS, 0),
|
|
95
|
+
[Opcode.INTERNALRETURN]: makeCost(c.AVM_INTERNALRETURN_BASE_L2_GAS, 0),
|
|
96
|
+
[Opcode.SET]: makeCost(c.AVM_SET_BASE_L2_GAS, 0),
|
|
97
|
+
[Opcode.MOV]: makeCost(c.AVM_MOV_BASE_L2_GAS, 0),
|
|
98
|
+
[Opcode.CMOV]: makeCost(c.AVM_CMOV_BASE_L2_GAS, 0),
|
|
99
|
+
[Opcode.SLOAD]: makeCost(c.AVM_SLOAD_BASE_L2_GAS, 0),
|
|
100
|
+
[Opcode.SSTORE]: makeCost(c.AVM_SSTORE_BASE_L2_GAS, 0),
|
|
101
|
+
[Opcode.NOTEHASHEXISTS]: makeCost(c.AVM_NOTEHASHEXISTS_BASE_L2_GAS, 0),
|
|
102
|
+
[Opcode.EMITNOTEHASH]: makeCost(c.AVM_EMITNOTEHASH_BASE_L2_GAS, 0),
|
|
103
|
+
[Opcode.NULLIFIEREXISTS]: makeCost(c.AVM_NULLIFIEREXISTS_BASE_L2_GAS, 0),
|
|
104
|
+
[Opcode.EMITNULLIFIER]: makeCost(c.AVM_EMITNULLIFIER_BASE_L2_GAS, 0),
|
|
105
|
+
[Opcode.L1TOL2MSGEXISTS]: makeCost(c.AVM_L1TOL2MSGEXISTS_BASE_L2_GAS, 0),
|
|
106
|
+
[Opcode.HEADERMEMBER]: makeCost(c.AVM_HEADERMEMBER_BASE_L2_GAS, 0),
|
|
107
|
+
[Opcode.EMITUNENCRYPTEDLOG]: makeCost(c.AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS, 0),
|
|
108
|
+
[Opcode.SENDL2TOL1MSG]: makeCost(c.AVM_SENDL2TOL1MSG_BASE_L2_GAS, 0),
|
|
109
|
+
[Opcode.GETCONTRACTINSTANCE]: makeCost(c.AVM_GETCONTRACTINSTANCE_BASE_L2_GAS, 0),
|
|
110
|
+
[Opcode.CALL]: makeCost(c.AVM_CALL_BASE_L2_GAS, 0),
|
|
111
|
+
[Opcode.STATICCALL]: makeCost(c.AVM_STATICCALL_BASE_L2_GAS, 0),
|
|
112
|
+
[Opcode.DELEGATECALL]: makeCost(c.AVM_DELEGATECALL_BASE_L2_GAS, 0),
|
|
113
|
+
[Opcode.RETURN]: makeCost(c.AVM_RETURN_BASE_L2_GAS, 0),
|
|
114
|
+
[Opcode.REVERT]: makeCost(c.AVM_REVERT_BASE_L2_GAS, 0),
|
|
115
|
+
[Opcode.DEBUGLOG]: makeCost(c.AVM_DEBUGLOG_BASE_L2_GAS, 0),
|
|
116
|
+
[Opcode.KECCAK]: makeCost(c.AVM_KECCAK_BASE_L2_GAS, 0),
|
|
117
|
+
[Opcode.POSEIDON2]: makeCost(c.AVM_POSEIDON2_BASE_L2_GAS, 0),
|
|
118
|
+
[Opcode.SHA256]: makeCost(c.AVM_SHA256_BASE_L2_GAS, 0),
|
|
119
|
+
[Opcode.PEDERSEN]: makeCost(c.AVM_PEDERSEN_BASE_L2_GAS, 0),
|
|
120
|
+
[Opcode.ECADD]: makeCost(c.AVM_ECADD_BASE_L2_GAS, 0),
|
|
121
|
+
[Opcode.MSM]: makeCost(c.AVM_MSM_BASE_L2_GAS, 0),
|
|
122
|
+
[Opcode.PEDERSENCOMMITMENT]: makeCost(c.AVM_PEDERSENCOMMITMENT_BASE_L2_GAS, 0),
|
|
123
|
+
[Opcode.TORADIXLE]: makeCost(c.AVM_TORADIXLE_BASE_L2_GAS, 0),
|
|
124
|
+
[Opcode.SHA256COMPRESSION]: makeCost(c.AVM_SHA256COMPRESSION_BASE_L2_GAS, 0),
|
|
125
|
+
[Opcode.KECCAKF1600]: makeCost(c.AVM_KECCAKF1600_BASE_L2_GAS, 0),
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const DynamicGasCosts: Record<Opcode, Gas> = {
|
|
129
|
+
[Opcode.ADD]: makeCost(c.AVM_ADD_DYN_L2_GAS, 0),
|
|
130
|
+
[Opcode.SUB]: makeCost(c.AVM_SUB_DYN_L2_GAS, 0),
|
|
131
|
+
[Opcode.MUL]: makeCost(c.AVM_MUL_DYN_L2_GAS, 0),
|
|
132
|
+
[Opcode.DIV]: makeCost(c.AVM_DIV_DYN_L2_GAS, 0),
|
|
133
|
+
[Opcode.FDIV]: makeCost(c.AVM_FDIV_DYN_L2_GAS, 0),
|
|
134
|
+
[Opcode.EQ]: makeCost(c.AVM_EQ_DYN_L2_GAS, 0),
|
|
135
|
+
[Opcode.LT]: makeCost(c.AVM_LT_DYN_L2_GAS, 0),
|
|
136
|
+
[Opcode.LTE]: makeCost(c.AVM_LTE_DYN_L2_GAS, 0),
|
|
137
|
+
[Opcode.AND]: makeCost(c.AVM_AND_DYN_L2_GAS, 0),
|
|
138
|
+
[Opcode.OR]: makeCost(c.AVM_OR_DYN_L2_GAS, 0),
|
|
139
|
+
[Opcode.XOR]: makeCost(c.AVM_XOR_DYN_L2_GAS, 0),
|
|
140
|
+
[Opcode.NOT]: makeCost(c.AVM_NOT_DYN_L2_GAS, 0),
|
|
141
|
+
[Opcode.SHL]: makeCost(c.AVM_SHL_DYN_L2_GAS, 0),
|
|
142
|
+
[Opcode.SHR]: makeCost(c.AVM_SHR_DYN_L2_GAS, 0),
|
|
143
|
+
[Opcode.CAST]: makeCost(c.AVM_CAST_DYN_L2_GAS, 0),
|
|
144
|
+
[Opcode.ADDRESS]: makeCost(c.AVM_ADDRESS_DYN_L2_GAS, 0),
|
|
145
|
+
[Opcode.STORAGEADDRESS]: makeCost(c.AVM_STORAGEADDRESS_DYN_L2_GAS, 0),
|
|
146
|
+
[Opcode.SENDER]: makeCost(c.AVM_SENDER_DYN_L2_GAS, 0),
|
|
147
|
+
[Opcode.FEEPERL2GAS]: makeCost(c.AVM_FEEPERL2GAS_DYN_L2_GAS, 0),
|
|
148
|
+
[Opcode.FEEPERDAGAS]: makeCost(c.AVM_FEEPERDAGAS_DYN_L2_GAS, 0),
|
|
149
|
+
[Opcode.TRANSACTIONFEE]: makeCost(c.AVM_TRANSACTIONFEE_DYN_L2_GAS, 0),
|
|
150
|
+
[Opcode.FUNCTIONSELECTOR]: makeCost(c.AVM_FUNCTIONSELECTOR_DYN_L2_GAS, 0),
|
|
151
|
+
[Opcode.CHAINID]: makeCost(c.AVM_CHAINID_DYN_L2_GAS, 0),
|
|
152
|
+
[Opcode.VERSION]: makeCost(c.AVM_VERSION_DYN_L2_GAS, 0),
|
|
153
|
+
[Opcode.BLOCKNUMBER]: makeCost(c.AVM_BLOCKNUMBER_DYN_L2_GAS, 0),
|
|
154
|
+
[Opcode.TIMESTAMP]: makeCost(c.AVM_TIMESTAMP_DYN_L2_GAS, 0),
|
|
155
|
+
[Opcode.COINBASE]: makeCost(c.AVM_COINBASE_DYN_L2_GAS, 0),
|
|
156
|
+
[Opcode.BLOCKL2GASLIMIT]: makeCost(c.AVM_BLOCKL2GASLIMIT_DYN_L2_GAS, 0),
|
|
157
|
+
[Opcode.BLOCKDAGASLIMIT]: makeCost(c.AVM_BLOCKDAGASLIMIT_DYN_L2_GAS, 0),
|
|
158
|
+
[Opcode.CALLDATACOPY]: makeCost(c.AVM_CALLDATACOPY_DYN_L2_GAS, 0),
|
|
159
|
+
[Opcode.L2GASLEFT]: makeCost(c.AVM_L2GASLEFT_DYN_L2_GAS, 0),
|
|
160
|
+
[Opcode.DAGASLEFT]: makeCost(c.AVM_DAGASLEFT_DYN_L2_GAS, 0),
|
|
161
|
+
[Opcode.JUMP]: makeCost(c.AVM_JUMP_DYN_L2_GAS, 0),
|
|
162
|
+
[Opcode.JUMPI]: makeCost(c.AVM_JUMPI_DYN_L2_GAS, 0),
|
|
163
|
+
[Opcode.INTERNALCALL]: makeCost(c.AVM_INTERNALCALL_DYN_L2_GAS, 0),
|
|
164
|
+
[Opcode.INTERNALRETURN]: makeCost(c.AVM_INTERNALRETURN_DYN_L2_GAS, 0),
|
|
165
|
+
[Opcode.SET]: makeCost(c.AVM_SET_DYN_L2_GAS, 0),
|
|
166
|
+
[Opcode.MOV]: makeCost(c.AVM_MOV_DYN_L2_GAS, 0),
|
|
167
|
+
[Opcode.CMOV]: makeCost(c.AVM_CMOV_DYN_L2_GAS, 0),
|
|
168
|
+
[Opcode.SLOAD]: makeCost(c.AVM_SLOAD_DYN_L2_GAS, 0),
|
|
169
|
+
[Opcode.SSTORE]: makeCost(c.AVM_SSTORE_DYN_L2_GAS, 0),
|
|
170
|
+
[Opcode.NOTEHASHEXISTS]: makeCost(c.AVM_NOTEHASHEXISTS_DYN_L2_GAS, 0),
|
|
171
|
+
[Opcode.EMITNOTEHASH]: makeCost(c.AVM_EMITNOTEHASH_DYN_L2_GAS, 0),
|
|
172
|
+
[Opcode.NULLIFIEREXISTS]: makeCost(c.AVM_NULLIFIEREXISTS_DYN_L2_GAS, 0),
|
|
173
|
+
[Opcode.EMITNULLIFIER]: makeCost(c.AVM_EMITNULLIFIER_DYN_L2_GAS, 0),
|
|
174
|
+
[Opcode.L1TOL2MSGEXISTS]: makeCost(c.AVM_L1TOL2MSGEXISTS_DYN_L2_GAS, 0),
|
|
175
|
+
[Opcode.HEADERMEMBER]: makeCost(c.AVM_HEADERMEMBER_DYN_L2_GAS, 0),
|
|
176
|
+
[Opcode.EMITUNENCRYPTEDLOG]: makeCost(c.AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS, 0),
|
|
177
|
+
[Opcode.SENDL2TOL1MSG]: makeCost(c.AVM_SENDL2TOL1MSG_DYN_L2_GAS, 0),
|
|
178
|
+
[Opcode.GETCONTRACTINSTANCE]: makeCost(c.AVM_GETCONTRACTINSTANCE_DYN_L2_GAS, 0),
|
|
179
|
+
[Opcode.CALL]: makeCost(c.AVM_CALL_DYN_L2_GAS, 0),
|
|
180
|
+
[Opcode.STATICCALL]: makeCost(c.AVM_STATICCALL_DYN_L2_GAS, 0),
|
|
181
|
+
[Opcode.DELEGATECALL]: makeCost(c.AVM_DELEGATECALL_DYN_L2_GAS, 0),
|
|
182
|
+
[Opcode.RETURN]: makeCost(c.AVM_RETURN_DYN_L2_GAS, 0),
|
|
183
|
+
[Opcode.REVERT]: makeCost(c.AVM_REVERT_DYN_L2_GAS, 0),
|
|
184
|
+
[Opcode.DEBUGLOG]: makeCost(c.AVM_DEBUGLOG_DYN_L2_GAS, 0),
|
|
185
|
+
[Opcode.KECCAK]: makeCost(c.AVM_KECCAK_DYN_L2_GAS, 0),
|
|
186
|
+
[Opcode.POSEIDON2]: makeCost(c.AVM_POSEIDON2_DYN_L2_GAS, 0),
|
|
187
|
+
[Opcode.SHA256]: makeCost(c.AVM_SHA256_DYN_L2_GAS, 0),
|
|
188
|
+
[Opcode.PEDERSEN]: makeCost(c.AVM_PEDERSEN_DYN_L2_GAS, 0),
|
|
189
|
+
[Opcode.ECADD]: makeCost(c.AVM_ECADD_DYN_L2_GAS, 0),
|
|
190
|
+
[Opcode.MSM]: makeCost(c.AVM_MSM_DYN_L2_GAS, 0),
|
|
191
|
+
[Opcode.PEDERSENCOMMITMENT]: makeCost(c.AVM_PEDERSENCOMMITMENT_DYN_L2_GAS, 0),
|
|
192
|
+
[Opcode.TORADIXLE]: makeCost(c.AVM_TORADIXLE_DYN_L2_GAS, 0),
|
|
193
|
+
[Opcode.SHA256COMPRESSION]: makeCost(c.AVM_SHA256COMPRESSION_DYN_L2_GAS, 0),
|
|
194
|
+
[Opcode.KECCAKF1600]: makeCost(c.AVM_KECCAKF1600_DYN_L2_GAS, 0),
|
|
133
195
|
};
|
|
134
196
|
|
|
135
197
|
/** Returns the fixed base gas cost for a given opcode. */
|
|
@@ -137,6 +199,10 @@ export function getBaseGasCost(opcode: Opcode): Gas {
|
|
|
137
199
|
return BaseGasCosts[opcode];
|
|
138
200
|
}
|
|
139
201
|
|
|
202
|
+
export function getDynamicGasCost(opcode: Opcode): Gas {
|
|
203
|
+
return DynamicGasCosts[opcode];
|
|
204
|
+
}
|
|
205
|
+
|
|
140
206
|
/** Returns the gas cost associated with the memory operations performed. */
|
|
141
207
|
export function getMemoryGasCost(args: { reads?: number; writes?: number; indirect?: number }) {
|
|
142
208
|
const { reads, writes, indirect } = args;
|
|
@@ -241,7 +241,7 @@ export class EmitUnencryptedLog extends Instruction {
|
|
|
241
241
|
const contractAddress = context.environment.address;
|
|
242
242
|
|
|
243
243
|
const memoryOperations = { reads: 1 + logSize, indirect: this.indirect };
|
|
244
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
244
|
+
context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: logSize }));
|
|
245
245
|
const log = memory.getSlice(logOffset, logSize).map(f => f.toFr());
|
|
246
246
|
context.persistableState.writeUnencryptedLog(contractAddress, log);
|
|
247
247
|
|
|
@@ -35,7 +35,7 @@ export class ToRadixLE extends Instruction {
|
|
|
35
35
|
const memory = context.machineState.memory.track(this.type);
|
|
36
36
|
const [srcOffset, dstOffset] = Addressing.fromWire(this.indirect).resolve([this.srcOffset, this.dstOffset], memory);
|
|
37
37
|
const memoryOperations = { reads: 1, writes: this.numLimbs, indirect: this.indirect };
|
|
38
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
38
|
+
context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.numLimbs }));
|
|
39
39
|
|
|
40
40
|
// The radix gadget only takes in a Field
|
|
41
41
|
memory.checkTag(TypeTag.FIELD, srcOffset);
|
|
@@ -67,7 +67,7 @@ abstract class ExternalCall extends Instruction {
|
|
|
67
67
|
|
|
68
68
|
// First we consume the gas for this operation.
|
|
69
69
|
const memoryOperations = { reads: calldataSize + 5, writes: 1 + this.retSize, indirect: this.indirect };
|
|
70
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
70
|
+
context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: calldataSize + this.retSize }));
|
|
71
71
|
// Then we consume the gas allocated for the nested call. The excess will be refunded later.
|
|
72
72
|
// Gas allocation is capped by the amount of gas left in the current context.
|
|
73
73
|
// We have to do some dancing here because the gas allocation is a field,
|
|
@@ -170,7 +170,7 @@ export class Return extends Instruction {
|
|
|
170
170
|
public async execute(context: AvmContext): Promise<void> {
|
|
171
171
|
const memoryOperations = { reads: this.copySize, indirect: this.indirect };
|
|
172
172
|
const memory = context.machineState.memory.track(this.type);
|
|
173
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
173
|
+
context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.copySize }));
|
|
174
174
|
|
|
175
175
|
const [returnOffset] = Addressing.fromWire(this.indirect).resolve([this.returnOffset], memory);
|
|
176
176
|
|
|
@@ -199,7 +199,7 @@ export class Revert extends Instruction {
|
|
|
199
199
|
public async execute(context: AvmContext): Promise<void> {
|
|
200
200
|
const memoryOperations = { reads: this.retSize, indirect: this.indirect };
|
|
201
201
|
const memory = context.machineState.memory.track(this.type);
|
|
202
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
202
|
+
context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.retSize }));
|
|
203
203
|
|
|
204
204
|
const [returnOffset] = Addressing.fromWire(this.indirect).resolve([this.returnOffset], memory);
|
|
205
205
|
|
|
@@ -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, sumGas } from '../avm_gas.js';
|
|
4
|
+
import { getBaseGasCost, getDynamicGasCost, mulGas, 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,12 +67,15 @@ 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(ops: Partial<MemoryOperations & { indirect: number; dynMultiplier: number }> = {}) {
|
|
71
71
|
const baseGasCost = getBaseGasCost(this.opcode);
|
|
72
|
+
// TODO: We are using a simplified gas model to reduce complexity in the circuit.
|
|
73
|
+
// Memory accounting will probably be removed.
|
|
72
74
|
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/6861): reconsider.
|
|
73
75
|
// const memoryGasCost = getMemoryGasCost(memoryOps);
|
|
74
|
-
const memoryGasCost = { l2Gas: 0, daGas: 0 };
|
|
75
|
-
|
|
76
|
+
// const memoryGasCost = { l2Gas: 0, daGas: 0 };
|
|
77
|
+
const dynGasCost = mulGas(getDynamicGasCost(this.opcode), ops.dynMultiplier ?? 0);
|
|
78
|
+
return sumGas(baseGasCost, dynGasCost);
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
/**
|
|
@@ -208,7 +208,7 @@ export class CalldataCopy extends Instruction {
|
|
|
208
208
|
public async execute(context: AvmContext): Promise<void> {
|
|
209
209
|
const memoryOperations = { writes: this.copySize, indirect: this.indirect };
|
|
210
210
|
const memory = context.machineState.memory.track(this.type);
|
|
211
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
211
|
+
context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.copySize }));
|
|
212
212
|
|
|
213
213
|
// We don't need to check tags here because: (1) the calldata is NOT in memory, and (2) we are the ones writing to destination.
|
|
214
214
|
const [cdOffset, dstOffset] = Addressing.fromWire(this.indirect).resolve([this.cdOffset, this.dstOffset], memory);
|
|
@@ -42,7 +42,7 @@ export class SStore extends BaseStorageInstruction {
|
|
|
42
42
|
|
|
43
43
|
const memoryOperations = { reads: this.size + 1, indirect: this.indirect };
|
|
44
44
|
const memory = context.machineState.memory.track(this.type);
|
|
45
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
45
|
+
context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.size }));
|
|
46
46
|
|
|
47
47
|
const [srcOffset, slotOffset] = Addressing.fromWire(this.indirect).resolve([this.aOffset, this.bOffset], memory);
|
|
48
48
|
memory.checkTag(TypeTag.FIELD, slotOffset);
|
|
@@ -72,7 +72,7 @@ export class SLoad extends BaseStorageInstruction {
|
|
|
72
72
|
public async execute(context: AvmContext): Promise<void> {
|
|
73
73
|
const memoryOperations = { writes: this.size, reads: 1, indirect: this.indirect };
|
|
74
74
|
const memory = context.machineState.memory.track(this.type);
|
|
75
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
75
|
+
context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.size }));
|
|
76
76
|
|
|
77
77
|
const [slotOffset, dstOffset] = Addressing.fromWire(this.indirect).resolve([this.aOffset, this.bOffset], memory);
|
|
78
78
|
memory.checkTag(TypeTag.FIELD, slotOffset);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type BlockProver,
|
|
3
2
|
type FailedTx,
|
|
4
3
|
NestedProcessReturnValues,
|
|
5
4
|
type ProcessedTx,
|
|
5
|
+
type ProcessedTxHandler,
|
|
6
6
|
PublicKernelType,
|
|
7
7
|
type PublicProvingRequest,
|
|
8
8
|
type SimulationError,
|
|
@@ -116,12 +116,13 @@ export class PublicProcessor {
|
|
|
116
116
|
/**
|
|
117
117
|
* Run each tx through the public circuit and the public kernel circuit if needed.
|
|
118
118
|
* @param txs - Txs to process.
|
|
119
|
+
* @param processedTxHandler - Handler for processed txs in the context of block building or proving.
|
|
119
120
|
* @returns The list of processed txs with their circuit simulation outputs.
|
|
120
121
|
*/
|
|
121
122
|
public async process(
|
|
122
123
|
txs: Tx[],
|
|
123
124
|
maxTransactions = txs.length,
|
|
124
|
-
|
|
125
|
+
processedTxHandler?: ProcessedTxHandler,
|
|
125
126
|
txValidator?: TxValidator<ProcessedTx>,
|
|
126
127
|
): Promise<[ProcessedTx[], FailedTx[], NestedProcessReturnValues[]]> {
|
|
127
128
|
// The processor modifies the tx objects in place, so we need to clone them.
|
|
@@ -164,9 +165,9 @@ export class PublicProcessor {
|
|
|
164
165
|
throw new Error(`Transaction ${invalid[0].hash} invalid after processing public functions`);
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
|
-
// if we were given a
|
|
168
|
-
if (
|
|
169
|
-
await
|
|
168
|
+
// if we were given a handler then send the transaction to it for block building or proving
|
|
169
|
+
if (processedTxHandler) {
|
|
170
|
+
await processedTxHandler.addNewTx(processedTx);
|
|
170
171
|
}
|
|
171
172
|
result.push(processedTx);
|
|
172
173
|
returns = returns.concat(returnValues ?? []);
|
package/src/rollup/rollup.ts
CHANGED
|
@@ -3,6 +3,9 @@ import {
|
|
|
3
3
|
type BaseOrMergeRollupPublicInputs,
|
|
4
4
|
type BaseParityInputs,
|
|
5
5
|
type BaseRollupInputs,
|
|
6
|
+
type BlockMergeRollupInputs,
|
|
7
|
+
type BlockRootOrBlockMergePublicInputs,
|
|
8
|
+
type BlockRootRollupInputs,
|
|
6
9
|
type MergeRollupInputs,
|
|
7
10
|
type ParityPublicInputs,
|
|
8
11
|
type RootParityInputs,
|
|
@@ -15,6 +18,10 @@ import {
|
|
|
15
18
|
SimulatedServerCircuitArtifacts,
|
|
16
19
|
convertBaseParityInputsToWitnessMap,
|
|
17
20
|
convertBaseParityOutputsFromWitnessMap,
|
|
21
|
+
convertBlockMergeRollupInputsToWitnessMap,
|
|
22
|
+
convertBlockMergeRollupOutputsFromWitnessMap,
|
|
23
|
+
convertBlockRootRollupInputsToWitnessMap,
|
|
24
|
+
convertBlockRootRollupOutputsFromWitnessMap,
|
|
18
25
|
convertMergeRollupInputsToWitnessMap,
|
|
19
26
|
convertMergeRollupOutputsFromWitnessMap,
|
|
20
27
|
convertRootParityInputsToWitnessMap,
|
|
@@ -56,6 +63,18 @@ export interface RollupSimulator {
|
|
|
56
63
|
* @returns The public inputs as outputs of the simulation.
|
|
57
64
|
*/
|
|
58
65
|
mergeRollupCircuit(input: MergeRollupInputs): Promise<BaseOrMergeRollupPublicInputs>;
|
|
66
|
+
/**
|
|
67
|
+
* Simulates the block root rollup circuit from its inputs.
|
|
68
|
+
* @param input - Inputs to the circuit.
|
|
69
|
+
* @returns The public inputs as outputs of the simulation.
|
|
70
|
+
*/
|
|
71
|
+
blockRootRollupCircuit(input: BlockRootRollupInputs): Promise<BlockRootOrBlockMergePublicInputs>;
|
|
72
|
+
/**
|
|
73
|
+
* Simulates the block merge rollup circuit from its inputs.
|
|
74
|
+
* @param input - Inputs to the circuit.
|
|
75
|
+
* @returns The public inputs as outputs of the simulation.
|
|
76
|
+
*/
|
|
77
|
+
blockMergeRollupCircuit(input: BlockMergeRollupInputs): Promise<BlockRootOrBlockMergePublicInputs>;
|
|
59
78
|
/**
|
|
60
79
|
* Simulates the root rollup circuit from its inputs.
|
|
61
80
|
* @param input - Inputs to the circuit.
|
|
@@ -128,6 +147,7 @@ export class RealRollupCircuitSimulator implements RollupSimulator {
|
|
|
128
147
|
|
|
129
148
|
return Promise.resolve(result);
|
|
130
149
|
}
|
|
150
|
+
|
|
131
151
|
/**
|
|
132
152
|
* Simulates the merge rollup circuit from its inputs.
|
|
133
153
|
* @param input - Inputs to the circuit.
|
|
@@ -146,6 +166,42 @@ export class RealRollupCircuitSimulator implements RollupSimulator {
|
|
|
146
166
|
return result;
|
|
147
167
|
}
|
|
148
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Simulates the block root rollup circuit from its inputs.
|
|
171
|
+
* @param input - Inputs to the circuit.
|
|
172
|
+
* @returns The public inputs as outputs of the simulation.
|
|
173
|
+
*/
|
|
174
|
+
public async blockRootRollupCircuit(input: BlockRootRollupInputs): Promise<BlockRootOrBlockMergePublicInputs> {
|
|
175
|
+
const witnessMap = convertBlockRootRollupInputsToWitnessMap(input);
|
|
176
|
+
|
|
177
|
+
const witness = await this.wasmSimulator.simulateCircuit(
|
|
178
|
+
witnessMap,
|
|
179
|
+
SimulatedServerCircuitArtifacts.BlockRootRollupArtifact,
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const result = convertBlockRootRollupOutputsFromWitnessMap(witness);
|
|
183
|
+
|
|
184
|
+
return Promise.resolve(result);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Simulates the block merge rollup circuit from its inputs.
|
|
189
|
+
* @param input - Inputs to the circuit.
|
|
190
|
+
* @returns The public inputs as outputs of the simulation.
|
|
191
|
+
*/
|
|
192
|
+
public async blockMergeRollupCircuit(input: BlockMergeRollupInputs): Promise<BlockRootOrBlockMergePublicInputs> {
|
|
193
|
+
const witnessMap = convertBlockMergeRollupInputsToWitnessMap(input);
|
|
194
|
+
|
|
195
|
+
const witness = await this.wasmSimulator.simulateCircuit(
|
|
196
|
+
witnessMap,
|
|
197
|
+
SimulatedServerCircuitArtifacts.BlockMergeRollupArtifact,
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const result = convertBlockMergeRollupOutputsFromWitnessMap(witness);
|
|
201
|
+
|
|
202
|
+
return Promise.resolve(result);
|
|
203
|
+
}
|
|
204
|
+
|
|
149
205
|
/**
|
|
150
206
|
* Simulates the root rollup circuit from its inputs.
|
|
151
207
|
* @param input - Inputs to the circuit.
|