@@ -108,7 +108,7 @@ impl Counter {
108
108
109
109
// find closest ancestor block (starting from top of stack and going down) with blocked flow and add 1
110
110
111
- for ( i , stack_i) in self . stack . iter ( ) . rev ( ) . enumerate ( ) {
111
+ for ( _i , stack_i) in self . stack . iter ( ) . rev ( ) . enumerate ( ) {
112
112
let block_i = self . blocks . get_mut ( * stack_i) . ok_or_else ( || ( ) ) ?;
113
113
if !block_i. flow_up || * stack_i == 0 {
114
114
block_i. cost = block_i. cost . checked_add ( val) . ok_or_else ( || ( ) ) ?;
@@ -120,15 +120,6 @@ impl Counter {
120
120
121
121
}
122
122
123
- /// Increment the cost of the current block by the specified value.
124
- fn increment ( & mut self , val : u32 ) -> Result < ( ) , ( ) > {
125
- let stack_top = self . stack . last_mut ( ) . ok_or_else ( || ( ) ) ?;
126
- let top_block = self . blocks . get_mut ( * stack_top) . ok_or_else ( || ( ) ) ?;
127
-
128
- top_block. cost = top_block. cost . checked_add ( val) . ok_or_else ( || ( ) ) ?;
129
-
130
- Ok ( ( ) )
131
- }
132
123
}
133
124
134
125
fn inject_grow_counter ( instructions : & mut elements:: Instructions , grow_counter_func : u32 ) -> usize {
@@ -154,10 +145,8 @@ fn add_grow_counter(module: elements::Module, rules: &rules::Set, gas_func: u32)
154
145
. with_instructions ( elements:: Instructions :: new ( vec ! [
155
146
GetLocal ( 0 ) ,
156
147
GetLocal ( 0 ) ,
157
- // I64Const(rules.grow_cost() as i64),
158
- // I64Mul,
159
- I32Const ( rules. grow_cost( ) as i32 ) ,
160
- I32Mul ,
148
+ I64Const ( rules. grow_cost( ) as i64 ) ,
149
+ I64Mul ,
161
150
// todo: there should be strong guarantee that it does not return anything on stack?
162
151
Call ( gas_func) ,
163
152
GrowMemory ( 0 ) ,
@@ -285,8 +274,7 @@ pub fn inject_counter(
285
274
if block. cost > 0 {
286
275
let effective_pos = block. start_pos + cumulative_offset;
287
276
288
- //instructions.elements_mut().insert(effective_pos, I64Const(block.cost as i64));
289
- instructions. elements_mut ( ) . insert ( effective_pos, I32Const ( block. cost as i32 ) ) ;
277
+ instructions. elements_mut ( ) . insert ( effective_pos, I64Const ( block. cost as i64 ) ) ;
290
278
instructions. elements_mut ( ) . insert ( effective_pos+1 , Call ( gas_func) ) ;
291
279
292
280
// Take into account these two inserted instructions.
@@ -308,7 +296,7 @@ pub fn inject_gas_counter(module: elements::Module, rules: &rules::Set)
308
296
let mut mbuilder = builder:: from_module ( module) ;
309
297
let import_sig = mbuilder. push_signature (
310
298
builder:: signature ( )
311
- . param ( ) . i32 ( )
299
+ . param ( ) . i64 ( )
312
300
. build_sig ( )
313
301
) ;
314
302
0 commit comments