1

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
{"module":"env","export":"malloc"}
thread-0  wasm_interface.hpp:41 resolve

{"mod_name":"env","export_name":"malloc"}
thread-0  wasm_interface.hpp:43 resolve

{"_pending_console_output.str()":""}
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> – TeeAttack42 Jul 4 '18 at 15:33
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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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