Skip to content

Commit

Permalink
added huff support
Browse files Browse the repository at this point in the history
  • Loading branch information
hananbeer committed Sep 28, 2022
1 parent fc74cda commit 511e5a6
Show file tree
Hide file tree
Showing 6 changed files with 1,035 additions and 27 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# e=vm²

*e=vm²* (pronounced *evm-squared; the = is silent), also spelled *evm2*, is an evm that runs inside evm.
*e=vm²* (pronounced *evm-squared*; the = is silent), also spelled *evm2*, is an evm that runs inside evm.

## Yo dawg I heard you like building

Expand All @@ -24,6 +24,34 @@ Use `evm run` or the provided helper script:

`./disas.sh` will compile *evm2* and then show disassembly so, you can like, do things that help stuff.

# TBD

Not yet implemented:
- CALLDATASIIZE
- CALLDATACOPY
- CODESIZE
- KECCAK256
- JUMP, JUMPI - IMPORTANT I KNOW... will fix asap
- SELFDESTRUCT - currently implemented as STOP... (probably should not be implemented at all)
- CREATE, CREATE2

Implemented without virtualization: (will shift all data 32 bytes)
- REVERT
- LOG0, LOG1, LOG2, LOG3, LOG4
- CALL, STATICCALL, DELEGATECALL, CALLCODE
- PC
- RETURNDATASIZE (supposedly ok)
- RETURNDATACOPY (supposedly ok)
- RETURN (supposedly ok)
- GAS (note: can implement HOSTGAS opcode in addition to virtualized GAS but is it useful?)
- CALLDATASIIZE (this would be CODESIZE of the input code)

### untested

untested but presumably works:
- CODESIZE (simply replaced to CALLDATASIZE)
- CODECOPY (simply replaced to CALLDATACOPY)

# Fun fact

I used `evm` to write pure bytecode, I couldn't even use labels for jumps I had to calculate offsets!
Expand Down
49 changes: 25 additions & 24 deletions evm.easm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;; init memory
push 0
msize
mstore
;; init memory (pc2 at first word)
push 0
msize
mstore

;; start loop (offset 4)
jumpdest
Expand Down Expand Up @@ -42,7 +42,7 @@ mstore
;; jump to opcode stub / implementation
jump

;; each stub should be exactly 4 bytes
;; each stub should be exactly 6 bytes
;; usually jumpdest + opcode + no-ops

;; 00 STOP
Expand Down Expand Up @@ -408,34 +408,35 @@ mstore
push 0x668
jump

;; 35 CALLDATALOAD
;; 35 CALLDATALOAD; TODO: virtualize?
;; (requires an additional param for calldata which is annoying but essential)
jumpdest
calldataload
push 0x668
jump

;; 36 CALLDATASIIZE; TODO: fixup
;; 36 CALLDATASIIZE; TODO: fixup?
jumpdest
calldatasize
push 0x668
jump

;; 37 CALLDATACOPY; TODO: implement...
jumpdest
;; calldatacopy ;; TODO: restore implementation.. :( will need to init with different code, or use sload or something :\
revert
;; TODO: restore implementation.. :( will need to init with different code, or use sload or something :\
calldatacopy
push 0x668
jump

;; 38 CODESIZE; TODO: jump to impl
;; 38 CODESIZE; note this is simply implemented as CALLDATASIZE
jumpdest
codesize
calldatasize
push 0x668
jump

;; 39 CODECOPY; TODO: jump to CODECOPY_impl
;; 39 CODECOPY; note this is simply implemented as CALLDATACOPY
jumpdest
codecopy
calldatacopy
push 0x668
jump

Expand All @@ -457,13 +458,13 @@ mstore
push 0x668
jump

;; 3D RETURNDATASIZE; TODO: jump to impl
;; 3D RETURNDATASIZE
jumpdest
returndatasize
push 0x668
jump

;; 3E RETURNDATACOPY; TODO: jump to impl
;; 3E RETURNDATACOPY
jumpdest
returndatacopy
push 0x668
Expand Down Expand Up @@ -591,19 +592,19 @@ mstore
push 0x668
jump

;; 51 MLOAD
;; 51 MLOAD (virtual)
jumpdest
push 0x644
jump
invalid

;; 52 MSTORE
;; 52 MSTORE (virtual)
jumpdest
push 0x64d
jump
invalid

;; 53 MSTORE8
;; 53 MSTORE8 (virtual)
jumpdest
push 0x656
jump
Expand Down Expand Up @@ -633,13 +634,13 @@ mstore
push 0x668
jump

;; 58 PC
;; 58 PC; TODO: virtualize
jumpdest
pc
push 0x668
jump

;; 59 MSIZE
;; 59 MSIZE (virtual)
jumpdest
push 0x65f
jump
Expand Down Expand Up @@ -1079,19 +1080,19 @@ mstore
push 0x668
jump

;; A1 LOG1
;; A1 LOG1; TODO: jump to impl
jumpdest
log1
push 0x668
jump

;; A2 LOG2
;; A2 LOG2; TODO: jump to impl
jumpdest
log2
push 0x668
jump

;; A3 LOG3
;; A3 LOG3; TODO: jump to impl
jumpdest
log3
push 0x668
Expand Down Expand Up @@ -1818,7 +1819,7 @@ mstore

;; FF SELFDESTRUCT (DO NOT IMPLEMENT (or hook to prevent self-selfdestruct))
jumpdest
invalid
stop
invalid
invalid
invalid
Expand Down
Loading

0 comments on commit 511e5a6

Please sign in to comment.