Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
bae75652
Commit
bae75652
authored
Jun 28, 2017
by
Martin Holst Swende
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/vm: fix overflow in gas calculation formula
parent
9e5f03b6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
gas_table.go
core/vm/gas_table.go
+10
-6
No files found.
core/vm/gas_table.go
View file @
bae75652
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
package
vm
package
vm
import
(
import
(
gmath
"math"
"math/big"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -28,15 +27,20 @@ import (
...
@@ -28,15 +27,20 @@ import (
// memoryGasCosts calculates the quadratic gas for memory expansion. It does so
// memoryGasCosts 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
)
{
// The maximum that will fit in a uint64 is max_word_count - 1
// anything above that will result in an overflow.
if
newMemSize
>
gmath
.
MaxUint64
-
32
{
return
0
,
errGasUintOverflow
}
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
// anything above that will result in an overflow.
// Additionally, a newMemSize which results in a
// newMemSizeWords larger than 0x7ffffffff will cause the square operation
// to overflow.
// The constant 0xffffffffe0 is the highest number that can be used without
// overflowing the gas calculation
if
newMemSize
>
0xffffffffe0
{
return
0
,
errGasUintOverflow
}
newMemSizeWords
:=
toWordSize
(
newMemSize
)
newMemSizeWords
:=
toWordSize
(
newMemSize
)
newMemSize
=
newMemSizeWords
*
32
newMemSize
=
newMemSizeWords
*
32
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment