|
|
@ -25,21 +25,17 @@ import ( |
|
|
|
// memoryGasCost calculates the quadratic gas for memory expansion. It does so
|
|
|
|
// memoryGasCost calculates the quadratic gas for memory expansion. It does so
|
|
|
|
// only for the memory region that is expanded, not the total memory.
|
|
|
|
// only for the memory region that is expanded, not the total memory.
|
|
|
|
func memoryGasCost(mem *Memory, newMemSize uint64) (uint64, error) { |
|
|
|
func memoryGasCost(mem *Memory, newMemSize uint64) (uint64, error) { |
|
|
|
|
|
|
|
|
|
|
|
if newMemSize == 0 { |
|
|
|
if newMemSize == 0 { |
|
|
|
return 0, nil |
|
|
|
return 0, nil |
|
|
|
} |
|
|
|
} |
|
|
|
// The maximum that will fit in a uint64 is max_word_count - 1
|
|
|
|
// The maximum that will fit in a uint64 is max_word_count - 1. Anything above
|
|
|
|
// anything above that will result in an overflow.
|
|
|
|
// that will result in an overflow. Additionally, a newMemSize which results in
|
|
|
|
// Additionally, a newMemSize which results in a
|
|
|
|
// a newMemSizeWords larger than 0xFFFFFFFF will cause the square operation to
|
|
|
|
// newMemSizeWords larger than 0xFFFFFFFF will cause the square operation
|
|
|
|
// overflow. The constant 0x1FFFFFFFE0 is the highest number that can be used
|
|
|
|
// to overflow.
|
|
|
|
// without overflowing the gas calculation.
|
|
|
|
// The constant 0x1FFFFFFFE0 is the highest number that can be used without
|
|
|
|
|
|
|
|
// overflowing the gas calculation
|
|
|
|
|
|
|
|
if newMemSize > 0x1FFFFFFFE0 { |
|
|
|
if newMemSize > 0x1FFFFFFFE0 { |
|
|
|
return 0, errGasUintOverflow |
|
|
|
return 0, errGasUintOverflow |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
newMemSizeWords := toWordSize(newMemSize) |
|
|
|
newMemSizeWords := toWordSize(newMemSize) |
|
|
|
newMemSize = newMemSizeWords * 32 |
|
|
|
newMemSize = newMemSizeWords * 32 |
|
|
|
|
|
|
|
|
|
|
|