good morning!!!!

Skip to content
Snippets Groups Projects
Commit b855e5f7 authored by Jeffrey Wilcke's avatar Jeffrey Wilcke
Browse files

Changed opcode numbers and added missing opcodes

parent 6593c694
No related branches found
No related tags found
No related merge requests found
...@@ -166,13 +166,9 @@ func (self *StateManager) ProcessTransaction(tx *Transaction, coinbase *StateObj ...@@ -166,13 +166,9 @@ func (self *StateManager) ProcessTransaction(tx *Transaction, coinbase *StateObj
// Subtract the amount from the senders account // Subtract the amount from the senders account
sender.SubAmount(totAmount) sender.SubAmount(totAmount)
fmt.Printf("state root after sender update %x\n", state.Root())
// Add the amount to receivers account which should conclude this transaction // Add the amount to receivers account which should conclude this transaction
receiver.AddAmount(tx.Value) receiver.AddAmount(tx.Value)
state.UpdateStateObject(receiver) state.UpdateStateObject(receiver)
fmt.Printf("state root after receiver update %x\n", state.Root())
} }
state.UpdateStateObject(sender) state.UpdateStateObject(sender)
...@@ -215,6 +211,8 @@ func (sm *StateManager) ApplyTransactions(coinbase []byte, state *State, block * ...@@ -215,6 +211,8 @@ func (sm *StateManager) ApplyTransactions(coinbase []byte, state *State, block *
validTxs = append(validTxs, tx) validTxs = append(validTxs, tx)
} }
fmt.Println("################# MADE\n", receipts, "\n############################")
// Update the total gas used for the block (to be mined) // Update the total gas used for the block (to be mined)
block.GasUsed = totalUsedGas block.GasUsed = totalUsedGas
...@@ -250,6 +248,7 @@ func (sm *StateManager) ApplyTransaction(coinbase []byte, state *State, block *B ...@@ -250,6 +248,7 @@ func (sm *StateManager) ApplyTransaction(coinbase []byte, state *State, block *B
// as it's data provider. // as it's data provider.
contract := sm.MakeStateObject(state, tx) contract := sm.MakeStateObject(state, tx)
if contract != nil { if contract != nil {
fmt.Println(Disassemble(contract.Init()))
// Evaluate the initialization script // Evaluate the initialization script
// and use the return value as the // and use the return value as the
// script section for the state object. // script section for the state object.
...@@ -323,6 +322,7 @@ func (sm *StateManager) ProcessBlock(state *State, parent, block *Block, dontRea ...@@ -323,6 +322,7 @@ func (sm *StateManager) ProcessBlock(state *State, parent, block *Block, dontRea
if !sm.bc.HasBlock(block.PrevHash) && sm.bc.CurrentBlock != nil { if !sm.bc.HasBlock(block.PrevHash) && sm.bc.CurrentBlock != nil {
return ParentError(block.PrevHash) return ParentError(block.PrevHash)
} }
fmt.Println(block.Receipts())
// Process the transactions on to current block // Process the transactions on to current block
sm.ApplyTransactions(block.Coinbase, state, parent, block.Transactions()) sm.ApplyTransactions(block.Coinbase, state, parent, block.Transactions())
......
package ethchain package ethchain
import ( import (
"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"
...@@ -144,7 +145,8 @@ func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) { ...@@ -144,7 +145,8 @@ func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) {
tx.v = byte(decoder.Get(6).Uint()) tx.v = byte(decoder.Get(6).Uint())
tx.r = decoder.Get(7).Bytes() tx.r = decoder.Get(7).Bytes()
tx.s = decoder.Get(8).Bytes() tx.s = decoder.Get(8).Bytes()
if len(tx.Recipient) == 0 {
if bytes.Compare(tx.Recipient, ContractAddr) == 0 {
tx.contractCreation = true tx.contractCreation = true
} }
} }
......
package ethchain package ethchain
import (
"fmt"
)
type OpCode int type OpCode int
// Op codes // Op codes
...@@ -37,7 +41,10 @@ const ( ...@@ -37,7 +41,10 @@ const (
CALLVALUE = 0x34 CALLVALUE = 0x34
CALLDATALOAD = 0x35 CALLDATALOAD = 0x35
CALLDATASIZE = 0x36 CALLDATASIZE = 0x36
GASPRICE = 0x37 CALLDATACOPY = 0x37
CODESIZE = 0x38
CODECOPY = 0x39
GASPRICE = 0x3a
// 0x40 range - block operations // 0x40 range - block operations
PREVHASH = 0x40 PREVHASH = 0x40
...@@ -48,18 +55,19 @@ const ( ...@@ -48,18 +55,19 @@ const (
GASLIMIT = 0x45 GASLIMIT = 0x45
// 0x50 range - 'storage' and execution // 0x50 range - 'storage' and execution
POP = 0x51 POP = 0x50
DUP = 0x52 DUP = 0x51
SWAP = 0x53 SWAP = 0x52
MLOAD = 0x54 MLOAD = 0x53
MSTORE = 0x55 MSTORE = 0x54
MSTORE8 = 0x56 MSTORE8 = 0x55
SLOAD = 0x57 SLOAD = 0x56
SSTORE = 0x58 SSTORE = 0x57
JUMP = 0x59 JUMP = 0x58
JUMPI = 0x5a JUMPI = 0x59
PC = 0x5b PC = 0x5a
MSIZE = 0x5c MSIZE = 0x5b
GAS = 0x5c
// 0x60 range // 0x60 range
PUSH1 = 0x60 PUSH1 = 0x60
...@@ -140,6 +148,9 @@ var opCodeToString = map[OpCode]string{ ...@@ -140,6 +148,9 @@ var opCodeToString = map[OpCode]string{
CALLVALUE: "CALLVALUE", CALLVALUE: "CALLVALUE",
CALLDATALOAD: "CALLDATALOAD", CALLDATALOAD: "CALLDATALOAD",
CALLDATASIZE: "CALLDATASIZE", CALLDATASIZE: "CALLDATASIZE",
CALLDATACOPY: "CALLDATACOPY",
CODESIZE: "CODESIZE",
CODECOPY: "CODECOPY",
GASPRICE: "TXGASPRICE", GASPRICE: "TXGASPRICE",
// 0x40 range - block operations // 0x40 range - block operations
...@@ -162,6 +173,7 @@ var opCodeToString = map[OpCode]string{ ...@@ -162,6 +173,7 @@ var opCodeToString = map[OpCode]string{
JUMPI: "JUMPI", JUMPI: "JUMPI",
PC: "PC", PC: "PC",
MSIZE: "MSIZE", MSIZE: "MSIZE",
GAS: "GAS",
// 0x60 range - push // 0x60 range - push
PUSH1: "PUSH1", PUSH1: "PUSH1",
...@@ -208,7 +220,12 @@ var opCodeToString = map[OpCode]string{ ...@@ -208,7 +220,12 @@ var opCodeToString = map[OpCode]string{
} }
func (o OpCode) String() string { func (o OpCode) String() string {
return opCodeToString[o] str := opCodeToString[o]
if len(str) == 0 {
return fmt.Sprintf("Missing opcode 0x%x", int(o))
}
return str
} }
// Op codes for assembling // Op codes for assembling
......
...@@ -337,6 +337,9 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro ...@@ -337,6 +337,9 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
stack.Push(ethutil.BigD(data)) stack.Push(ethutil.BigD(data))
case CALLDATASIZE: case CALLDATASIZE:
stack.Push(big.NewInt(int64(len(closure.Args)))) stack.Push(big.NewInt(int64(len(closure.Args))))
case CALLDATACOPY:
case CODESIZE:
case CODECOPY:
case GASPRICE: case GASPRICE:
stack.Push(closure.Price) stack.Push(closure.Price)
...@@ -423,6 +426,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro ...@@ -423,6 +426,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
stack.Push(pc) stack.Push(pc)
case MSIZE: case MSIZE:
stack.Push(big.NewInt(int64(mem.Len()))) stack.Push(big.NewInt(int64(mem.Len())))
case GAS:
stack.Push(closure.Gas)
// 0x60 range // 0x60 range
case CREATE: case CREATE:
require(3) require(3)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment