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
7849b7e9
Commit
7849b7e9
authored
Oct 28, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refund SSTORE properly
parent
5920aa7b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
state.go
ethstate/state.go
+25
-1
vm_debug.go
vm/vm_debug.go
+2
-1
No files found.
ethstate/state.go
View file @
7849b7e9
...
@@ -22,11 +22,13 @@ type State struct {
...
@@ -22,11 +22,13 @@ type State struct {
stateObjects
map
[
string
]
*
StateObject
stateObjects
map
[
string
]
*
StateObject
manifest
*
Manifest
manifest
*
Manifest
refund
map
[
string
]
*
big
.
Int
}
}
// Create a new state from a given trie
// Create a new state from a given trie
func
New
(
trie
*
ethtrie
.
Trie
)
*
State
{
func
New
(
trie
*
ethtrie
.
Trie
)
*
State
{
return
&
State
{
Trie
:
trie
,
stateObjects
:
make
(
map
[
string
]
*
StateObject
),
manifest
:
NewManifest
()}
return
&
State
{
Trie
:
trie
,
stateObjects
:
make
(
map
[
string
]
*
StateObject
),
manifest
:
NewManifest
()
,
refund
:
make
(
map
[
string
]
*
big
.
Int
)
}
}
}
// Retrieve the balance from the given address or 0 if object not found
// Retrieve the balance from the given address or 0 if object not found
...
@@ -39,6 +41,16 @@ func (self *State) GetBalance(addr []byte) *big.Int {
...
@@ -39,6 +41,16 @@ func (self *State) GetBalance(addr []byte) *big.Int {
return
ethutil
.
Big0
return
ethutil
.
Big0
}
}
func
(
self
*
State
)
Refund
(
addr
[]
byte
,
gas
,
price
*
big
.
Int
)
{
amount
:=
new
(
big
.
Int
)
.
Mul
(
gas
,
price
)
if
self
.
refund
[
string
(
addr
)]
==
nil
{
self
.
refund
[
string
(
addr
)]
=
new
(
big
.
Int
)
}
self
.
refund
[
string
(
addr
)]
=
new
(
big
.
Int
)
.
Add
(
self
.
refund
[
string
(
addr
)],
amount
)
}
func
(
self
*
State
)
AddBalance
(
addr
[]
byte
,
amount
*
big
.
Int
)
{
func
(
self
*
State
)
AddBalance
(
addr
[]
byte
,
amount
*
big
.
Int
)
{
stateObject
:=
self
.
GetStateObject
(
addr
)
stateObject
:=
self
.
GetStateObject
(
addr
)
if
stateObject
!=
nil
{
if
stateObject
!=
nil
{
...
@@ -186,6 +198,10 @@ func (self *State) Copy() *State {
...
@@ -186,6 +198,10 @@ func (self *State) Copy() *State {
state
.
stateObjects
[
k
]
=
stateObject
.
Copy
()
state
.
stateObjects
[
k
]
=
stateObject
.
Copy
()
}
}
for
addr
,
refund
:=
range
self
.
refund
{
state
.
refund
[
addr
]
=
refund
}
return
state
return
state
}
}
...
@@ -199,6 +215,7 @@ func (self *State) Set(state *State) {
...
@@ -199,6 +215,7 @@ func (self *State) Set(state *State) {
self
.
Trie
=
state
.
Trie
self
.
Trie
=
state
.
Trie
self
.
stateObjects
=
state
.
stateObjects
self
.
stateObjects
=
state
.
stateObjects
self
.
refund
=
state
.
refund
}
}
func
(
s
*
State
)
Root
()
interface
{}
{
func
(
s
*
State
)
Root
()
interface
{}
{
...
@@ -240,10 +257,17 @@ func (s *State) Sync() {
...
@@ -240,10 +257,17 @@ func (s *State) Sync() {
func
(
self
*
State
)
Empty
()
{
func
(
self
*
State
)
Empty
()
{
self
.
stateObjects
=
make
(
map
[
string
]
*
StateObject
)
self
.
stateObjects
=
make
(
map
[
string
]
*
StateObject
)
self
.
refund
=
make
(
map
[
string
]
*
big
.
Int
)
}
}
func
(
self
*
State
)
Update
()
{
func
(
self
*
State
)
Update
()
{
var
deleted
bool
var
deleted
bool
// Refund any gas that's left
for
addr
,
amount
:=
range
self
.
refund
{
self
.
GetStateObject
([]
byte
(
addr
))
.
AddBalance
(
amount
)
}
for
_
,
stateObject
:=
range
self
.
stateObjects
{
for
_
,
stateObject
:=
range
self
.
stateObjects
{
if
stateObject
.
remove
{
if
stateObject
.
remove
{
self
.
DeleteStateObject
(
stateObject
)
self
.
DeleteStateObject
(
stateObject
)
...
...
vm/vm_debug.go
View file @
7849b7e9
...
@@ -179,7 +179,8 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -179,7 +179,8 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
// 0 => non 0
// 0 => non 0
mult
=
ethutil
.
Big3
mult
=
ethutil
.
Big3
}
else
if
val
.
BigInt
()
.
Cmp
(
ethutil
.
Big0
)
!=
0
&&
len
(
y
.
Bytes
())
==
0
{
}
else
if
val
.
BigInt
()
.
Cmp
(
ethutil
.
Big0
)
!=
0
&&
len
(
y
.
Bytes
())
==
0
{
//state.AddBalance(closure.caller.Address(), new(big.Int).Mul(big.NewInt(100), closure.Price))
state
.
Refund
(
closure
.
caller
.
Address
(),
big
.
NewInt
(
100
),
closure
.
Price
)
mult
=
ethutil
.
Big0
mult
=
ethutil
.
Big0
}
else
{
}
else
{
// non 0 => non 0
// non 0 => non 0
...
...
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