-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Support for offchain
keyword
#12610
Comments
That's an interesting idea. Very similar to how for example in C/C++ you have the Unfortunately I don't think it would work out in practice. This would need support from blockchain clients and the flow would probably be something like this:
The problem is that the fact that your checks passed in the initial execution does not mean they would pass on-chain too. Unless all your offchain logic is Also, some general remarks:
|
you understand the flow perfectly. and yes, as I mentioned the
and lastly regarding your last remark: the whole point is gas saving, the one-time payment of few extra weis for the extra code is completely negligible compared to the overall gas savings. and what you suggest with extending the ABI would actually require clients support. considering the code-block will indeed have no side effects, I can't see any other drawbacks for this syntax. although I am open to be enlightened and learn otherwise :) edit: I have to admit I did not check a single client's given |
What I meant is that you need support from clients to execute it. Otherwise it's just a piece of dead code that's useless without client-side support.
I mean, this was more of an argument against executing it off-chain at all. A |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
Abstract
A lot of expensive sanity checks can be performed off-chain. I propose a new solidity keyword with simple, familiar syntax and fully compatible with current EVM opcodes.
Motivation
Gas costs increase significantly with complexity. Moreover, a lot of information present on-chain can be fetched off-chain, saving significant gas for storage access.
Specification
Similarly to the
unchecked
keyword, I propose a syntax foroffchain
blocks:To avoid contradictions between off-chain & on-chain logic, the block must behave like view-only or pure functions, such that it cannot affect the flow of execution aside from reverting.
Which is equivalent to:
if (isOffChain) { ... }
isOffChain can be repurpose
block.coinbase
, since it is unknown during offchain execution anyway. So now the above code can be translated to:if (block.coinbase == OFFCHAIN_MAGIC) { ... }
Note
COINBASE
opcode costs only 2 gas. I suggest OFFCHAIN_MAGIC to beuint256(0)
. this way the new keyword can be implemented with just 4 opcodes overhead:The extra cost will be 2 + 3 + 10 + 1 = 16 gas, while potentially saving significantly larger amounts. Moreover, the cost of the off-chain block can be calculated and if it is smaller than 16, the
offchain
keyword can be optimized out.Caveats
Users of the
offchain
keyword need to be careful not to introduce security holes. Here is a safe and an unsafe example:safe:
unsafe:
Backwards Compatibility
Since no new EVM opcodes were introduced, it is compatible with existing EVM chains.
Nothing breaks on the compiler side, and additionally the
offchain
keyword can be ignored with a warning for older solidity versions, with the side effect of producing more expensive bytecode.The text was updated successfully, but these errors were encountered: