@@ -28,8 +28,6 @@ pub const Gas = struct {
2828 /// amount, matching the reference (vm charge_state_gas / credit_state_gas_refund), so a
2929 /// spilled-then-refunded charge restores regular gas for subsequent 63/64 forwarding.
3030 state_gas_spilled : u64 = 0 ,
31- /// Memoisation of values for memory expansion cost.
32- memory : MemoryGas ,
3331
3432 /// Creates a new `Gas` struct with the given gas limit.
3533 pub fn new (limit : u64 ) Gas {
@@ -41,7 +39,6 @@ pub const Gas = struct {
4139 .reservoir = 0 ,
4240 .state_gas_spent = 0 ,
4341 .state_gas_refunded = 0 ,
44- .memory = MemoryGas .new (),
4542 };
4643 }
4744
@@ -55,7 +52,6 @@ pub const Gas = struct {
5552 .reservoir = 0 ,
5653 .state_gas_spent = 0 ,
5754 .state_gas_refunded = 0 ,
58- .memory = MemoryGas .new (),
5955 };
6056 }
6157
@@ -64,16 +60,6 @@ pub const Gas = struct {
6460 return self .limit ;
6561 }
6662
67- /// Returns the memory gas.
68- pub fn getMemory (self : Gas ) MemoryGas {
69- return self .memory ;
70- }
71-
72- /// Returns the memory gas mutably.
73- pub fn getMemoryMut (self : * Gas ) * MemoryGas {
74- return & self .memory ;
75- }
76-
7763 /// Returns the total amount of gas that was refunded.
7864 pub fn getRefunded (self : Gas ) i64 {
7965 return self .refunded ;
@@ -192,32 +178,6 @@ pub const Gas = struct {
192178 self .refunded = refund_amount ;
193179 }
194180
195- /// Load gas with memory
196- pub fn loadGasWithMemory (self : * Gas , amount : u64 , memory : MemoryGas ) void {
197- self .remaining = amount ;
198- self .memory = memory ;
199- }
200-
201- /// Load gas with memory and refund
202- pub fn loadGasWithMemoryAndRefund (self : * Gas , amount : u64 , memory : MemoryGas , refund_amount : i64 ) void {
203- self .remaining = amount ;
204- self .memory = memory ;
205- self .refunded = refund_amount ;
206- }
207-
208- /// Load gas with limit and memory
209- pub fn loadGasWithLimitAndMemory (self : * Gas , amount : u64 , limit : u64 , memory : MemoryGas ) void {
210- self .remaining = @min (amount , limit );
211- self .memory = memory ;
212- }
213-
214- /// Load gas with limit, memory and refund
215- pub fn loadGasWithLimitMemoryAndRefund (self : * Gas , amount : u64 , limit : u64 , memory : MemoryGas , refund_amount : i64 ) void {
216- self .remaining = @min (amount , limit );
217- self .memory = memory ;
218- self .refunded = refund_amount ;
219- }
220-
221181 /// Apply EIP-3529 refund cap in-place.
222182 /// Pre-London: cap at gas_spent / 2. London+: cap at gas_spent / 5.
223183 pub fn setFinalRefund (self : * Gas , is_london : bool ) void {
@@ -234,63 +194,3 @@ pub const Gas = struct {
234194 return if (spent > ref ) spent - ref else 0 ;
235195 }
236196};
237-
238- /// Memory gas tracking for memory expansion costs
239- pub const MemoryGas = struct {
240- /// The current memory size in words
241- size : u64 ,
242- /// The maximum memory size reached during execution
243- max_size : u64 ,
244-
245- pub fn new () MemoryGas {
246- return MemoryGas {
247- .size = 0 ,
248- .max_size = 0 ,
249- };
250- }
251-
252- /// Get the current memory size in words
253- pub fn getSize (self : MemoryGas ) u64 {
254- return self .size ;
255- }
256-
257- /// Get the maximum memory size reached
258- pub fn maxSize (self : MemoryGas ) u64 {
259- return self .max_size ;
260- }
261-
262- /// Set the memory size
263- pub fn setSize (self : * MemoryGas , size : u64 ) void {
264- self .size = size ;
265- self .max_size = @max (self .max_size , size );
266- }
267-
268- /// Calculate memory expansion cost
269- pub fn expansionCost (self : MemoryGas , new_size : u64 ) u64 {
270- if (new_size <= self .size ) {
271- return 0 ;
272- }
273-
274- // std.math.divCeil(u64, n, 32) avoids (n + 31) overflow for large n.
275- const new_words = std .math .divCeil (u64 , new_size , 32 ) catch return std .math .maxInt (u64 );
276- const current_words = std .math .divCeil (u64 , self .size , 32 ) catch return std .math .maxInt (u64 );
277-
278- if (new_words <= current_words ) {
279- return 0 ;
280- }
281-
282- const sq_new = std .math .mul (u64 , new_words , new_words ) catch return std .math .maxInt (u64 );
283- const cost = std .math .add (u64 , sq_new / 512 , 3 * new_words ) catch return std .math .maxInt (u64 );
284- const sq_cur = std .math .mul (u64 , current_words , current_words ) catch return std .math .maxInt (u64 );
285- const current_cost = std .math .add (u64 , sq_cur / 512 , 3 * current_words ) catch return std .math .maxInt (u64 );
286-
287- return cost - current_cost ;
288- }
289-
290- /// Record memory expansion
291- pub fn recordExpansion (self : * MemoryGas , new_size : u64 ) u64 {
292- const cost = self .expansionCost (new_size );
293- self .setSize (new_size );
294- return cost ;
295- }
296- };
0 commit comments