I'm trying to compile smart contracts written in Rust. So far so good, but when I tried to add memory management contract deployment choked.

(type (;0;) (func (param i32) (result i32)))
(import "env" "malloc" (func $malloc (type 0)))

This line in webassembly makes contract deployment fail with message

2663336ms thread-0   http_plugin.cpp:406 handle_exception] Exception Details: 10 assert_exception: Assert Exception
!"unresolvable": env.malloc
thread-0  wasm_interface.hpp:41 resolve

thread-0  wasm_interface.hpp:43 resolve

thread-0  apply_context.cpp:62 exec_one

Although this method is listed in c function reference https://developers.eos.io/eosio-cpp/reference#memory

Other methods like printi and action_data_size works fine. So my question is how do I work with memory in smart contracts and how do I know which foreign functions are in "env" module and which are not?

  • I am not a rust expert, but did you include the memory library from eosio? In C++ you would have to use #include <eosiolib/memory.hpp>
    – tmm
    Commented Jul 4, 2018 at 15:33

1 Answer 1


Answering my own question:

The problem is that part of C API is external to webassembly (like printui, etc) - so these are imported. However memory management is a thing that is compiled to wasm - so malloc and other stuff will appear in your wasm contract code. That's why you don't need to count on EOS functions on that, but rather use your own memory allocator

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.