A blazingly fast compiling & optimization tool for CosmWasm smart contracts.

Overview

cw-optimizoor

alt text

Build Status Latest version Documentation License

A blazingly fast alternative to CosmWasm/rust-optimizer for compiling & optimizing CW smart contracts.

It's primarily meant to speed up local development and testing.

Features:

  • Fast - especially in workspaces with many contracts
  • Uses same optimizations as rust-optimizer by default
  • No dependency on Docker
  • Supports both single- & multi-contract workspaces
  • Written as a cargo subcommand
  • Cross-platform, cross-arch

Installation

# Pre-requisites
$ rustup install 1.69.0
$ rustup target add wasm32-unknown-unknown

$ cargo install cw-optimizoor

You might also need any of the following:

Linux

# Ubuntu
$ sudo apt install -y cmake pkg-config libssl-dev clang

# Fedora
$ sudo dnf install -y cmake openssl-devel clang

macOS

$ xcode-select --install # clang
$ brew install cmake pkg-config

Windows

Usage

$ cargo cw-optimizoor -h

Usage: cargo cw-optimizoor [OPTIONS] [WORKSPACE_PATH]

Arguments:
  [WORKSPACE_PATH]  Path to the workspace dir or Cargo.toml

Options:
  -f, --features <FEATURES>  Space or comma separated list of features to activate
      --all-features         Activate all available features
      --no-default-features  Do not activate the `default` feature
  -h, --help                 Print help information
  -V, --version              Print version information

Example

$ cargo cw-optimizoor              # defaults to the current dir
# cargo cw-optimizoor Cargo.toml   # or this for pointing directly at a Cargo manifest
# cargo cw-optimizoor .            # or this for the current dir

🧐️  Compiling .../monorepo/Cargo.toml
    Finished release [optimized] target(s) in 0.10s
    
🤓  Intermediate checksums:
    ...326a37596ef54377869d8f7caa37cec393333b9808c9ecc75ddadf1357193a50  contract_1.wasm
    ...170190ce817c36aa093263f4689abaffafe363909aea13e48b80c43a39a7cde9  contract_2.wasm
    ...6a718777f28b2e213e3f18f60ffbf62febe563072e8a89b0cfa5359b3e0bed1b  contract_3.wasm
    ...9f9dae24e8a388730b40de3092117cf84476dacfb6ed0112bec53b1b21127333  contract_4.wasm
    ...9255c18758fd0b27de38c8aacd2030167b9d3c1575374d811f89742be8af4f8b  contract_5.wasm
    
🥸  Ahh I'm optimiziing
    ...✅ contract_1 was optimized.
    ...⏭️ contract_2 is unchanged. Skipping.
    ...✅ contract_3 was optimized.
    ...⏭️ contract_4 is unchanged. Skipping.
    ...✅ contract_5 was optimized.
    
🤓  Final checksums:
    ...e11db2d5b9ff3e14deee2a04ee40be0d1f8da96c4a45bc55348ea74ff4a4d4ae  contract_1-aarch64.wasm
    ...0565368394fd2fa1409909f63fe11d09f37a1f777f26bc5ddb65d17c2fc82bb9  contract_2-aarch64.wasm
    ...1364e024dab8cc057d090d8686042d8ab5e41e810b16d464be71a24aedc79ad3  contract_3-aarch64.wasm
    ...4f553da8e620137c194eddfddcaa7baa29239ec723d0b1b2b49d11fe625986e5  contract_4-aarch64.wasm
    ...61ea8988f4275c15785d7496c453a37ae4c3b021d4521120fc5c0d532287f864  contract_5-aarch64.wasm
    
🫡  Done. Saved optimized artifacts to:
   .../monorepo/artifacts
