Skip to content
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

CodeRejected: module imports a non-existent function #243

Open
ashutoshvarma opened this issue Jan 27, 2023 · 7 comments
Open

CodeRejected: module imports a non-existent function #243

ashutoshvarma opened this issue Jan 27, 2023 · 7 comments

Comments

@ashutoshvarma
Copy link
Contributor

ashutoshvarma commented Jan 27, 2023

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

@external("__unstable__", "seal_clear_storage")
export declare function seal_clear_storage(keyPtr: Ptr): Size;

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

@yjhmelody
Copy link
Contributor

yjhmelody commented Jan 30, 2023

found an unexpected start function with index 58 this error means that wasm code exported a start function which is illegal in contract

@ashutoshvarma
Copy link
Contributor Author

@yjhmelody did you get a chance to take a look at the fix (or the one suggested in this issue ).

@ashutoshvarma
Copy link
Contributor Author

ashutoshvarma commented Mar 2, 2023

@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 new pallet-contracts versions , fixed in feat: update contract runtime to polkadot-v0.9.39 #268
  • AS always export start function (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 either deploy() or call(). 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.

@yjhmelody
Copy link
Contributor

Ok, will be updated

@yjhmelody
Copy link
Contributor

yjhmelody commented Mar 6, 2023

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.

@yjhmelody
Copy link
Contributor

Oh, I misunderstood, indeed, I need to study further

@yjhmelody
Copy link
Contributor

Related issues about start functions:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants