Include removal of the `_` export from the WASM executable as part of the command to optimize contracts.

Open
#387 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust, wasm
Domain
build-system, cli

Research direction

Start at the soroban optimize command entry point and inspect how the WASM executable's exports and custom section are handled. Confirm which exports represent contract functions and ensure optimization removes the non-contract _ export while preserving the contract exports and required custom section.

Written by the indexing model from the issue text.

Description

What problem does your feature solve?

Originally, this issue was raised in the SDK repo https://github.com/stellar/rs-soroban-sdk/issues/843#issuecomment-1410805103.

I spend my days building a tool that interacts with the WASM binary in the browser, and if I want to display all available contract functions, I have to filter out the _ export. The reason the _ function is exported in the first place is to please the linker and keep the custom section included in the final *.wasm file. However, after the executable is compiled, that function will never be called and it shouldn't exist.

What would you like to see?

To solve this issue downstream, I wrote a simple disassembler that looks for non-contract exports and removes their definitions. I then re-assemble the executable and work with that. This satisfies my use case, however it's probably good to offer this more widely, I.e. running this command would also remove non-contract exports from the bytecode.

soroban optimize
What alternatives are there?

Not sure of the alternatives, but from what I've seen of NEAR executable that my friend showed me, they do not have non-contract function exports.

Dominant language
Rust
Stars
123
Forks
141
Avg merge
2d 21h
Merged PRs (30d)
17

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stellar/stellar-cli

All issues in stellar/stellar-cli

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.