-
Notifications
You must be signed in to change notification settings - Fork 17
Why not EVM OPCODE to RISC-V recompiler? #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for your kind words and interest in the project. As for
I think writing a EVM interpreter contract in Rust, compiled to RISC-V (which EVM contracts might be able to delegate call into) should achieve the same while being the much more efficient solution. This way you can support all EVM instructions. Once the PVM JIT compiler becomes available, such a interpreter contract would also run near native speed. Unless the EVM being written in EVM itself is somehow a hard requirement for you? |
Totally agree write a EVM interpreter in Rust is faster, but it cannot run inside other EVM compatible blockchain's. But the question wasn't about this specific contract, but about the ones which use low-level EVM or verbatim in general, wondering if it is in the scope of revive. Even if it doesn't use verbatim at all, this is how I deploy this interpreter in Solidity/Yul: The |
Our current stance is that we only support YUL as long as we can get away with it. Only supporting EVM and not YUL is not really viable because we rely on it to make contract instantiation work. Yes, we are aware that are some things that would require an EVM frontend. But thats more like anecdotal evidence. We would need some data or market research to justify adding this huge chunk of complexity. So short answer: We don't know. |
Yeah that's exactly my question, what is the scope of revive, if the goal is to enable all existing Solidity code to run on PolkaVm, then I don't see how this is possible without support low-level evm opcodes, many projects rely on low-evm code, including Open-Zeppelin and a few ethereum standards. EIP-1014 - Skinny CREATE2Needs the EVM binary to compute the contract address. EIP-1167 - Minimal Proxy Standard
EIP-3448 - MetaProxy StandardI understand how challenging is porting a Stack Machine like EVM to a Register Machine like RISC-V, I'm thinking about propose an EVM Interpreter optimized to run on RISC-V, once the existing EVM stack used by many parachains (Astar, Moonbean, Acala, etc..) seems abandoned and unmaintained:
|
This is not the goal. Because even with an EVM frontend we couldn't enable all existing code to run. Super low level stuff will never work because of our differences in bytecode and contract instantiation. |
@Lohann may add, I see your usecase and justification. However note that EVM compatibility is solved in our ecosystem already. I think you could as well deploy to moonbeam and bridge into AssetHub for whatever your needs are? |
I don't think is solved, I worked building bridges between many networks inside and outside polkadot ecosystem, for some I had to use a specific language/tools, such as ink! for parachains, cosmwasm for cosmos, bpf for Solana, PyTeal for Algorand, etc.. But the most widely supported is EVM, and frontier-based chains are the most incompatible and painful to get working, is the only one which forced me to add Custom Solidity Code to get the same contract working on all EVM Chains, the rpc-api is inconsistent, the opcodes doesn't behave the same, the block-hash stored doesn't match the block returned by the API, I opened a PR trying to fix it which was never reviewed, etc.. When I saw Revive, I thought it would replace frontier, but now I understood it was never the goal. |
The use case is having the same Solidity code that works on Ethereum, Polygon, Near, Avalanche, (any other EVM compatible blockchain actually), working on substrate. BridgesHub/AssetHub only works for Polkadot consensus, it cannot connect Polkadot to Avalanche for example. |
The goal is that this is true for 99% of contracts. Exceptions apply. We are compatible where we can and take it very seriously. However, there are cases where we simply can't be compatible. I am not ruling out an EVM frontend if it turns out we need it because a substantial amount of contracts is written in assembly. But for the time being it looks like niche use cases. The OpenZeppelin contract you posted seems to use just YUL. |
Yes, is a YUL code that manipulates EVM bytecode for deploying a EIP-1167 Minimal Proxy. Usually every time solidity code uses |
I see. Yeah this will not work. But it won't be fixed by an EVM frontend, either. This is because on-chain it will be all PolkaVM. The transformation EVM -> PolkaVM is done offline. |
yep, that's why I think an EVM interpreter is unavoidable if the goal is being 99.99% EVM compatible and support all features up to |
Agreed. But why are you posting that on a repo on a recompiler to RISC-V? Like what is your point? |
I believe is possible to convert I believe the reasonw why YUL was choosen over EVM is because YUL doesn't allow arbitrary JUMPS and can be easily converted to LLVM-IR, and also because assign a stack to a register isn't possible in
Also all valid destinations must be tagged with EVM only allows OPCODES to access the 16 elements in the top of the stack, coincidentally is the number of registers supported by |
I assume you meant O(n) here. Oh we are back to baseline compilers now? I am glad we closed that chapter a long time ago when we moved away from Wasm. Even in O(n) the compilation will be slow and a tradeoff between compile and execution time. Might just stick to an EVM interpeter. The whole point of PolkaVM is to not make this tradeoff. I swear to god if you say "caching" now I will close this thread. |
I wasn't aware about this chapter, actually we can close this thread because all my questions were answered, thank you @athei and @xermicus, now I have a better idea of what is the scope, goals and non-goals of revive.
I'm interested on improve the compatibility between Substrate and EVM, because I believe compatibility is more important than performance, once if my goal is implement the most efficient contract possible, I would choose ink! + Rust instead of using ink! + Solidity which is impossible to generate efficient code because YUL/Solidity assumes 256bit word size. |
First thank you for all the hard work on this awesome project.
I have a few questions, this project aims to recompile YUL to RISC-V, but without low level OPCODE support it also means not all YUL features like verbatim can be supported.
I also wrote a few smart-contracts in pure EVM assembly, that would be impossible to be written efficiently in YUL or solidity:
I understand if this may not be in the scope of this project to support those contracts, should be a separated project? if it is in the scope of this project I would like to contribute to it.
The text was updated successfully, but these errors were encountered: