-
Notifications
You must be signed in to change notification settings - Fork 576
adr: draft ADR for stateful precompiled contracts #1131
Conversation
This is awesome! But collides a bit with the designed proposed in #1272 with a more modular proposition. We should try to decide towards one model and work together towards that model. If we agree the other proposal is the way to go we could either close this or adapt it to meet the modular design. Open for discussion 🙏 |
I think the difference is mainly stateful vs stateless, we can rework this one after the stateless part is done. |
This draft ADR is similar to the work I did back in February 2022: go-ethereumloredanacirstea/go-ethereum@abd62c3
Changes 1 and 2 were mostly isolated in loredanacirstea/go-ethereum@abd62c3.
ethermintThen, ethermint could just use the But I think @fedekunze's approach is superior because it does not require go-ethereum changes. So, we don't need to expend effort in supporting a geth fork or in convincing the geth team to change their source. |
Yeah, It's directly inspired by your work, the main development is to make stateful precompiles work with statedb snapshot and revert. |
@yihuang We should define what stateless and stateful precompiles are. Because I see several categories:
|
Hmm, what I mean here is the contract modifies the global state, specifically, modifies the cosmos-sdk states, like bank transfers, or sending ibc packets. |
@yihuang @loredanacirstea. All of the above makes sense, I've been doing some research into getting state changing precompile working and ultimately am realizing that the StateDB is the problem. IMO we need to find a way to make it so that an EVM txn reverting reverts the Cosmos txn as well. The design decision to make a reverting EVM transaction a successful cosmos transaction is a huge antipattern in my opinion, and is the root of the StateDB commit() revert() issue. |
This ADR proposed a solution to this problem, with examples. |
@yihuang correct. But the issue is that we can't call arbitrary module logic, in the way that we can pass CosmosMsg's from CosmWasm VM to the module directly. Going this route, would required duplicating logic that is possibly already defined in it's keeper. |
yes, we have to carefully manage temporary states in memory. |
Seems like bad developer UX, there has to be a way to get it to work like how CosmWasm works. That should be the end goal for Stateful Precompiles IMO. |
Having an EthTx revert, revert the whole Cosmos Txn would resolve this issue, no? |
I think |
The exception revert can happen in nested way. |
Needless to say, I think the approach should be attempt to get synchronous ability to call Cosmos SDK modules from the evm. Having to duplicate all the logic seems like a massive way to introduce issues. |
@calbera I have two questions,
|
@yihuang personally I'm not against a very mild fork with an extremely small diff. Though I know @fedekunze is quite against. Why would we need nonce? An invariant that is checked post call to ensure nonce hasn't been altered by a native call seems reasonable. |
|
But you'll need to hold the whole stack of cache contexts to be able to commit all the way back to the top level, commit once only commit to the upper layer. |
Thank you for your reply |
I added Cosmos |
@loredanacirstea very similar to the arch @calbera and I are starting to come to, this is awsome. The geth PR is sweet too, one issue we faced when getting this going without a fork was that we ended up having to pull much the evm out into ethermint to shadow. |
@itsdevbear |
If we fix the slowness of nested cache context, we might reconsider the nested cache context solution, which would be perfect for precompiles. |
@loredanacirstea I was thinking that if we customize an opCode, then define the evm in the interpreter as an interface, and then suggest that the etherum team export the interpreter as a public variable, so that the modification may be less and easier for them to accept? Of course, this is my simple idea, there may be something I haven't considered |
I have a full working quasar precompile (cosmos sdk messages & queries from inside the EVM). This means stateful precompiles, solved call context nesting, efficient state sync between EVM StateDB & Cosmos context, gas metering of the mixed context! It is publicly verifiable on the Mythos chain. And demoed here, with more details: https://youtu.be/COu5Olszhtg. If you want to see the example contract used for testing, see min 7:09. |
I'm curious how you do the context nesting and statedb thing. |
Of course. |
Sad to see Ethermint going down this path, but @loredanacirstea I totally understand your rationale, given the state of the project. We recently had to go this route as well and it totally sucks. If you ever want to collaborate on this topic please reach out to either myself or @calbera. Godspeed 🙏 |
@itsdevbear care to elaborate on why you wrote this comment? |
I still only see one way to support precompiles with |
@fedekunze please clarify if this is the official stance of Tharsis, as cited in my comment here https://commonwealth.im/evmos/discussion/8496-bring-quasar-to-evmos-execute-cosmos-transactions-queries-from-the-evm-from-any-smart-contract?comment=41558
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days-before-close if no further activity occurs. |
This PR is not relevant now, @mmsqe is taking a different approach on this issue, based on the cache store refactoring here: cosmos/cosmos-sdk#14444, we can expect an implementation PR directly soon. |
@yihuang thanks for your insightful discussions. |
do you mean wrap existing cache store into a journal entry? the performance is very bad with deeply nested cache store. |
I mean AFAIK the statedb has been refactored to replace nested cachestore with journals, but you seem to imply that we need to go back to the original cachestore approach to support stateful precompiled contracts. I'm not clear about the motivation. Correct me if I'm wrong. |
because native code don't have access to the dirty cache in statedb, for example the current balance of evm denom. |
ref: #1116
Description
Example implementation: https://github.com/yihuang/ethermint/tree/precompiled
IBC example:
For contributor use:
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerFor admin use:
WIP
,R4R
,docs
, etc)