Skip to content

CodeRejected: module imports a non-existent function #243

Open

Description

@ashutoshvarma

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

Activity

  1. yjhmelody commented on Jan 30, 2023

    @yjhmelody
    Contributor

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

  2. ashutoshvarma commented on Feb 7, 2023

    @ashutoshvarma
    ContributorAuthor

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

  3. ashutoshvarma commented on Mar 2, 2023

    @ashutoshvarma
    ContributorAuthor

    @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.

  4. yjhmelody commented on Mar 6, 2023

    @yjhmelody
    Contributor

    Ok, will be updated

  5. yjhmelody commented on Mar 6, 2023

    @yjhmelody
    Contributor

    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.

  6. yjhmelody commented on Mar 6, 2023

    @yjhmelody
    Contributor

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

  7. yjhmelody commented on Mar 16, 2023

    @yjhmelody
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions