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
c0a030ef
Commit
c0a030ef
authored
Apr 09, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new insruction methods
parent
90bb512f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
1 deletion
+39
-1
closure.go
ethchain/closure.go
+5
-0
contract.go
ethchain/contract.go
+9
-0
vm.go
ethchain/vm.go
+25
-1
No files found.
ethchain/closure.go
View file @
c0a030ef
...
...
@@ -17,6 +17,7 @@ type ClosureBody interface {
ethutil
.
RlpEncodable
GetMem
(
*
big
.
Int
)
*
ethutil
.
Value
SetMem
(
*
big
.
Int
,
*
ethutil
.
Value
)
GetInstr
(
*
big
.
Int
)
*
ethutil
.
Value
}
// Basic inline closure object which implement the 'closure' interface
...
...
@@ -46,6 +47,10 @@ func (c *Closure) GetMem(x *big.Int) *ethutil.Value {
return
m
}
func
(
c
*
Closure
)
GetInstr
(
x
*
big
.
Int
)
*
ethutil
.
Value
{
return
c
.
object
.
GetInstr
(
x
)
}
func
(
c
*
Closure
)
SetMem
(
x
*
big
.
Int
,
val
*
ethutil
.
Value
)
{
c
.
object
.
SetMem
(
x
,
val
)
}
...
...
ethchain/contract.go
View file @
c0a030ef
...
...
@@ -11,6 +11,7 @@ type Contract struct {
//state *ethutil.Trie
state
*
State
address
[]
byte
script
[]
byte
}
func
NewContract
(
address
[]
byte
,
Amount
*
big
.
Int
,
root
[]
byte
)
*
Contract
{
...
...
@@ -45,6 +46,14 @@ func (c *Contract) GetMem(num *big.Int) *ethutil.Value {
return
c
.
Addr
(
nb
)
}
func
(
c
*
Contract
)
GetInstr
(
pc
*
big
.
Int
)
*
ethutil
.
Value
{
if
int64
(
len
(
c
.
script
)
-
1
)
<
pc
.
Int64
()
{
return
ethutil
.
NewValue
(
0
)
}
return
ethutil
.
NewValueFromBytes
([]
byte
{
c
.
script
[
pc
.
Int64
()]})
}
func
(
c
*
Contract
)
SetMem
(
num
*
big
.
Int
,
val
*
ethutil
.
Value
)
{
addr
:=
ethutil
.
BigToBytes
(
num
,
256
)
c
.
state
.
trie
.
Update
(
string
(
addr
),
string
(
val
.
Encode
()))
...
...
ethchain/vm.go
View file @
c0a030ef
...
...
@@ -72,7 +72,7 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
for
{
step
++
// Get the memory location of pc
val
:=
closure
.
Get
Mem
(
pc
)
val
:=
closure
.
Get
Instr
(
pc
)
// Get the opcode (it must be an opcode!)
op
:=
OpCode
(
val
.
Uint
())
if
ethutil
.
Config
.
Debug
{
...
...
@@ -233,13 +233,37 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
// 0x10 range
case
oAND
:
x
,
y
:=
stack
.
Popn
()
if
(
x
.
Cmp
(
ethutil
.
BigTrue
)
>=
0
)
&&
(
y
.
Cmp
(
ethutil
.
BigTrue
)
>=
0
)
{
stack
.
Push
(
ethutil
.
BigTrue
)
}
else
{
stack
.
Push
(
ethutil
.
BigFalse
)
}
case
oOR
:
x
,
y
:=
stack
.
Popn
()
if
(
x
.
Cmp
(
ethutil
.
BigInt0
)
>=
0
)
||
(
y
.
Cmp
(
ethutil
.
BigInt0
)
>=
0
)
{
stack
.
Push
(
ethutil
.
BigTrue
)
}
else
{
stack
.
Push
(
ethutil
.
BigFalse
)
}
case
oXOR
:
x
,
y
:=
stack
.
Popn
()
stack
.
Push
(
base
.
Xor
(
x
,
y
))
case
oBYTE
:
val
,
th
:=
stack
.
Popn
()
if
th
.
Cmp
(
big
.
NewInt
(
32
))
<
0
{
stack
.
Push
(
big
.
NewInt
(
int64
(
len
(
val
.
Bytes
())
-
1
)
-
th
.
Int64
()))
}
else
{
stack
.
Push
(
ethutil
.
BigFalse
)
}
// 0x20 range
case
oSHA3
:
size
,
offset
:=
stack
.
Popn
()
data
:=
mem
.
Get
(
offset
.
Int64
(),
size
.
Int64
())
stack
.
Push
(
ethutil
.
BigD
(
data
))
// 0x30 range
case
oADDRESS
:
stack
.
Push
(
ethutil
.
BigD
(
closure
.
Object
()
.
Address
()))
...
...
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