Skip to content

hayeah/evm-clojure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An EVM Low Level Lisp compiler, in Clojure.

Start REPL:

lein repl

Then load the module

(require 'clll.core :reload)

Compile a minimal program:

(clll.core/genbinary '[
    (mstore 0 0xaabbcc)
    (return 0 32)
])

; => "62aabbcc60005260206000f3"

Run with EVM CLI:

evm  --statdump --code 62aabbcc60005260206000f3 --input aabb run
evm execution time: 119.82µs
heap objects:       10424
allocations:        1516432
total allocations:  1516432
GC calls:           0
Gas used:           18

0x0000000000000000000000000000000000000000000000000000000000aabbcc

A Minimal Deployable Contract

(def code '[
  (codecopy 0x0 (blockoffset :contract) (blocksize :contract))
  (return 0x0 (blocksize :contract))

  (block :contract
    (mstore 0 0xaabbcc)
    (return 0 32))
])

Compile expression to instructions:

=> (clll.core/genassembly code)
((:blocksize :contract) (:blockoffset :contract) 0 :codecopy (:blocksize :contract) 0 :return (:block :contract 11189196 0 :mstore 32 0 :return))

Convert instructions to bytecode:

=> (clll.core/genbinary code)
"600c600c600039600c6000f35b62aabbcc60005260206000f3"

About

EVM Low Level Lisp compiler in Clojure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages