diff options
author | stefan <stefan@s00.xyz> | 2023-05-24 22:29:46 -0400 |
---|---|---|
committer | stefan <stefan@s00.xyz> | 2023-05-24 22:29:46 -0400 |
commit | 20621e073562ee5d423b636fae8b6aa8e38275fa (patch) | |
tree | 4a81bde039e58602e44a213cfb8d91a65f1dadd9 /vm/vm.go | |
parent | ba2b9c8a1bb1876b6eb4c9783fde798b19de4418 (diff) | |
download | evm-20621e073562ee5d423b636fae8b6aa8e38275fa.tar.gz |
readme and cleanup
Diffstat (limited to 'vm/vm.go')
-rw-r--r-- | vm/vm.go | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -11,6 +11,7 @@ type Evm struct { memory Memory pc uint64 stopped bool + returndata []byte } func NewEvm(_code []byte) *Evm { @@ -19,25 +20,36 @@ func NewEvm(_code []byte) *Evm { stopped: true, stack : Stack{}, code: _code, + returndata: nil, } } -func (vm *Evm) Start() { +func (vm *Evm) Run() []byte { vm.stopped = false + fmt.Printf("code: ", vm.code) for !(vm.stopped) { - op := vm.code.Fetch(&(vm.pc), 1)[0] - fmt.Printf("pc: %d | opcode: %x -> string: %s\n", vm.pc, op, Instructions[op].name) - if op >= PUSH1 && op <= PUSH32 { - nb := op - PUSH1 + 1 - fmt.Printf("pushing %d byte value to the stack!\n", vm.pc, nb) - b := vm.code.Fetch(&(vm.pc), uint64(nb)) + s := vm.code.Fetch(&(vm.pc), 1) + op := Opcode(STOP) + if (s != nil) { + op = Opcode(s[0]) + } + + fmt.Printf("pc: %d | opcode: 0x%x -> string: %s\n", vm.pc, op, Instructions[op].name) + push := (&op).IsPush() + if (push != 0) { + b := vm.code.Fetch(&(vm.pc), uint64(push)) x := uint256.NewInt(0) x = x.SetBytes(b) vm.stack.Push(x) } else { - vm.Execute(op) + vm.Execute(byte(op)) } + + if (op == RETURN) { + return vm.returndata + } } + return nil } func (vm *Evm) Execute(op byte) { |