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
01c1bce9
Commit
01c1bce9
authored
Mar 21, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed regular ints from the virtual machine and closures
parent
9a9e252c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
10 deletions
+39
-10
closure.go
ethchain/closure.go
+7
-2
contract.go
ethchain/contract.go
+7
-2
stack.go
ethchain/stack.go
+4
-0
vm.go
ethchain/vm.go
+15
-6
common.go
ethutil/common.go
+6
-0
No files found.
ethchain/closure.go
View file @
01c1bce9
...
@@ -15,7 +15,8 @@ type Callee interface {
...
@@ -15,7 +15,8 @@ type Callee interface {
type
ClosureBody
interface
{
type
ClosureBody
interface
{
Callee
Callee
ethutil
.
RlpEncodable
ethutil
.
RlpEncodable
GetMem
(
int64
)
*
ethutil
.
Value
GetMem
(
*
big
.
Int
)
*
ethutil
.
Value
SetMem
(
*
big
.
Int
,
*
ethutil
.
Value
)
}
}
// Basic inline closure object which implement the 'closure' interface
// Basic inline closure object which implement the 'closure' interface
...
@@ -36,7 +37,7 @@ func NewClosure(callee Callee, object ClosureBody, state *State, gas, val *big.I
...
@@ -36,7 +37,7 @@ func NewClosure(callee Callee, object ClosureBody, state *State, gas, val *big.I
}
}
// Retuns the x element in data slice
// Retuns the x element in data slice
func
(
c
*
Closure
)
GetMem
(
x
int64
)
*
ethutil
.
Value
{
func
(
c
*
Closure
)
GetMem
(
x
*
big
.
Int
)
*
ethutil
.
Value
{
m
:=
c
.
object
.
GetMem
(
x
)
m
:=
c
.
object
.
GetMem
(
x
)
if
m
==
nil
{
if
m
==
nil
{
return
ethutil
.
EmptyValue
()
return
ethutil
.
EmptyValue
()
...
@@ -45,6 +46,10 @@ func (c *Closure) GetMem(x int64) *ethutil.Value {
...
@@ -45,6 +46,10 @@ func (c *Closure) GetMem(x int64) *ethutil.Value {
return
m
return
m
}
}
func
(
c
*
Closure
)
SetMem
(
x
*
big
.
Int
,
val
*
ethutil
.
Value
)
{
c
.
object
.
SetMem
(
x
,
val
)
}
func
(
c
*
Closure
)
Address
()
[]
byte
{
func
(
c
*
Closure
)
Address
()
[]
byte
{
return
c
.
object
.
Address
()
return
c
.
object
.
Address
()
}
}
...
...
ethchain/contract.go
View file @
01c1bce9
...
@@ -39,12 +39,17 @@ func (c *Contract) State() *State {
...
@@ -39,12 +39,17 @@ func (c *Contract) State() *State {
return
c
.
state
return
c
.
state
}
}
func
(
c
*
Contract
)
GetMem
(
num
int64
)
*
ethutil
.
Value
{
func
(
c
*
Contract
)
GetMem
(
num
*
big
.
Int
)
*
ethutil
.
Value
{
nb
:=
ethutil
.
BigToBytes
(
big
.
NewInt
(
num
)
,
256
)
nb
:=
ethutil
.
BigToBytes
(
num
,
256
)
return
c
.
Addr
(
nb
)
return
c
.
Addr
(
nb
)
}
}
func
(
c
*
Contract
)
SetMem
(
num
*
big
.
Int
,
val
*
ethutil
.
Value
)
{
addr
:=
ethutil
.
BigToBytes
(
num
,
256
)
c
.
state
.
trie
.
Update
(
string
(
addr
),
string
(
val
.
Encode
()))
}
// Return the gas back to the origin. Used by the Virtual machine or Closures
// Return the gas back to the origin. Used by the Virtual machine or Closures
func
(
c
*
Contract
)
ReturnGas
(
val
*
big
.
Int
,
state
*
State
)
{
func
(
c
*
Contract
)
ReturnGas
(
val
*
big
.
Int
,
state
*
State
)
{
c
.
Amount
.
Add
(
c
.
Amount
,
val
)
c
.
Amount
.
Add
(
c
.
Amount
,
val
)
...
...
ethchain/stack.go
View file @
01c1bce9
...
@@ -237,6 +237,10 @@ func (m *Memory) Get(offset, size int64) []byte {
...
@@ -237,6 +237,10 @@ func (m *Memory) Get(offset, size int64) []byte {
return
m
.
store
[
offset
:
offset
+
size
]
return
m
.
store
[
offset
:
offset
+
size
]
}
}
func
(
m
*
Memory
)
Len
()
int
{
return
len
(
m
.
store
)
}
func
(
m
*
Memory
)
Print
()
{
func
(
m
*
Memory
)
Print
()
{
fmt
.
Println
(
"### MEM ###"
)
fmt
.
Println
(
"### MEM ###"
)
if
len
(
m
.
store
)
>
0
{
if
len
(
m
.
store
)
>
0
{
...
...
ethchain/vm.go
View file @
01c1bce9
...
@@ -49,7 +49,7 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
...
@@ -49,7 +49,7 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
// New stack (should this be shared?)
// New stack (should this be shared?)
stack
:=
NewStack
()
stack
:=
NewStack
()
// Instruction pointer
// Instruction pointer
pc
:=
int64
(
0
)
pc
:=
big
.
NewInt
(
0
)
// Current step count
// Current step count
step
:=
0
step
:=
0
// The base for all big integer arithmetic
// The base for all big integer arithmetic
...
@@ -226,7 +226,8 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
...
@@ -226,7 +226,8 @@ 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
++
pc
.
Add
(
pc
,
ethutil
.
Big1
)
val
:=
closure
.
GetMem
(
pc
)
.
BigInt
()
val
:=
closure
.
GetMem
(
pc
)
.
BigInt
()
stack
.
Push
(
val
)
stack
.
Push
(
val
)
case
oPOP
:
case
oPOP
:
...
@@ -250,14 +251,22 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
...
@@ -250,14 +251,22 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
mem
.
Set
(
mStart
.
Int64
(),
32
,
ethutil
.
BigToBytes
(
base
,
256
))
mem
.
Set
(
mStart
.
Int64
(),
32
,
ethutil
.
BigToBytes
(
base
,
256
))
case
oSLOAD
:
case
oSLOAD
:
loc
:=
stack
.
Pop
()
loc
:=
stack
.
Pop
()
val
:=
closure
.
GetMem
(
loc
.
Int64
()
)
val
:=
closure
.
GetMem
(
loc
)
stack
.
Push
(
val
.
BigInt
())
stack
.
Push
(
val
.
BigInt
())
case
oSSTORE
:
case
oSSTORE
:
val
,
loc
:=
stack
.
Popn
()
closure
.
SetMem
(
loc
,
ethutil
.
NewValue
(
val
))
case
oJUMP
:
case
oJUMP
:
pc
=
stack
.
Pop
()
case
oJUMPI
:
case
oJUMPI
:
pos
,
cond
:=
stack
.
Popn
()
if
cond
.
Cmp
(
big
.
NewInt
(
0
))
>
0
{
pc
=
pos
}
case
oPC
:
case
oPC
:
stack
.
Push
(
pc
)
case
oMSIZE
:
case
oMSIZE
:
stack
.
Push
(
big
.
NewInt
(
int64
(
mem
.
Len
())))
// 0x60 range
// 0x60 range
case
oCALL
:
case
oCALL
:
// Pop return size and offset
// Pop return size and offset
...
@@ -304,7 +313,7 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
...
@@ -304,7 +313,7 @@ func (vm *Vm) RunClosure(closure *Closure) []byte {
ethutil
.
Config
.
Log
.
Debugln
(
"Invalid opcode"
,
op
)
ethutil
.
Config
.
Log
.
Debugln
(
"Invalid opcode"
,
op
)
}
}
pc
++
pc
.
Add
(
pc
,
ethutil
.
Big1
)
}
}
}
}
...
@@ -682,7 +691,7 @@ func makeInlineTx(addr []byte, value, from, length *big.Int, contract *Contract,
...
@@ -682,7 +691,7 @@ func makeInlineTx(addr []byte, value, from, length *big.Int, contract *Contract,
j
:=
int64
(
0
)
j
:=
int64
(
0
)
dataItems
:=
make
([]
string
,
int
(
length
.
Uint64
()))
dataItems
:=
make
([]
string
,
int
(
length
.
Uint64
()))
for
i
:=
from
.
Int64
();
i
<
length
.
Int64
();
i
++
{
for
i
:=
from
.
Int64
();
i
<
length
.
Int64
();
i
++
{
dataItems
[
j
]
=
contract
.
GetMem
(
j
)
.
Str
()
dataItems
[
j
]
=
contract
.
GetMem
(
big
.
NewInt
(
j
)
)
.
Str
()
j
++
j
++
}
}
...
...
ethutil/common.go
View file @
01c1bce9
...
@@ -33,3 +33,9 @@ func CurrencyToString(num *big.Int) string {
...
@@ -33,3 +33,9 @@ func CurrencyToString(num *big.Int) string {
return
fmt
.
Sprintf
(
"%v Wei"
,
num
)
return
fmt
.
Sprintf
(
"%v Wei"
,
num
)
}
}
var
(
Big1
=
big
.
NewInt
(
1
)
Big0
=
big
.
NewInt
(
0
)
Big256
=
big
.
NewInt
(
0xff
)
)
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