Reach Graduates the Consensys Grant Program
We graduated from the second Consensys Grant Program and it was a success!
Reach provides the tools essential to increase the speed, and decrease the risks, of blockchain development. Our tools are specifically designed and built to reduce onboarding time, costs and the expenditure of resources while maintaining enough flexibility for developers to accomplish their goals. Blockchain has the disruptive potential to be as important as the Internet is today. However, that potential can only be realized if building a blockchain (decentralized) application is as easy as building a centralized application.
When we approached Consensys we were outputting Solidity contracts, and we kept getting asked why we weren’t compiling directly to the EVM. The answer was very simple, we wanted to save time. We knew that there were many benefits to compile directly to EVM byte code, but we needed some more time and money to do so. We decided that building the EVM connector was the perfect task to present to Consensys because it fit perfectly with the time and grant size that they were offering.
The Consensys team agreed!
We were off to the races. We set the goal of being able to compile all of our existing example applications directly into EVM byte code and not Solidity while maintaining at least the same gas cost. We knew that rebuilding a working EVM compiler to fit within the Reach workflow in three months' time was a hard enough task we didn’t want to set ourselves up for failure, and we knew we could continue to improve the compiler.
Throughout this process, the Consensys team was a dream to work with. We were worried for a little bit because Consensys went through the restructuring process in the middle of the program, but we didn’t feel any ill effects at all. The biggest bottleneck was a large amount of information about the EVM that was spread throughout the community rather than a single authoritative source. We were able to work through that problem by reading the Solidity compiler source code for some perspective on what is done in practice.
In the end, we were successful! We hit all the milestones we set for ourselves, and we were able to go above and beyond a few of them. We released a standalone Haskell EVM bytecode library that anyone in the community can use for their own projects, and we were able to not only maintain the same gas efficiency but we were able to provide developers with on the low end a 7% and on the high end a 30% gas savings.
Our next goal is to increase the feature set of the Reach Language. Currently, the language is limited to a small subset of the overall potential DApps that can be created. We plan to increase that subset to over 80% by the end of this year, as well as add the ability to compile to layer 2 scaling solutions rather than directly onto Ethereum. This will allow us to be the goto development tool for the entire Ethereum community.
We are super thankful for the grant from Consensys. Without it we would have never compiled directly to the EVM and we would have never discovered the actual efficiency gains we could pass onto the developers. If you would like to learn more please join our community, and check out the links below.
Website: https://reach.sh
Telegram: https://t.me/reach_sh
Source Code:
ReachLang: https://github.com/reach-sh/reach-lang
Haskell-EVM Parser: https://github.com/reach-sh/haskell-evm
Example EVM Program: https://github.com/reach-sh/reach-lang/blob/master/examples/rps/build/rps_while.evm
Consensys Grant Milestones:
Functional Milestone#1 Objective
Represent EVM bytecode in Reach code with the correct serializer
Functional Milestone#1 Key Result
The compilation process can target an abstract representation, rather than the low-level bits.
Functional Milestone#1 Actual Result
We completed this in early January with our EVM.Bytecode Haskell package that is available here:
https://github.com/reach-sh/haskell-evm
Functional Milestone#2 Objective
Extend backend language to support the explicit transaction model
Functional Milestone#2 Key Result
Existing Reach backends assume an object/method model that is not actually present in on the EVM, but is part of the Solidity abstraction.
Functional Milestone#2 Actual Result
This task was not separable from milestone #3, so we combined its discussion below.
Functional Milestone#3 Objective
Compile Reach to EVM bytecode
Functional Milestone#3 Key Result
All existing Reach programs deployable without using Solidity.
Functional Milestone#3 Actual Result
We completed this in early March. You can see an example program here:
https://github.com/reach-sh/reach-lang/blob/master/examples/rps/build/rps_while.evm
The new compiler backend is here:
https://github.com/reach-sh/reach-lang/blob/master/hs/src/Reach/EmitEVM.hs
Aspirational Milestone#1 Objective
Automatic EVM variable spilling to memory
Aspirational Milestone #1 KeyResult
Reach users do not need to stay within stack depth bounds, but without gas costs of storing all variables in memory.
Aspirational Milestone#1 Actual Result
Our compiler produces tighter EVM bytecode than the corresponding Solidity code would. For example, in our main example application, Solidity’s bytecode is 8,160 bytes while ours is 6,874 bytes.
Aspirational Milestone #2 Objective
Gas based-optimizer for variable layout
Aspirational Milestone #2 Key Result
Reduce the gas usage on transactions to a minimum, with a gas-sensitive register allocation policy.
Aspirational Milestone#2 Actual Result
Our new backend produces significantly cheaper bytecode to execute as well. On the low end, the first message of the example protocol costs 23,134 gas when compiled by Solidity, but 21,663 gas when compiled by our backend, a savings of about 7%. On the high end, the second message costs 37,129 in Solidity and 25,785 in Reach, a savings of over 30%.
Aspirational Milestone #3 Objective
Collapse smaller-than-word-size values into words
Aspirational Milestone #3 KeyResult
Reduce the gas usage further by compressing, rather than expanding, sub-word variables.
Aspirational Milestone#3 Actual Result
We did not have time to complete this objective.