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
205e33bc
Commit
205e33bc
authored
Mar 30, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug in stack to expand beyond expectations. Fixed EQ and NOT opcode
parent
6625b6ff
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
23 deletions
+32
-23
stack.go
ethchain/stack.go
+9
-5
vm.go
ethchain/vm.go
+14
-6
vm_test.go
ethchain/vm_test.go
+9
-12
No files found.
ethchain/stack.go
View file @
205e33bc
...
...
@@ -173,21 +173,25 @@ func NewStack() *Stack {
}
func
(
st
*
Stack
)
Pop
()
*
big
.
Int
{
str
:=
st
.
data
[
0
]
st
.
data
=
st
.
data
[
1
:
]
str
:=
st
.
data
[
len
(
st
.
data
)
-
1
]
copy
(
st
.
data
[
:
len
(
st
.
data
)
-
1
],
st
.
data
[
:
len
(
st
.
data
)
-
1
])
st
.
data
=
st
.
data
[
:
len
(
st
.
data
)
-
1
]
return
str
}
func
(
st
*
Stack
)
Popn
()
(
*
big
.
Int
,
*
big
.
Int
)
{
ints
:=
st
.
data
[
:
2
]
st
.
data
=
st
.
data
[
2
:
]
ints
:=
st
.
data
[
len
(
st
.
data
)
-
2
:
]
copy
(
st
.
data
[
:
len
(
st
.
data
)
-
2
],
st
.
data
[
:
len
(
st
.
data
)
-
2
])
st
.
data
=
st
.
data
[
:
len
(
st
.
data
)
-
2
]
return
ints
[
0
],
ints
[
1
]
}
func
(
st
*
Stack
)
Peek
()
*
big
.
Int
{
str
:=
st
.
data
[
0
]
str
:=
st
.
data
[
len
(
st
.
data
)
-
1
]
return
str
}
...
...
ethchain/vm.go
View file @
205e33bc
...
...
@@ -2,7 +2,7 @@ package ethchain
import
(
_
"bytes"
_
"fmt"
"fmt"
"github.com/ethereum/eth-go/ethutil"
_
"github.com/obscuren/secp256k1-go"
_
"math"
...
...
@@ -213,10 +213,17 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
}
else
{
stack
.
Push
(
ethutil
.
BigFalse
)
}
case
o
NOT
:
case
o
EQ
:
x
,
y
:=
stack
.
Popn
()
// x != y
if
x
.
Cmp
(
y
)
!=
0
{
// x == y
if
x
.
Cmp
(
y
)
==
0
{
stack
.
Push
(
ethutil
.
BigTrue
)
}
else
{
stack
.
Push
(
ethutil
.
BigFalse
)
}
case
oNOT
:
x
:=
stack
.
Pop
()
if
x
.
Cmp
(
ethutil
.
BigFalse
)
==
0
{
stack
.
Push
(
ethutil
.
BigTrue
)
}
else
{
stack
.
Push
(
ethutil
.
BigFalse
)
...
...
@@ -300,8 +307,8 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
case
oJUMP
:
pc
=
stack
.
Pop
()
case
oJUMPI
:
pos
,
cond
:=
stack
.
Popn
()
if
cond
.
Cmp
(
big
.
NewInt
(
0
))
>
0
{
cond
,
pos
:=
stack
.
Popn
()
if
cond
.
Cmp
(
ethutil
.
BigTrue
)
==
0
{
pc
=
pos
}
case
oPC
:
...
...
@@ -314,6 +321,7 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
retSize
,
retOffset
:=
stack
.
Popn
()
// Pop input size and offset
inSize
,
inOffset
:=
stack
.
Popn
()
fmt
.
Println
(
inSize
,
inOffset
)
// Get the arguments from the memory
args
:=
mem
.
Get
(
inOffset
.
Int64
(),
inSize
.
Int64
())
// Pop gas and value of the stack.
...
...
ethchain/vm_test.go
View file @
205e33bc
package
ethchain
import
(
"bytes"
_
"bytes"
"fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
...
...
@@ -11,6 +11,7 @@ import (
"testing"
)
/*
func TestRun3(t *testing.T) {
ethutil.ReadConfig("")
...
...
@@ -73,7 +74,7 @@ func TestRun3(t *testing.T) {
if bytes.Compare(ret, exp) != 0 {
t.Errorf("expected return value to be %v, got %v", exp, ret)
}
}
}
*/
func
TestRun4
(
t
*
testing
.
T
)
{
ethutil
.
ReadConfig
(
""
)
...
...
@@ -81,17 +82,13 @@ func TestRun4(t *testing.T) {
db
,
_
:=
ethdb
.
NewMemDatabase
()
state
:=
NewState
(
ethutil
.
NewTrie
(
db
,
""
))
mutan
.
Compile
(
strings
.
NewReader
(
`
a = 1337
c = 1
store[0] = 50
d = store[0]
`
),
false
)
asm
,
err
:=
mutan
.
Compile
(
strings
.
NewReader
(
`
a = 3 + 3
store[1000] = a
store[1000]
a = 10
b = 10
if a == b {
b = 1000
c = 10
}
`
),
false
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
...
...
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