Running WASM in WASM #173
Replies: 11 comments 16 replies
-
I don't quite understand the rationale behind this. If you want to call another wasm contract, why couldn't you deploy the wasm to another account and use a regular cross contract call? If you want to simply execute some function, you can just write it as part of the contract? Did I miss something here? |
Beta Was this translation helpful? Give feedback.
-
Executing another contract in cross contract call are:
- async, meaning you have no guarantee when they will execute
- failure will not rollback
- there is no guarantee / control on the caller what will happen to callee
The idea to allow permissionless innovation.
For example https://github.com/ref-finance allows to customize pools. But
every time will require to commit into the same codebase and deploy via
upgrade the contract. This is not going to be permissoinless at all.
…On Fri, Mar 12, 2021 at 9:22 AM Bowen Wang ***@***.***> wrote:
I don't quite understand the rationale behind this. If you want to call
another wasm contract, why couldn't you deploy the wasm to another account
and use a regular cross contract call? If you want to simply execute some
function, you can just write it as part of the contract? Did I miss
something here?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#173 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABK27RRXVFFMLXM5BBMPH3TDI5TZANCNFSM4ZB2H7HQ>
.
--
Best regards,
Illia Polosukhin
|
Beta Was this translation helpful? Give feedback.
-
As described in the proposal above, there are two different permissions
models that can be done.
…On Mon, Mar 15, 2021 at 8:38 AM Bowen Wang ***@***.***> wrote:
I see. But if you want to allow it to be done permissionlessly, that seems
quite dangerous -- what prevents someone calling this function and change
the underlying contract? Or is there some limit as to what this injected
wasm code can do?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#173 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABK27VAF64AQF2FZ2SOVA3TDYSVRANCNFSM4ZB2H7HQ>
.
--
Best regards,
Illia Polosukhin
|
Beta Was this translation helpful? Give feedback.
-
I think this is an interesting idea overall. Some questions/comments:
|
Beta Was this translation helpful? Give feedback.
-
This a nice trick with many caveats:
Given limited development resources, I would rather prefer us to focus on developing good async DevX, and then circle back to this idea once we have async DevX figured out. |
Beta Was this translation helpful? Give feedback.
-
Seems like @ilblackdragon suggests adding dynamic codegeneration facility to the blockchain. It looks really tempting, however has its own caveats. Most important ones as performance consideration, especially if we'll implement full contract compilation on deployment, and security, as an innocently looking contract can exploit potential WASM vulnerability. fn call_inplace(contract_id: u64, method_key: u64, method_ptr: u64, arg_register_id: u64, result_register_id: u64); |
Beta Was this translation helpful? Give feedback.
-
Why not focus on deploying L2 solution like rollups for EVM or NEAR runtime? Optimistic or ZK? Then you get the off-chain computation boost and lower the fees. Within these rollup chains calls would be sync no? |
Beta Was this translation helpful? Give feedback.
-
It looks like we are talking about two problems:
The first one is a fundamental problem -- developers cannot avoid dealing with synchronization primitives like Mutex/Lock if they want to benefit from parallel processing, even outside the blockchain world. And unfortunately, we cannot abstract it away with the runtime since dealing with deadlocks, livelocks, and race conditions is done on a business-logic level. The second problem does not necessarily require a Wasm-in-Wasm solution. If we are talking about a simple example when an exchange contract wants to have a code of the pool deployed separately with a limited access to the storage, then it can be done through a cross-contract call mechanism with pool living in a separate code. We can provide a convenience macros/wrapper for it that deals with the Mutex. It is very similar to https://github.com/OpenZeppelin/openzeppelin-contracts -- developers are saved from common contract development mistakes by having some convenience classes written for them. For more complex scenarios, we cannot avoid needing to educate engineers on elements of safe concurrent programming. Most of the DeFi developers have their code interact with the contracts that they cannot escape dealing with async code anyway, and have to educate themselves on concurrency. There are also issues with the specific proposed solution, as I said before this will make optimization more complex (we cannot do IO pipelining, we now don't know how much RAM to allocate per shard because of varying number of Wasmer instances executing simultaneously, etc). This is also add new scheme for communicating between the contracts, which will make both runtime and all dev-tools more complex. I suggest the following solution instead:
|
Beta Was this translation helpful? Give feedback.
-
@ilblackdragon this is very interesting. I agree that this gives app developers more flexibility when it comes to deploying their applications. At the same time, I worry that now there are more ways for the deployment/management of the smart contract to go wrong. Do we actually see demand/good use cases for this feature? |
Beta Was this translation helpful? Give feedback.
-
Yes, for example ref finance right now need to update the whole contract
even if just want to add a new kind of a pool.
There are more complex contracts which require many separate contracts
which would be useful to separate both for development, testing and
upgradability, also allowing to customize with other versions. But
currently it will be required to deploy it as one contract as the
synchronicity required between these contracts.
…On Tue, Dec 14, 2021 at 4:52 AM Bowen Wang ***@***.***> wrote:
Container that just allows to componentize the deployment of a single app
instead of using a single WASM.
@ilblackdragon <https://github.com/ilblackdragon> this is very
interesting. I agree that this gives app developers more flexibility when
it comes to deploying their applications. At the same time, I worry that
now there are more ways for the deployment/management of the smart contract
to go wrong. Do we actually see demand/good use cases for this feature?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#173 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABK27RKZDKDDHMFXSNTLMLUQ2WNVANCNFSM4ZB2H7HQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
Best regards,
Illia Polosukhin
|
Beta Was this translation helpful? Give feedback.
-
@ilblackdragon @bowenwang1996 For example, can I containerize the contract I deployed and the ref finance contract so that they are processed internally synchronously? |
Beta Was this translation helpful? Give feedback.
-
Context
Given async nature of NEAR Native contracts, some types of permission-less innovation are hard to build. We are seeing more and more people learning how to build them, but aiding developer in easier development is always goal of NEAR Protocol.
Examples span from splitting a complex system into a number of contracts or reusing existing contract code - right now usually would mean to build it into a single WASM contract. Similarly if there is a complex interaction between contracts, it will require a complex handling of edge cases.
Allowing to build subsets of contracts in an environment that is synchronous would make a drastic improvement to Native developer experience. This can be done by grouping a number of logical contracts into a NEAR contract.
Logically each NEAR contract is a shard. They then get grouped into physical shards. Meaning each NEAR contract potentially can run up to single shard of capacity.
The most prominent example is Aurora - an EVM contract that runs a separate shard. Inside it contains a number of other executable contracts and sub-states that this contract knows how to interpret.
The con of this idea, is that these subsets would be limited to performance of a single shard. Also this would add an extra trade off that developers need to decide on -- deploy inside an existing container, new container or direct contract. Potentially some containers will have their own ecosystem like Aurora does.
WASM in WASM proposal
The proposal is to allow to create WASM containers similar to EVM container that Aurora is doing. These containers would provide synchronous execution between contracts that are deployed inside it.
There can be different implementations of the containers designed for different use cases.
Here are few examples:
Given variety of potential use case, proposal is to create very limited change to the runtime and SDK and allow developers of a container to decide on the specific implementation.
Extra benefit, that such container can implement relayer model, similar to one that Aurora using, allowing users to interact with container and pay no fees or pay fees in other currencies.
Potential implementation
The way it can be implemented is by adding next host function:
There are two options how to permission / configure this:
call_parent
method to access data from caller's contract (pretty much making the native contract as a "host" of subsequent contracts). This allows to implement on demand the previous version.Beta Was this translation helpful? Give feedback.
All reactions