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
a38dafcc
Commit
a38dafcc
authored
10 years ago
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved the To256
parent
bd7aca76
master
v1.10.12
v1.10.12-modified
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
29 deletions
+37
-29
big.go
ethutil/big.go
+13
-0
vm.go
ethvm/vm.go
+24
-29
No files found.
ethutil/big.go
View file @
a38dafcc
...
...
@@ -34,6 +34,19 @@ func BigD(data []byte) *big.Int {
return
n
}
// To256
//
// "cast" the big int to a 256 big int (i.e., limit to)
var
tt256
=
new
(
big
.
Int
)
.
Sub
(
new
(
big
.
Int
)
.
Lsh
(
big
.
NewInt
(
1
),
256
),
big
.
NewInt
(
1
))
func
To256
(
x
*
big
.
Int
)
{
x
.
And
(
x
,
tt256
)
if
x
.
Cmp
(
new
(
big
.
Int
))
<
0
{
x
.
SetInt64
(
0
)
}
}
// Big to bytes
//
// Returns the bytes of a big integer with the size specified by **base**
...
...
This diff is collapsed.
Click to expand it.
ethvm/vm.go
View file @
a38dafcc
...
...
@@ -9,6 +9,9 @@ import (
"github.com/ethereum/eth-go/ethutil"
)
// Shortcut :-)
var
To256
=
ethutil
.
To256
type
Debugger
interface
{
BreakHook
(
step
int
,
op
OpCode
,
mem
*
Memory
,
stack
*
Stack
,
object
*
ethstate
.
StateObject
)
bool
StepHook
(
step
int
,
op
OpCode
,
mem
*
Memory
,
stack
*
Stack
,
object
*
ethstate
.
StateObject
)
bool
...
...
@@ -262,7 +265,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Add
(
y
,
x
)
ensure
256
(
base
)
To
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
// Pop result back on the stack
...
...
@@ -274,7 +277,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Sub
(
y
,
x
)
ensure
256
(
base
)
To
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
// Pop result back on the stack
...
...
@@ -286,7 +289,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Mul
(
y
,
x
)
ensure
256
(
base
)
To
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
// Pop result back on the stack
...
...
@@ -300,7 +303,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Div
(
y
,
x
)
}
ensure
256
(
base
)
To
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
// Pop result back on the stack
...
...
@@ -314,7 +317,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Div
(
y
,
x
)
}
ensure
256
(
base
)
To
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
// Pop result back on the stack
...
...
@@ -327,7 +330,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Mod
(
y
,
x
)
ensure
256
(
base
)
To
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
stack
.
Push
(
base
)
...
...
@@ -339,7 +342,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Mod
(
y
,
x
)
ensure
256
(
base
)
To
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
stack
.
Push
(
base
)
...
...
@@ -352,7 +355,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Exp
(
y
,
x
,
Pow256
)
ensure
256
(
base
)
To
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
...
...
@@ -465,7 +468,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Add
(
x
,
y
)
base
.
Mod
(
base
,
z
)
ensure
256
(
base
)
To
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
...
...
@@ -480,7 +483,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
base
.
Mul
(
x
,
y
)
base
.
Mod
(
base
,
z
)
ensure
256
(
base
)
To
256
(
base
)
self
.
Printf
(
" = %v"
,
base
)
...
...
@@ -758,7 +761,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
// Snapshot the current stack so we are able to
// revert back to it later.
snapshot
=
self
.
env
.
State
()
.
Copy
()
//
snapshot = self.env.State().Copy()
)
// Generate a new address
...
...
@@ -778,7 +781,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
stack
.
Push
(
ethutil
.
BigFalse
)
// Revert the state as it was before.
self
.
env
.
State
()
.
Set
(
snapshot
)
//
self.env.State().Set(snapshot)
self
.
Printf
(
"CREATE err %v"
,
err
)
}
else
{
...
...
@@ -809,7 +812,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
// Get the arguments from the memory
args
:=
mem
.
Get
(
inOffset
.
Int64
(),
inSize
.
Int64
())
snapshot
:=
self
.
env
.
State
()
.
Copy
()
//
snapshot := self.env.State().Copy()
var
executeAddr
[]
byte
if
op
==
CALLCODE
{
...
...
@@ -823,7 +826,7 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
if
err
!=
nil
{
stack
.
Push
(
ethutil
.
BigFalse
)
self
.
env
.
State
()
.
Set
(
snapshot
)
//
self.env.State().Set(snapshot)
}
else
{
stack
.
Push
(
ethutil
.
BigTrue
)
...
...
@@ -905,21 +908,6 @@ func (self *Vm) Endl() *Vm {
return
self
}
func
ensure256
(
x
*
big
.
Int
)
{
//max, _ := big.NewInt(0).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639936", 0)
//if x.Cmp(max) >= 0 {
d
:=
big
.
NewInt
(
1
)
d
.
Lsh
(
d
,
256
)
.
Sub
(
d
,
big
.
NewInt
(
1
))
x
.
And
(
x
,
d
)
//}
// Could have done this with an OR, but big ints are costly.
if
x
.
Cmp
(
new
(
big
.
Int
))
<
0
{
x
.
SetInt64
(
0
)
}
}
type
Execution
struct
{
vm
*
Vm
closure
*
Closure
...
...
@@ -937,6 +925,8 @@ func (self *Execution) Addr() []byte {
}
func
(
self
*
Execution
)
Exec
(
codeAddr
[]
byte
,
caller
ClosureRef
)
(
ret
[]
byte
,
err
error
)
{
snapshot
:=
self
.
vm
.
env
.
State
()
.
Copy
()
msg
:=
self
.
vm
.
env
.
State
()
.
Manifest
()
.
AddMessage
(
&
ethstate
.
Message
{
To
:
self
.
address
,
From
:
caller
.
Address
(),
Input
:
self
.
input
,
...
...
@@ -957,6 +947,7 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) (ret []byte, err
caller
.
Object
()
.
SubAmount
(
self
.
value
)
stateObject
.
AddAmount
(
self
.
value
)
// Precompiled contracts (address.go) 1, 2 & 3.
if
p
:=
Precompiled
[
ethutil
.
BigD
(
codeAddr
)
.
Uint64
()];
p
!=
nil
{
if
self
.
gas
.
Cmp
(
p
.
Gas
)
>=
0
{
ret
=
p
.
Call
(
self
.
input
)
...
...
@@ -974,6 +965,10 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) (ret []byte, err
}
}
if
err
!=
nil
{
self
.
vm
.
env
.
State
()
.
Set
(
snapshot
)
}
return
}
...
...
This diff is collapsed.
Click to expand it.
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