Skip to content

contract init should generate a contract that's compatible with fuzzing #1800

Closed

Description

@leighmcculloch

What version are you using?

22.0.1

What did you do?

  1. Create a contract.
    stellar contract init
    
  2. Add fuzzing to the contract.
    cargo fuzz init
    
  3. Edit the fuzz_target_1 to use the contract, by referencing the contract's crate.
  4. Run the fuzzer
    cargo +nightly fuzz run fuzz_target_1
    

What did you expect to see?

The fuzz test run.

What did you see instead?

Errors saying that the contract crate doesn't exist and isn't imported as a dependency. The crate is listed as a dependency, but fails to import because the crate-type is fixed to cdylib only.

Suggested fix

The crate-type should default to ["lib", "cdylib"] so that the crate can be released as a wasm file, as well as be imported into fuzzing tests.

There's some history to why the lib wasn't included. Having multiple crate-type's causes builds for wasms to skip link-time optimizations (LTO), resulting in larger wasm files. We used to avoid that issue by defaulting to, and telling folks, not to use lib in their crate-type. But that was impractical advice, because you need lib in the crate-type to do fuzzing and some other things. Today we recommend using stellar contract build that runs the build with some flags that result in LTO being activated for the wasm build.

Activity

  1. added
    bug
    on Dec 17, 2024
  2. moved this to Backlog (Not Ready) in DevXon Dec 17, 2024
  3. added a commit that references this issue on Dec 20, 2024
    e79aa3c
  4. moved this from Backlog (Not Ready) to Todo (Ready for Dev) in DevXon Jan 10, 2025
  5. github-actions commented on Jan 19, 2025

    @github-actions
    Contributor

    This issue is stale because it has been assigned for 30 days with no activity. It will be closed in 90 days unless the stale label is removed, and the assignee is removed or updated.

  6. moved this from Todo (Ready for Dev) to Done in DevXon Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions