CodeRejected: module imports a non-existent function
Problem: -
Error while deploying contracts that contains methods that deletes storage states. That includes operation like Mapping.delete() that call env().clearContractStroage().
Temporary Fix: -
Commented out the new seal_clear_storage from __unstable__.ts, that overshadows the old seal_clear_storage from seal0.ts
https://github.com/ask-lang/ask/blob/a1bd060593b247bc0e2a9d0b5bc88f95ec3fdfa1/as-packages/as-contract-runtime/assembly/unstable.ts#L34-L35
Substrate Contracts Node Log
v0.22
DEBUG tokio-runtime-worker runtime::contracts: CodeRejected: module imports a non-existent function
v0.23
DEBUG tokio-runtime-worker runtime::contracts: failed to instantiate code: cannot find definition for import __unstable__::seal_clear_storage: Func(DedupFuncType(GuardedEntity { guard_idx: EngineIdx(2), entity_idx: DedupFuncTypeIdx(0) }))
Steps to reproduce: -
Build and deploy any contract that has delete() method. Below is the minimal reproduction contract.
import { HashKeccak256, AccountId, Mapping } from "ask-lang";
@contract()
export class Contract {
_map: Mapping<AccountId, u32, HashKeccak256> = new Mapping();
@constructor()
default(): void {}
@message({ mutates: true })
remove(k: AccountId): void {
return this._map.delete(k);
}
}
Notes (Not related to this issue) :-
Cannot deploy any contract build with ark-lang v0.4.0 on latest substrate-contracts-node v0.23.
Always fails with below error.
DEBUG tokio-runtime-worker runtime::contracts: failed to instantiate code: found an unexpected start function with index 58
Maybe related to paritytech/substrate#207
found an unexpected start function with index 58 this error means that wasm code exported a start function which is illegal in contract
@yjhmelody did you get a chance to take a look at the fix (or the one suggested in this issue ).
@yjhmelody
Just wanted to bump this since this is a critical bug. The ask! v0.4.0 cannot be used with new pallet-contracts (polkadot-v0.9.32 or higher) due to: -
- ~~old host functions in
__unstable__that are stabilized in newpallet-contractsversions~~ , fixed in https://github.com/ask-lang/ask/pull/268 - AS always export
startfunction (for init stdlib) which is now illegal in contracts (new AS supports--exportStart <some-init-name>which can be used to export start function as eitherdeploy()orcall(). Not sure how will that work)
I believe it should be top priority as without fixing this ask! is essentially broken for all major parachains.
Ok, will be updated
AS always export start function (for init stdlib) which is now illegal in contracts (new AS supports --exportStart
which can be used to export start function as either deploy() or call(). Not sure how will that work)
That's not true. You should config it such as:
{
"targets": {
"debug": {
"sourceMap": true,
"debug": true
},
"release": {
"sourceMap": false,
"optimizeLevel": 3,
"shrinkLevel": 2,
"converge": false,
"noAssert": false
}
},
"options": {
"transform": ["ask-transform", "as-serde-transform"],
"importMemory": true,
"initialMemory": 2,
"maximumMemory": 16,
"noExportMemory": true,
"runtime": "stub",
"use": "abort=",
"disable": ["Sign-extension"]
}
}
or inherent this config:
"extends": "ask-lang/asconfig.json",
I did not see start function when I did the above.
Oh, I misunderstood, indeed, I need to study further
Related issues about start functions:
- https://github.com/AssemblyScript/assemblyscript/issues/2672
- https://github.com/paritytech/polkadot-sdk/issues/116