3
    #[ink(storage)]
    pub struct Variables {
        a: u128,
        b: u128,
        multiplier: u128
    }

    impl Variables {

        #[ink(constructor)]
        pub fn new(a: u128, b: u128) -> Self {
            Variables {
                a: a,
                b: b,
                multiplier: 1_000_000_000_000
            }
        }

        #[ink(constructor)]
        pub fn default() -> Self {
            Variables {
                a: Default::default(),
                b: Default::default(),
                multiplier: 1_000_000_000_000
            }
        }

        #[ink(message)]
        pub fn initializer(&mut self, a: u128, b: u128) -> bool{
            self.a = a;
            self.b = b;
            true
        }

        #[ink(message)]
        pub fn div(&self) -> u128 {
            (self.a*self.multiplier/self.b) as u128
        }
    }
}

when I try to build above contract i'm getting this error - ERROR: Validation of the Wasm failed.

ERROR: An unexpected panic function import was found in the contract Wasm.
This typically goes back to a known bug in the Rust compiler:
https://github.com/rust-lang/rust/issues/78744

As a workaround try to insert overflow-checks = false into your Cargo.toml. This will disable safe math operations, but unfortunately we are currently not aware of a better workaround until the bug in the compiler is fixed.

ERROR: An unexpected import function was found in the contract Wasm: _ZN4core9panicking5panic17h8d2687444d110f05E.
Import funtions must either be prefixed with 'memory', or part of a module prefixed with 'seal'

Ignore with --skip-wasm-validation

1 Answer 1

3

You should add these lines to your Cargo.toml file (as suggested)

[profile.dev]
overflow-checks = false

Note that it is not needed in ink! if you build with --release flag

1
  • How does building with the --release flag fix this? It fixed it.
    – Snowmead
    Jun 23, 2023 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.