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
6a530ea3
Commit
6a530ea3
authored
Apr 10, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call fixed
parent
0fccbeab
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
35 deletions
+50
-35
closure.go
ethchain/closure.go
+4
-0
contract.go
ethchain/contract.go
+3
-1
vm.go
ethchain/vm.go
+16
-10
vm_test.go
ethchain/vm_test.go
+20
-3
parsing.go
ethutil/parsing.go
+7
-21
No files found.
ethchain/closure.go
View file @
6a530ea3
...
@@ -52,6 +52,10 @@ func (c *Closure) Get(x *big.Int) *ethutil.Value {
...
@@ -52,6 +52,10 @@ func (c *Closure) Get(x *big.Int) *ethutil.Value {
}
}
func
(
c
*
Closure
)
Gets
(
x
,
y
*
big
.
Int
)
*
ethutil
.
Value
{
func
(
c
*
Closure
)
Gets
(
x
,
y
*
big
.
Int
)
*
ethutil
.
Value
{
if
x
.
Int64
()
>
int64
(
len
(
c
.
Script
))
||
y
.
Int64
()
>
int64
(
len
(
c
.
Script
))
{
return
ethutil
.
NewValue
(
0
)
}
partial
:=
c
.
Script
[
x
.
Int64
()
:
x
.
Int64
()
+
y
.
Int64
()]
partial
:=
c
.
Script
[
x
.
Int64
()
:
x
.
Int64
()
+
y
.
Int64
()]
return
ethutil
.
NewValue
(
partial
)
return
ethutil
.
NewValue
(
partial
)
...
...
ethchain/contract.go
View file @
6a530ea3
...
@@ -70,7 +70,7 @@ func (c *Contract) Address() []byte {
...
@@ -70,7 +70,7 @@ func (c *Contract) Address() []byte {
}
}
func
(
c
*
Contract
)
RlpEncode
()
[]
byte
{
func
(
c
*
Contract
)
RlpEncode
()
[]
byte
{
return
ethutil
.
Encode
([]
interface
{}{
c
.
Amount
,
c
.
Nonce
,
c
.
state
.
trie
.
Root
})
return
ethutil
.
Encode
([]
interface
{}{
c
.
Amount
,
c
.
Nonce
,
c
.
state
.
trie
.
Root
,
c
.
script
,
c
.
initScript
})
}
}
func
(
c
*
Contract
)
RlpDecode
(
data
[]
byte
)
{
func
(
c
*
Contract
)
RlpDecode
(
data
[]
byte
)
{
...
@@ -79,6 +79,8 @@ func (c *Contract) RlpDecode(data []byte) {
...
@@ -79,6 +79,8 @@ func (c *Contract) RlpDecode(data []byte) {
c
.
Amount
=
decoder
.
Get
(
0
)
.
BigInt
()
c
.
Amount
=
decoder
.
Get
(
0
)
.
BigInt
()
c
.
Nonce
=
decoder
.
Get
(
1
)
.
Uint
()
c
.
Nonce
=
decoder
.
Get
(
1
)
.
Uint
()
c
.
state
=
NewState
(
ethutil
.
NewTrie
(
ethutil
.
Config
.
Db
,
decoder
.
Get
(
2
)
.
Interface
()))
c
.
state
=
NewState
(
ethutil
.
NewTrie
(
ethutil
.
Config
.
Db
,
decoder
.
Get
(
2
)
.
Interface
()))
c
.
script
=
decoder
.
Get
(
3
)
.
Bytes
()
c
.
initScript
=
decoder
.
Get
(
4
)
.
Bytes
()
}
}
func
MakeContract
(
tx
*
Transaction
,
state
*
State
)
*
Contract
{
func
MakeContract
(
tx
*
Transaction
,
state
*
State
)
*
Contract
{
...
...
ethchain/vm.go
View file @
6a530ea3
...
@@ -2,7 +2,7 @@ package ethchain
...
@@ -2,7 +2,7 @@ package ethchain
import
(
import
(
_
"bytes"
_
"bytes"
"fmt"
_
"fmt"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
_
"github.com/obscuren/secp256k1-go"
_
"github.com/obscuren/secp256k1-go"
_
"math"
_
"math"
...
@@ -301,9 +301,14 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
...
@@ -301,9 +301,14 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
// 0x50 range
// 0x50 range
case
oPUSH
:
// Push PC+1 on to the stack
case
oPUSH
:
// Push PC+1 on to the stack
pc
.
Add
(
pc
,
ethutil
.
Big1
)
pc
.
Add
(
pc
,
ethutil
.
Big1
)
//val := closure.GetMem(pc).BigInt()
data
:=
closure
.
Gets
(
pc
,
big
.
NewInt
(
32
))
val
:=
ethutil
.
BigD
(
data
.
Bytes
())
val
:=
closure
.
GetMem
(
pc
)
.
BigInt
()
// Push value to stack
stack
.
Push
(
val
)
stack
.
Push
(
val
)
pc
.
Add
(
pc
,
big
.
NewInt
(
31
))
case
oPOP
:
case
oPOP
:
stack
.
Pop
()
stack
.
Pop
()
case
oDUP
:
case
oDUP
:
...
@@ -343,17 +348,16 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
...
@@ -343,17 +348,16 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
stack
.
Push
(
big
.
NewInt
(
int64
(
mem
.
Len
())))
stack
.
Push
(
big
.
NewInt
(
int64
(
mem
.
Len
())))
// 0x60 range
// 0x60 range
case
oCALL
:
case
oCALL
:
// Pop return size and offset
// Closure addr
retSize
,
retOffset
:=
stack
.
Popn
()
addr
:=
stack
.
Pop
()
// Pop gas and value of the stack.
gas
,
value
:=
stack
.
Popn
()
// Pop input size and offset
// Pop input size and offset
inSize
,
inOffset
:=
stack
.
Popn
()
inSize
,
inOffset
:=
stack
.
Popn
()
fmt
.
Println
(
inSize
,
inOffset
)
// Pop return size and offset
retSize
,
retOffset
:=
stack
.
Popn
()
// Get the arguments from the memory
// Get the arguments from the memory
args
:=
mem
.
Get
(
inOffset
.
Int64
(),
inSize
.
Int64
())
args
:=
mem
.
Get
(
inOffset
.
Int64
(),
inSize
.
Int64
())
// Pop gas and value of the stack.
gas
,
value
:=
stack
.
Popn
()
// Closure addr
addr
:=
stack
.
Pop
()
// Fetch the contract which will serve as the closure body
// Fetch the contract which will serve as the closure body
contract
:=
vm
.
state
.
GetContract
(
addr
.
Bytes
())
contract
:=
vm
.
state
.
GetContract
(
addr
.
Bytes
())
// Create a new callable closure
// Create a new callable closure
...
@@ -385,7 +389,9 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
...
@@ -385,7 +389,9 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
break out
break out
*/
*/
default
:
default
:
ethutil
.
Config
.
Log
.
Debugln
(
"Invalid opcode"
,
op
)
ethutil
.
Config
.
Log
.
Debugf
(
"Invalid opcode %x
\n
"
,
op
)
return
closure
.
Return
(
nil
)
}
}
pc
.
Add
(
pc
,
ethutil
.
Big1
)
pc
.
Add
(
pc
,
ethutil
.
Big1
)
...
...
ethchain/vm_test.go
View file @
6a530ea3
...
@@ -83,6 +83,21 @@ func TestRun4(t *testing.T) {
...
@@ -83,6 +83,21 @@ func TestRun4(t *testing.T) {
state
:=
NewState
(
ethutil
.
NewTrie
(
db
,
""
))
state
:=
NewState
(
ethutil
.
NewTrie
(
db
,
""
))
asm
,
err
:=
mutan
.
Compile
(
strings
.
NewReader
(
`
asm
,
err
:=
mutan
.
Compile
(
strings
.
NewReader
(
`
int32 a = 10
int32 b = 20
if a > b {
int32 c = this.caller()
}
exit()
`
),
false
)
script
:=
ethutil
.
Assemble
(
asm
...
)
tx
:=
NewContractCreationTx
(
ethutil
.
Big
(
"0"
),
ethutil
.
Big
(
"1000"
),
script
)
addr
:=
tx
.
Hash
()[
12
:
]
contract
:=
MakeContract
(
tx
,
state
)
state
.
UpdateContract
(
contract
)
fmt
.
Printf
(
"%x
\n
"
,
addr
)
asm
,
err
=
mutan
.
Compile
(
strings
.
NewReader
(
`
int32 a = 10
int32 a = 10
int32 b = 10
int32 b = 10
if a == b {
if a == b {
...
@@ -97,9 +112,9 @@ func TestRun4(t *testing.T) {
...
@@ -97,9 +112,9 @@ func TestRun4(t *testing.T) {
store[a] = 20
store[a] = 20
store[b] = this.caller()
store[b] = this.caller()
int8
[10] ret
int8
ret = 0
int8
[10] arg
int8
arg = 10
call(
1234
, 0, 100000000, arg, ret)
call(
938726394128221156290138488023434115948430767407
, 0, 100000000, arg, ret)
`
),
false
)
`
),
false
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
...
@@ -113,6 +128,8 @@ func TestRun4(t *testing.T) {
...
@@ -113,6 +128,8 @@ func TestRun4(t *testing.T) {
// Contract addr as test address
// Contract addr as test address
account
:=
NewAccount
(
ContractAddr
,
big
.
NewInt
(
10000000
))
account
:=
NewAccount
(
ContractAddr
,
big
.
NewInt
(
10000000
))
c
:=
MakeContract
(
callerTx
,
state
)
c
:=
MakeContract
(
callerTx
,
state
)
//fmt.Println(c.script[230:240])
//fmt.Println(c.script)
callerClosure
:=
NewClosure
(
account
,
c
,
c
.
script
,
state
,
big
.
NewInt
(
1000000000
),
new
(
big
.
Int
))
callerClosure
:=
NewClosure
(
account
,
c
,
c
.
script
,
state
,
big
.
NewInt
(
1000000000
),
new
(
big
.
Int
))
vm
:=
NewVm
(
state
,
RuntimeVars
{
vm
:=
NewVm
(
state
,
RuntimeVars
{
...
...
ethutil/parsing.go
View file @
6a530ea3
package
ethutil
package
ethutil
import
(
import
(
_
"fmt"
"math/big"
"math/big"
"strconv"
)
)
// Op codes
// Op codes
...
@@ -98,11 +98,16 @@ func CompileInstr(s interface{}) ([]byte, error) {
...
@@ -98,11 +98,16 @@ func CompileInstr(s interface{}) ([]byte, error) {
// Assume regular bytes during compilation
// Assume regular bytes during compilation
if
!
success
{
if
!
success
{
num
.
SetBytes
([]
byte
(
str
))
num
.
SetBytes
([]
byte
(
str
))
}
else
{
// tmp fix for 32 bytes
n
:=
BigToBytes
(
num
,
256
)
return
n
,
nil
}
}
return
num
.
Bytes
(),
nil
return
num
.
Bytes
(),
nil
case
int
:
case
int
:
return
big
.
NewInt
(
int64
(
s
.
(
int
)))
.
Bytes
(),
nil
num
:=
BigToBytes
(
big
.
NewInt
(
int64
(
s
.
(
int
))),
256
)
return
num
,
nil
case
[]
byte
:
case
[]
byte
:
return
BigD
(
s
.
([]
byte
))
.
Bytes
(),
nil
return
BigD
(
s
.
([]
byte
))
.
Bytes
(),
nil
}
}
...
@@ -110,25 +115,6 @@ func CompileInstr(s interface{}) ([]byte, error) {
...
@@ -110,25 +115,6 @@ func CompileInstr(s interface{}) ([]byte, error) {
return
nil
,
nil
return
nil
,
nil
}
}
func
Instr
(
instr
string
)
(
int
,
[]
string
,
error
)
{
base
:=
new
(
big
.
Int
)
base
.
SetString
(
instr
,
0
)
args
:=
make
([]
string
,
7
)
for
i
:=
0
;
i
<
7
;
i
++
{
// int(int(val) / int(math.Pow(256,float64(i)))) % 256
exp
:=
BigPow
(
256
,
i
)
num
:=
new
(
big
.
Int
)
num
.
Div
(
base
,
exp
)
args
[
i
]
=
num
.
Mod
(
num
,
big
.
NewInt
(
256
))
.
String
()
}
op
,
_
:=
strconv
.
Atoi
(
args
[
0
])
return
op
,
args
[
1
:
7
],
nil
}
// Script compilation functions
// Script compilation functions
// Compiles strings to machine code
// Compiles strings to machine code
func
Assemble
(
instructions
...
interface
{})
(
script
[]
byte
)
{
func
Assemble
(
instructions
...
interface
{})
(
script
[]
byte
)
{
...
...
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