Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/vm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"github.com/holiman/uint256"
)

// MaxMemorySize is the largest size that won't overflow memory gas calculation.
const MaxMemorySize = 0x1FFFFFFFE0

// calcMemSize64 calculates the required memory size, and returns
// the size and whether the result overflowed uint64
func calcMemSize64(off, l *uint256.Int) (uint64, bool) {
Expand Down Expand Up @@ -76,6 +79,11 @@ func getDataAndAdjustedBounds(data []byte, start uint64, size uint64) (codeCopyP
return common.RightPadBytes(data[start:end], int(size)), start, end - start
}

// ToWordSize returns the ceiled word size required for memory expansion.
func ToWordSize(size uint64) uint64 {
return toWordSize(size)
}

// toWordSize returns the ceiled word size required for memory expansion.
func toWordSize(size uint64) uint64 {
Comment on lines +82 to 88
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not making the old function public? fork-diff-wise I'd say it wouldn't be that harmful

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk I just felt like avoiding modifying go-ethereum code might make merging the upstream work easier

if size > math.MaxUint64-31 {
Expand Down
4 changes: 2 additions & 2 deletions core/vm/gas_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func memoryGasCost(mem *Memory, newMemSize uint64) (multigas.MultiGas, 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 0xFFFFFFFF will cause the square operation to
// overflow. The constant 0x1FFFFFFFE0 is the highest number that can be used
// overflow. The constant MaxMemorySize is the highest number that can be used
// without overflowing the gas calculation.
if newMemSize > 0x1FFFFFFFE0 {
if newMemSize > MaxMemorySize {
return multigas.ZeroGas(), ErrGasUintOverflow
}
newMemSizeWords := toWordSize(newMemSize)
Expand Down
Loading