Comments
  • Sometimes creates empty wasm binaries

    Sometimes creates empty wasm binaries

    Awesome project!

    I ran into an issue trying to use it with this workspace: https://github.com/DA0-DA0/dao-contracts

    It produced nearly empty optimized wasm binaries for cw20_stake and cw_core contracts.

    When I tried to use them, I got this error:

    Error calling the VM: Error during static Wasm validation: Wasm contract doesn't have required export: "instantiate". Exports required by VM: ["allocate", "deallocate", "instantiate"].: create wasm contract failed: invalid request
    

    Im wondering if optimizoor is compiling them with the library feature enabled?

    opened by de-husk 6
  • chore: Compile only the package's libraries

    chore: Compile only the package's libraries

    https://github.com/CosmWasm/rust-optimizer/pull/91/files introduces the required --lib argument when optimizing with rust-optimizer/workspace-optimizer. This enables the schema generation to live under src/bin instead of examples/.

    This PR applies the same change to cw-optimizoor

    opened by nicolaslara 4
  • chore(deps): Bump libgit2-sys from 0.14.1+1.5.0 to 0.14.2+1.5.1

    chore(deps): Bump libgit2-sys from 0.14.1+1.5.0 to 0.14.2+1.5.1

    Bumps libgit2-sys from 0.14.1+1.5.0 to 0.14.2+1.5.1.

    Commits
    • a233483 Update to libgit2 1.5.1
    • bce1555 Merge pull request #909 from ehuss/ssh-keys
    • 222fbf3 Bump versions
    • fa41943 Change the certificate_check callback to support passthrough.
    • 84e21aa Add ability to get the SSH host key and its type.
    • e6aa666 Bump git2-curl version. (#861)
    • 46674ce Fix warning about unused_must_use for Box::from_raw (#860)
    • 951dce9 Merge pull request #858 from davidkna/git2150
    • 8871f8e bump libgit2 to 1.5.0
    • 04278a2 Merge pull request #839 from davidkna/libgit2_143
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • chore(deps): Bump tokio from 1.20.1 to 1.20.3

    chore(deps): Bump tokio from 1.20.1 to 1.20.3

    Bumps tokio from 1.20.1 to 1.20.3.

    Release notes

    Sourced from tokio's releases.

    Tokio v1.20.2

    1.20.2 (September 27, 2022)

    This release removes the dependency on the once_cell crate to restore the MSRV of the 1.20.x LTS release. (#5048)

    #5048: tokio-rs/tokio#5048

    Commits
    • ba81945 chore: prepare Tokio 1.20.3 release
    • 763bdc9 ci: run WASI tasks using latest Rust
    • 9f98535 Merge remote-tracking branch 'origin/tokio-1.18.x' into fix-named-pipes-1.20
    • 9241c3e chore: prepare Tokio v1.18.4 release
    • 699573d net: fix named pipes server configuration builder
    • 3d95a46 chore: prepare Tokio v1.20.2 (#5055)
    • 2063d66 Merge 'tokio-1.18.3' into 'tokio-1.20.x' (#5054)
    • 5c76d07 chore: prepare Tokio v1.18.3 (#5051)
    • 05e6614 chore: don't use once_cell for 1.18.x LTS release (#5048)
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Update cargo dependency to 0.65

    Update cargo dependency to 0.65

    workspace-inheritance has been stabilized in cargo 0.65. This change allows cw-optimizoor to compile contracts using workspace inheritance without needing to specify cargo-features = ["workspace-inheritance"] on top of every Cargo.toml

    opened by nicolaslara 1
  • Fails with contract packages that also include binary crates

    Fails with contract packages that also include binary crates

    You can reproduce it by running cw-optimizoor against the head of cw-plus.

    The solution is likely to make sure any invocation of cargo build includes the --lib parameter.

    opened by uint 1
  • chore: Bump deps

    chore: Bump deps

    Bumps openssl from 0.10.45 to 0.10.48.

    Release notes

    Sourced from openssl's releases.

    openssl v0.10.48

    What's Changed

    New Contributors

    Full Changelog: https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.47...openssl-v0.10.48

    openssl v0.10.47

    No release notes provided.

    openssl v0.10.46

    No release notes provided.

    Commits
    • 4ff734f Release openssl v0.10.48 and openssl-sys v0.9.83 (#1855)
    • 5efceaa Merge pull request #1854 from alex/davids-openssl-of-horrors
    • 6ced4f3 Fix race condition with X509Name creation
    • a752805 Document the horror show
    • 78aa9aa Always provide an X509V3Context in X509Extension::new because OpenSSL require...
    • 332311b Resolve an injection vulnerability in EKU creation
    • 482575b Resolve an injection vulnerability in SAN creation
    • 690eeb2 Merge pull request #1852 from smoelius/master
    • e5b6d97 Improve reliability of some tests
    • 319200a Merge pull request #1851 from alex/libressl-versions
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the Security Alerts page.
    dependencies 
    opened by dependabot[bot] 0
  • chore(deps): Bump git2 from 0.16.0 to 0.16.1

    chore(deps): Bump git2 from 0.16.0 to 0.16.1

    Bumps git2 from 0.16.0 to 0.16.1.

    Commits
    • a233483 Update to libgit2 1.5.1
    • bce1555 Merge pull request #909 from ehuss/ssh-keys
    • 222fbf3 Bump versions
    • fa41943 Change the certificate_check callback to support passthrough.
    • 84e21aa Add ability to get the SSH host key and its type.
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • chore: Bump deps

    chore: Bump deps

    Bumps the deps, including cargo to >=0.67.1, which fixes a security vulnerability in cargo.

    https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-46176

    opened by mandrean 0
  • test: Bump cw-plus

    test: Bump cw-plus

    • Bumps the cw-plus submodule used by the e2e tests, so that we test against the current cw-plus
    • Bumps Rust to 1.66
    • Bumps cucumber to a version that plays better with CLion
    • Fix regression in the "user makes a change in " scenario from bumping cargo and/or cw-plus
    opened by mandrean 0
  • It doesn't error when it can't create wasms

    It doesn't error when it can't create wasms

    In case it doesn't have permission to write binaries to directory (created by the docker, for ex.) after finishing it simply prints:

    🤓  Intermediate checksums:
    

    But it didn't create any binaries, so IMO it should throw an error

    opened by Buckram123 0
  • Optimizes the wrong file version?

    Optimizes the wrong file version?

    Still not sure the root of the problem but when optimizing my contract I was getting schemas that were very old (like not even on in my repo old). Problem was solved by using the normal docker optimizer.

    opened by triccs 0
  • Support single contract repos

    Support single contract repos

    @mandrean I found this today and it has already improved my life quality significantly. Thank you 🙏

    But I ran into some issues when trying to compile "single contract repos" since they usually don't contain a contracts folder. Currently when running cargo cw-optimizoor in a single contract repo it results in

    Error: No CW contracts found. Exiting.
    

    To reproduce run:

    cargo generate --git https://github.com/CosmWasm/cw-template.git --name cw-test-project
    cd cw-test-project
    cargo cw-optimizoor
    

    This PR solves this problem by only filtering the workspace members if the workspace is virtual. Does this seem like a reasonable to you?

    opened by pacmanifold 2
  • When contracts import each other, the imported contracts skip the entry points

    When contracts import each other, the imported contracts skip the entry points

    If you compile two contracts A and B where the B one imports the A, then A one will be built both as a contract and as a library.

    As a consequence, the .wasm artifact for the A being built as a contract will be overwritten by the .wasm of A being built as a library. This means that there is no way to obtain A as a contract. This can be seen in the following workspace: https://github.com/osmosis-labs/osmosis/tree/main/x/ibc-hooks.

    I think I know how to fix this, so I'll try to submit a PR when I have time, but leaving the issue here in case someone gets to it before me.

    opened by nicolaslara 0
  • Produces larger binaries than cosmwasm workspace-optimizer

    Produces larger binaries than cosmwasm workspace-optimizer

    I noticed that the cw-optimizoor optimized binaries are a bit larger than the rust workspace-optimizer for the DAO DAO contracts.

    cw-optimizoor:

    $ ls -lh artifacts | grep wasm | awk '{print $5,$9}'
    293K cw20_stake-x86_64.wasm
    295K cw20_staked_balance_voting-x86_64.wasm
    196K cw4_voting-x86_64.wasm
    278K cw721_stake-x86_64.wasm
    161K cw_admin_factory-x86_64.wasm
    404K cw_core-x86_64.wasm
    175K cw_named_groups-x86_64.wasm
    209K cw_names_registry-x86_64.wasm
    219K cw_native_staked_balance_voting-x86_64.wasm
    495K cw_proposal_multiple-x86_64.wasm
    501K cw_proposal_single-x86_64.wasm
    178K cw_token_swap-x86_64.wasm
    244K stake_cw20_external_rewards-x86_64.wasm
    190K stake_cw20_reward_distributor-x86_64.wasm
    

    cosmwasm workspace optimizer:

    $ ls -lh artifacts | grep wasm | awk '{print $5,$9}'
    257K cw20_stake.wasm
    261K cw20_staked_balance_voting.wasm
    193K cw4_voting.wasm
    276K cw721_stake.wasm
    143K cw_admin_factory.wasm
    407K cw_core.wasm
    173K cw_named_groups.wasm
    188K cw_names_registry.wasm
    216K cw_native_staked_balance_voting.wasm
    455K cw_proposal_multiple.wasm
    460K cw_proposal_single.wasm
    171K cw_token_swap.wasm
    226K stake_cw20_external_rewards.wasm
    171K stake_cw20_reward_distributor.wasm
    

    You can see the % difference here: https://github.com/DA0-DA0/dao-contracts/pull/474#issuecomment-1234664958

    I wonder if there is a different optimization flag being used?

    opened by de-husk 2
  • Support activating certain features

    Support activating certain features

    Running cargo build --feature x or cargo build --all-features works well, but trying to specify it on cw-optimizoor:

    ❯ cargo cw-optimizoor -- --all-features
    

    exits with no output and empty artifacts/

    opened by nicolaslara 9
Releases(v0.10.0)
Owner
Sebastian Mandrean
Systems Engineer. Passionate about distributed systems, architecture, infrastructure, Go, Rust, crypto, functional programming, hardware hacking & RE.
Sebastian Mandrean
CosmWasm-Examples is a collection of example contracts and applications built using the CosmWasm framework

CosmWasm-Examples is a collection of example contracts and applications built using the CosmWasm framework. CosmWasm is a secure and efficient smart contract platform designed specifically for the Cosmos ecosystem.

Vitalii Tsyhulov 20 Jun 9, 2023
My code for the terra.academy course on CosmWasm smart contracts

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

Alex Incerti 0 Nov 7, 2021
A gRPC-based scripting library for interacting with CosmWasm smart-contracts.

Cosmos Rust Script Smart contract scripting library to ease CosmWasm smart contract development and deployment. cosm-script is inspired by terra-rust-

null 11 Nov 3, 2022
A simple example demonstrating cross-contract calls in CosmWasm smart contracts

Cross-contract calls This tutorial demonstrates cross-contract calls with CosmWasm v1. Overview An end user calls the reservation contract to register

csli Tools 3 Sep 12, 2022
Minimal Substrate node configured for smart contracts via pallet-contracts.

substrate-contracts-node This repository contains Substrate's node-template configured to include Substrate's pallet-contracts ‒ a smart contract modu

Parity Technologies 73 Dec 30, 2022
CosmWasm/Sylvia counting contract w/ IBC enabled (Cosmos, Rust, CosmWasm, Sylvia)

CosmWasm/Sylvia counting contract w/ IBC enabled (Cosmos, Rust, CosmWasm, Sylvia) This repository contains counting contract created during the study

Alex Cryp 3 Nov 13, 2023
Examples and helpers to build NFT contracts on CosmWasm

CosmWasm NFTS This repo is the official repository to work on all NFT standard and examples in the CosmWasm ecosystem. cw721 and cw721-base were moved

CosmWasm 147 Jan 4, 2023
An example CosmWasm contract for connecting contracts over IBC.

CosmWasm IBC Example This is a simple IBC enabled CosmWasm smart contract. It expects to be deployed on two chains and, when prompted, will send messa

ekez 64 Jun 21, 2023
An automated CLI tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function call efficiency.

Solidity-Gas-Optimizoor An high performance automated CLI tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function

Chia Yong Kang 10 Mar 11, 2024
evm2near compiles Solidity contracts into NEAR WebAssembly contracts.

EVM → NEAR evm2near is a project for compiling EVM bytecode into wasm bytecode, with the particular goal of having that wasm artifact be executable on

Aurora 125 Dec 3, 2022
Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin.

dlctix Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin. This project is part of the Backdrop Build

null 7 Feb 29, 2024
Smart contracts for Ref Finance

Ref Finance Contracts This mono repo contains the source code for the smart contracts of Ref Finance on NEAR. Contracts Contract Reference Description

Ref Finance 92 Dec 7, 2022
Skyward Finance smart-contracts

Build and Init ./build.sh near dev-deploy res/skyward.was export CONTRACT_ID=skyward.testnet near call $CONTRACT_ID new --account_id=$CONTRACT_ID Regi

Skyward Finance 777 Jan 4, 2023
Rust client to Opensea's APIs and Ethereum smart contracts

opensea.rs Rust bindings & CLI to the Opensea API and Contracts CLI Usage Run cargo r -- --help to get the top level help menu: opensea-cli 0.1.0 Choo

Georgios Konstantopoulos 226 Dec 27, 2022
A framework for creating PoC's for Solana Smart Contracts in a painless and intuitive way

Solana PoC Framework DISCLAIMER: any illegal usage of this framework is heavily discouraged. Most projects on Solana offer a more than generous bug bo

Neodyme 165 Dec 18, 2022
Smart contracts powering Spectrum Protocol on Terra

Spectrum Core Contracts This monorepository contains the source code for the core smart contracts implementing Spectrum Protocol on the Terra blockcha

Spectrum Protocol 38 Dec 19, 2022
A template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it.

CosmWasm Starter Pack This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understan

null 1 Mar 7, 2022
Create your personal token with rust smart contracts

Solana Rust Token ?? This application written Rust using Anchor ⚓

Ritesh 6 Nov 22, 2022
This is a node implementation of Thippy, a Substrate parachain for smart contracts

Thippy ‒- A Smart Contracts Parachain This is a node implementation of Thippy, a Substrate parachain for smart contracts. Developing Smart Contracts f

Arthur·Thomas 15 Mar 16, 2022