Skip to content

Commit

Permalink
core/vm: Correct the Memory Gas Overflow condition
Browse files Browse the repository at this point in the history
previous overflow condition is too big to use.
0x7FFFFFFFF squre operation is overflowed uint64.

0x7FFFFFFFF^2 = 0x3F FFFF FFF0 0000 0001
  • Loading branch information
Liang Ma committed Mar 28, 2019
1 parent 5b0d3fa commit 157f09e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/vm/gas_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func memoryGasCost(mem *Memory, newMemSize uint64) (uint64, error) {
// The maximum that will fit in a uint64 is max_word_count - 1
// anything above that will result in an overflow.
// Additionally, a newMemSize which results in a
// newMemSizeWords larger than 0x7ffffffff will cause the square operation
// newMemSizeWords larger than 0xFFFFFFFF will cause the square operation
// to overflow.
// The constant 0xffffffffe0 is the highest number that can be used without
// The constant 0x1FFFFFFFE0 is the highest number that can be used without
// overflowing the gas calculation
if newMemSize > 0xffffffffe0 {
if newMemSize > 0x1FFFFFFFE0 {
return 0, errGasUintOverflow
}

Expand Down

0 comments on commit 157f09e

Please sign in to comment.