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
caa2c23a
Unverified
Commit
caa2c23a
authored
Aug 12, 2018
by
Martin Holst Swende
Committed by
Péter Szilágyi
Sep 18, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core,state: finish implementing Eip 1283
parent
58374e28
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
16 deletions
+41
-16
state_object.go
core/state/state_object.go
+10
-0
statedb.go
core/state/statedb.go
+8
-0
gas_table.go
core/vm/gas_table.go
+13
-16
interface.go
core/vm/interface.go
+1
-0
jump_table.go
core/vm/jump_table.go
+8
-0
noop.go
core/vm/noop.go
+1
-0
No files found.
core/state/state_object.go
View file @
caa2c23a
...
...
@@ -183,6 +183,16 @@ func (self *stateObject) GetState(db Database, key common.Hash) common.Hash {
return
value
}
// GetOriginalStateValue returns the state value that is currently in the Trie, that is, ignoring any
// changes that have been made but not yet written to trie.
func
(
self
*
stateObject
)
GetOriginalStateValue
(
db
Database
,
key
common
.
Hash
)
common
.
Hash
{
if
original
,
exist
:=
self
.
originalValue
[
key
];
exist
{
// original value has been set, return it
return
original
}
return
self
.
GetState
(
db
,
key
)
}
// SetState updates a value in account storage.
func
(
self
*
stateObject
)
SetState
(
db
Database
,
key
,
value
common
.
Hash
)
{
prev
:=
self
.
GetState
(
db
,
key
)
...
...
core/state/statedb.go
View file @
caa2c23a
...
...
@@ -255,6 +255,14 @@ func (self *StateDB) GetState(addr common.Address, bhash common.Hash) common.Has
return
common
.
Hash
{}
}
func
(
self
*
StateDB
)
GetStateOriginal
(
addr
common
.
Address
,
bhash
common
.
Hash
)
common
.
Hash
{
stateObject
:=
self
.
getStateObject
(
addr
)
if
stateObject
!=
nil
{
return
stateObject
.
GetOriginalStateValue
(
self
.
db
,
bhash
)
}
return
common
.
Hash
{}
}
// Database retrieves the low level database supporting the lower level trie ops.
func
(
self
*
StateDB
)
Database
()
Database
{
return
self
.
db
...
...
core/vm/gas_table.go
View file @
caa2c23a
...
...
@@ -17,11 +17,9 @@
package
vm
import
(
"bytes"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/params"
"math/big"
)
// memoryGasCosts calculates the quadratic gas for memory expansion. It does so
...
...
@@ -117,7 +115,7 @@ func gasReturnDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *
return
gas
,
nil
}
func
gasSStore
Old
(
gt
params
.
GasTable
,
evm
*
EVM
,
contract
*
Contract
,
stack
*
Stack
,
mem
*
Memory
,
memorySize
uint64
)
(
uint64
,
error
)
{
func
gasSStore
(
gt
params
.
GasTable
,
evm
*
EVM
,
contract
*
Contract
,
stack
*
Stack
,
mem
*
Memory
,
memorySize
uint64
)
(
uint64
,
error
)
{
var
(
y
,
x
=
stack
.
Back
(
1
),
stack
.
Back
(
0
)
val
=
evm
.
StateDB
.
GetState
(
contract
.
Address
(),
common
.
BigToHash
(
x
))
...
...
@@ -139,10 +137,11 @@ func gasSStoreOld(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack
}
}
func
gasSStore
(
gt
params
.
GasTable
,
evm
*
EVM
,
contract
*
Contract
,
stack
*
Stack
,
mem
*
Memory
,
memorySize
uint64
)
(
uint64
,
error
)
{
// gasSStoreEip1283 calculates SSTORE gas cost according to EIP-1283
func
gasSStoreEip1283
(
gt
params
.
GasTable
,
evm
*
EVM
,
contract
*
Contract
,
stack
*
Stack
,
mem
*
Memory
,
memorySize
uint64
)
(
uint64
,
error
)
{
var
(
y
,
x
=
stack
.
Back
(
1
),
stack
.
Back
(
0
)
current
=
evm
.
StateDB
.
GetState
(
contract
.
Address
(),
common
.
BigToHash
(
x
))
y
,
x
=
stack
.
Back
(
1
),
stack
.
Back
(
0
)
current
=
evm
.
StateDB
.
GetState
(
contract
.
Address
(),
common
.
BigToHash
(
x
))
)
//1. If current value equals new value (this is a no-op), 200 gas is deducted.
//2. If current value does not equal new value
...
...
@@ -161,33 +160,31 @@ func gasSStore(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, m
// 1. current == new
return
200
,
nil
}
// Todo, get this value
original
:=
common
.
Hash
{}
original
:=
evm
.
StateDB
.
GetStateOriginal
(
contract
.
Address
(),
common
.
BigToHash
(
x
))
// 2
if
original
==
current
{
// 2.1
if
original
==
(
common
.
Hash
{}){
// 2.1.1
if
original
==
(
common
.
Hash
{})
{
// 2.1.1
return
20000
,
nil
}
// 2.1.2
if
new
==
(
common
.
Hash
{}){
if
new
==
(
common
.
Hash
{})
{
evm
.
StateDB
.
AddRefund
(
15000
)
}
return
5000
,
nil
}
// 2.2
if
original
!=
(
common
.
Hash
{}){
// 2.2.1
if
current
==
(
common
.
Hash
{}){
// 2.2.1.1
if
original
!=
(
common
.
Hash
{})
{
// 2.2.1
if
current
==
(
common
.
Hash
{})
{
// 2.2.1.1
evm
.
StateDB
.
SubRefund
(
15000
)
}
else
{
}
else
{
// 2.2.1.2
evm
.
StateDB
.
AddRefund
(
15000
)
}
}
if
original
==
new
{
// 2.2.2
if
original
==
(
common
.
Hash
{}){
if
original
==
(
common
.
Hash
{})
{
evm
.
StateDB
.
AddRefund
(
19800
)
}
else
{
}
else
{
evm
.
StateDB
.
AddRefund
(
4800
)
}
}
...
...
core/vm/interface.go
View file @
caa2c23a
...
...
@@ -44,6 +44,7 @@ type StateDB interface {
GetRefund
()
uint64
GetState
(
common
.
Address
,
common
.
Hash
)
common
.
Hash
GetStateOriginal
(
common
.
Address
,
common
.
Hash
)
common
.
Hash
SetState
(
common
.
Address
,
common
.
Hash
,
common
.
Hash
)
Suicide
(
common
.
Address
)
bool
...
...
core/vm/jump_table.go
View file @
caa2c23a
...
...
@@ -95,6 +95,14 @@ func newConstantinopleInstructionSet() [256]operation {
writes
:
true
,
returns
:
true
,
}
instructionSet
[
SSTORE
]
=
operation
{
execute
:
opSstore
,
gasCost
:
gasSStoreEip1283
,
validateStack
:
makeStackFunc
(
2
,
0
),
valid
:
true
,
writes
:
true
,
}
return
instructionSet
}
...
...
core/vm/noop.go
View file @
caa2c23a
...
...
@@ -59,6 +59,7 @@ func (NoopStateDB) AddRefund(uint64)
func
(
NoopStateDB
)
SubRefund
(
uint64
)
{}
func
(
NoopStateDB
)
GetRefund
()
uint64
{
return
0
}
func
(
NoopStateDB
)
GetState
(
common
.
Address
,
common
.
Hash
)
common
.
Hash
{
return
common
.
Hash
{}
}
func
(
NoopStateDB
)
GetStateOriginal
(
common
.
Address
,
common
.
Hash
)
common
.
Hash
{
return
common
.
Hash
{}
}
func
(
NoopStateDB
)
SetState
(
common
.
Address
,
common
.
Hash
,
common
.
Hash
)
{}
func
(
NoopStateDB
)
Suicide
(
common
.
Address
)
bool
{
return
false
}
func
(
NoopStateDB
)
HasSuicided
(
common
.
Address
)
bool
{
return
false
}
...
...
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