Experimental repository to write smart contracts directly in EVM bytecode without the use of Solidity or any other intermediate language
Both EVM and Solidity are new and experimental technologies. Being able to get closer to the actual machine code that gets executed can provide significant advantages.
In a context where gas prices are very high, being able to save gas can have a profound impact.
The Solidity compiler and the Solidity optimizer can introduce bugs. However, not having the guardrails and protections provided by these tools can also introduce bugs. Furthermore, the fact that fewer people are able to audit a smart contract written in bytecode is also a very troubling possible avenue for bugs.
The Medianizer is one of the gas-critical components of the MakerDAO smart contract infrastructure. It is the on-chain gateway of Maker's decentralized oracle network. Take a look at this transaction. It costed 29 dollars at a moment when the network congestion was relatively low (59 Gwei). Since Maker's oracle relayers make several such calls a day, their annual cost can be extremely high, which has repercussions in Maker's security model.
I wrote a proof-of-concept bytecode implementation of the Medianizer and deployed it to Goerli in order to compare its gas consumption with the Solidity one. The results were as follows:
implementation | function | parameters | gas consumption | link |
---|---|---|---|---|
Solidity | poke | bar: 13 | 138,303 | https://etherscan.io/tx/0xb76e2...e1aa |
bytecode | poke | bar: 13 | 137,506 | https://goerli.etherscan.io/tx/0x8108...74b9 |
As you can see, the gas savings are modest. The bytecode implementation is 0.58% cheaper than the Solidity implementation. However, as EVM bytecode offers many possibilities for gas optimization, further research needs to be done in order to determine whether better results are possible.