The EVM back end
How omegyu evm build compiles a contract, what it prints and writes, the options of a deployment, and where the contract model and its tests are documented.
omegyu evm build FILE compiles a contract for the Osaka fork of Ethereum.
The value of the file is a record with a field contract, which
std:EVM/Contract builds. The compiler checks
the program, stages the contract's term into code, and validates the code
that it generates
(the pipeline).
A contract
Counter attaches a view to two public names:
read for native calls and count for Solidity. Choose Build… to compile
the whole contract, not just the displayed lines.
, read =
C.define
(C.on
(C.Routes.Both
{ native = C.Name.Field, solidity = C.Name.Rename ("count", refl) })
(C.reading { Args = {}, Result = Word 256 }))
(\_ -> state.count.read)EVM interfaceruntime 815 bytes, deployment 868 bytes
0x1003e2d2 add(uint256)
0x584e235d addTimes(uint256,uint8)
0xd09de08a increment()
0x06661abd count()
0x4f4d47010510660c add (nonpayable)
0x4f4d4701baf65249 addAll (nonpayable)
0x4f4d470121e9d791 addTimes (nonpayable)
0x4f4d4701cdcc9267 increment (nonpayable)
0x4f4d470117d0e339 read (view)Each native method has an 8-byte header and a mode. Dispatch through two interfaces explains the headers, and actions and modes the modes.
What it prints
Without --output, omegyu evm build prints the runtime code and the init
code in hexadecimal, then the selector of each Solidity function, then the
header, the name and the mode of each native method:
$ omegyu evm build examples/evm/Counter.omg
runtime 346101c157634f4d47015f3560e01c1461016d575b600436106101c1575f3560…
init 346031576020620003643803036031575f62000364016020906020396020515f…
1003e2d2 add(uint256)
584e235d addTimes(uint256,uint8)
d09de08a increment()
06661abd count()
4f4d47010510660c native add nonpayable
4f4d4701baf65249 native addAll nonpayable
4f4d470121e9d791 native addTimes nonpayable
4f4d4701cdcc9267 native increment nonpayable
4f4d470117d0e339 native read viewThe init code is what a creation transaction sends, followed by the constructor's arguments.
Options
| Option | Effect |
|---|---|
-o DIR, --output DIR | writes the plan, the interfaces and any bytecode of a direct deployment into DIR |
--abi | prints the contract's ABI JSON instead |
--dump-ir FILE | writes the staged IR, the assembly blocks and their byte offsets as JSON |
--constructor-args HEX | includes encoded constructor arguments; creation input that is too large selects a package deployment |
--sender ADDRESS --nonce N | the deploying account and its next nonce, from which a package predicts the addresses of its installation |
--value WEI | the value that the deployment plan sends to the constructor |
With -o out, the build of examples/evm/Counter.omg writes
Counter.runtime.hex, Counter.init.hex, Counter.selectors.txt,
Counter.abi.json, Counter.native.json and Counter.plan.json into
out. omegyu evm plan FILE takes the same options, and prints the
deployment plan, measured, without sending a transaction.
Packages
A contract whose runtime code exceeds 24,576 bytes, the limit of EIP-170,
is installed as a package: its components, a root, a factory and an
installer, created by several transactions. The benchmark methodology explains how the measurements account for all of them.
omegyu evm build selects a package automatically, and --sender and
--nonce let it predict the addresses of the installation.
The contract model
std:EVM/Contract is an ordinary library: a
contract's state, methods, events and errors are types, and its handlers
are actions whose modes are in their types. The repository documents the
model and its proofs:
docs/contracts.md: the contract model, what it implements and what remains.
docs/evm.md: the design of the back end, the storage format and the soundness argument.
docs/contract-foundations.md: the pure foundations of contracts, which carry their kernel-checked laws.
docs/evm-hevm-coverage.md: what hevm, which runs the tests, implements of Osaka.
Benchmarks against Solidity: the comparison with solc, summarised in Omegyu vs. Solidity.
Examples
Counter: read a scalar field and choose checked or wrapping addition.
Token: keep balances by address and call the same balance and allowance handlers from a query loop.
Pool: combine a proved swap formula with calls to two external tokens.
Lending: update nested positions, accrue interest and check protocol-specific limits.
For the last three, start with the interface. Pool's two swap signatures have the same type. Their implementation fields choose the two directions. The top-level contract takes the resulting facet as a whole: it has no second choice of handler to get wrong.