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
9294b8f1
Unverified
Commit
9294b8f1
authored
Apr 01, 2019
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/vm: polish gas PR, fix tests, make table driven
parent
157f09e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
21 deletions
+20
-21
gas_table.go
core/vm/gas_table.go
+5
-9
gas_table_test.go
core/vm/gas_table_test.go
+15
-12
No files found.
core/vm/gas_table.go
View file @
9294b8f1
...
...
@@ -25,21 +25,17 @@ import (
// memoryGasCost calculates the quadratic gas for memory expansion. It does so
// only for the memory region that is expanded, not the total memory.
func
memoryGasCost
(
mem
*
Memory
,
newMemSize
uint64
)
(
uint64
,
error
)
{
if
newMemSize
==
0
{
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 0xFFFFFFFF will cause the square operation
// to overflow.
// The constant 0x1FFFFFFFE0 is the highest number that can be used without
// overflowing the gas calculation
// 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
// without overflowing the gas calculation.
if
newMemSize
>
0x1FFFFFFFE0
{
return
0
,
errGasUintOverflow
}
newMemSizeWords
:=
toWordSize
(
newMemSize
)
newMemSize
=
newMemSizeWords
*
32
...
...
core/vm/gas_table_test.go
View file @
9294b8f1
...
...
@@ -19,18 +19,21 @@ package vm
import
"testing"
func
TestMemoryGasCost
(
t
*
testing
.
T
)
{
//size := uint64(math.MaxUint64 - 64)
size
:=
uint64
(
0xffffffffe0
)
v
,
err
:=
memoryGasCost
(
&
Memory
{},
size
)
if
err
!=
nil
{
t
.
Error
(
"didn't expect error:"
,
err
)
tests
:=
[]
struct
{
size
uint64
cost
uint64
overflow
bool
}{
{
0x1fffffffe0
,
36028809887088637
,
false
},
{
0x1fffffffe1
,
0
,
true
},
}
if
v
!=
36028899963961341
{
t
.
Errorf
(
"Expected: 36028899963961341, got %d"
,
v
)
}
_
,
err
=
memoryGasCost
(
&
Memory
{},
size
+
1
)
if
err
==
nil
{
t
.
Error
(
"expected error"
)
for
i
,
tt
:=
range
tests
{
v
,
err
:=
memoryGasCost
(
&
Memory
{},
tt
.
size
)
if
(
err
==
errGasUintOverflow
)
!=
tt
.
overflow
{
t
.
Errorf
(
"test %d: overflow mismatch: have %v, want %v"
,
i
,
err
==
errGasUintOverflow
,
tt
.
overflow
)
}
if
v
!=
tt
.
cost
{
t
.
Errorf
(
"test %d: gas cost mismatch: have %v, want %v"
,
i
,
v
,
tt
.
cost
)
}
}
}
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