File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change 17
17
package vm
18
18
19
19
import (
20
- gmath "math"
21
20
"math/big"
22
21
23
22
"github.com/ethereum/go-ethereum/common"
@@ -28,15 +27,20 @@ import (
28
27
// memoryGasCosts calculates the quadratic gas for memory expansion. It does so
29
28
// only for the memory region that is expanded, not the total memory.
30
29
func memoryGasCost (mem * Memory , newMemSize uint64 ) (uint64 , error ) {
31
- // The maximum that will fit in a uint64 is max_word_count - 1
32
- // anything above that will result in an overflow.
33
- if newMemSize > gmath .MaxUint64 - 32 {
34
- return 0 , errGasUintOverflow
35
- }
36
30
37
31
if newMemSize == 0 {
38
32
return 0 , nil
39
33
}
34
+ // The maximum that will fit in a uint64 is max_word_count - 1
35
+ // anything above that will result in an overflow.
36
+ // Additionally, a newMemSize which results in a
37
+ // newMemSizeWords larger than 0x7ffffffff will cause the square operation
38
+ // to overflow.
39
+ // The constant 0xffffffffe0 is the highest number that can be used without
40
+ // overflowing the gas calculation
41
+ if newMemSize > 0xffffffffe0 {
42
+ return 0 , errGasUintOverflow
43
+ }
40
44
41
45
newMemSizeWords := toWordSize (newMemSize )
42
46
newMemSize = newMemSizeWords * 32
You can’t perform that action at this time.
0 commit comments