Coder Social home page Coder Social logo

Comments (1)

mpapierski avatar mpapierski commented on July 19, 2024

It is feasible as it turns out that whatever we were using nightly it’s already in stable. It was a matter of adding feature flags to the contract API to hide #![feature(...)] etc.

The issues though:

Using stable rust by default with #![no_std]as we do currently doesn’t work as alloc_error_handler is required - but alloc_error_handler is a nightly feature. So if you want to write a smart contract with no_std you need a nightly compiler.
Building with stdlib enabled by default increases gas cost and all the test contracts grow in size (approx ~200KB extra for all contracts combined). The overhead is likely from the panic behavior from rust’s runtime compiled into wasm. I.e. overflow checks, stdlib’s panic handler with stack unwinding, etc. We don’t need all that under wasm.
I was able to use stable rust with std enabled on all contracts by disabling most if not all rust’s runtime checks with an extra cargo profile. This is what smart contract devs should use as well and we should update our reference contracts to do this:

[profile.release-smart-contracts]
inherits = "release"
codegen-units = 1
opt-level = "s"
lto = true
debug = false
panic = "abort"
overflow-checks = true

With the above settings, I was able to have stable rust, stdlib enabled, with the same size and same gas cost as the current dev with nightly:

# stable, with default release build flags (initial attempt; bad)
$ wc -c target/wasm32-unknown-unknown/release/*.wasm | grep total
 6099831 total

# stable, stdlib with extra compiler flags
$ wc -c target/wasm32-unknown-unknown/release/*.wasm | grep total
 4800659 total

# dev, nightly, the baseline
$ wc -c target/wasm32-unknown-unknown/release/*.wasm | grep total
 4800659 total

What’s left are the feature flags we want to add to the contract API crate. In my experiment, I added the std feature always enabled, nightly flag, and the wee_alloc flag in my experiment. By default, std is on and it also enables wee_alloc. For convenience, I have a no_std flag that enables a nightly flag (as raised above it’s for #![feature(...) and alloc_error_handler).

from casper-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.