good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
92faf1bf
Unverified
Commit
92faf1bf
authored
Apr 1, 2019
by
Péter Szilágyi
Committed by
GitHub
Apr 1, 2019
Browse files
Options
Downloads
Plain Diff
Merge pull request #19348 from LiangMa/overflowPR
core/vm: Correct the Memory Gas Overflow condition
parents
cd79bc61
9294b8f1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/vm/gas_table.go
+6
-10
6 additions, 10 deletions
core/vm/gas_table.go
core/vm/gas_table_test.go
+15
-12
15 additions, 12 deletions
core/vm/gas_table_test.go
with
21 additions
and
22 deletions
core/vm/gas_table.go
+
6
−
10
View file @
92faf1bf
...
@@ -25,21 +25,17 @@ import (
...
@@ -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 0x7ffffffff 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 0xffffffffe0 is the highest number that can be used without
if
newMemSize
>
0x1FFFFFFFE0
{
// overflowing the gas calculation
if
newMemSize
>
0xffffffffe0
{
return
0
,
errGasUintOverflow
return
0
,
errGasUintOverflow
}
}
newMemSizeWords
:=
toWordSize
(
newMemSize
)
newMemSizeWords
:=
toWordSize
(
newMemSize
)
newMemSize
=
newMemSizeWords
*
32
newMemSize
=
newMemSizeWords
*
32
...
...
This diff is collapsed.
Click to expand it.
core/vm/gas_table_test.go
+
15
−
12
View file @
92faf1bf
...
@@ -19,18 +19,21 @@ package vm
...
@@ -19,18 +19,21 @@ package vm
import
"testing"
import
"testing"
func
TestMemoryGasCost
(
t
*
testing
.
T
)
{
func
TestMemoryGasCost
(
t
*
testing
.
T
)
{
//size := uint64(math.MaxUint64 - 64)
tests
:=
[]
struct
{
size
:=
uint64
(
0xffffffffe0
)
size
uint64
v
,
err
:=
memoryGasCost
(
&
Memory
{},
size
)
cost
uint64
if
err
!=
nil
{
overflow
bool
t
.
Error
(
"didn't expect error:"
,
err
)
}{
{
0x1fffffffe0
,
36028809887088637
,
false
},
{
0x1fffffffe1
,
0
,
true
},
}
}
if
v
!=
36028899963961341
{
for
i
,
tt
:=
range
tests
{
t
.
Errorf
(
"Expected: 36028899963961341, got %d"
,
v
)
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
)
}
}
_
,
err
=
memoryGasCost
(
&
Memory
{},
size
+
1
)
if
err
==
nil
{
t
.
Error
(
"expected error"
)
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment