Skip to content

feat(contracts): Wasm bytecode size optimization via sub-contract mod…#299

Merged
Solomonsolomonsolomon merged 1 commit intogear5labs:masterfrom
devJaja:feat/wasm-bytecode-size-optimization
Mar 31, 2026
Merged

feat(contracts): Wasm bytecode size optimization via sub-contract mod…#299
Solomonsolomonsolomon merged 1 commit intogear5labs:masterfrom
devJaja:feat/wasm-bytecode-size-optimization

Conversation

@devJaja
Copy link
Copy Markdown
Contributor

@devJaja devJaja commented Mar 30, 2026

feat(contracts): Wasm bytecode size optimization via sub-contract modular architecture

Problem

Soroban enforces a strict Wasm bytecode size limit per contract. The btc_relay contract exceeded this limit due to
its inline Bitcoin cryptographic helpers (double-SHA256, Merkle proof traversal, PoW target decoding).
Additionally, 7 of the 11 contracts were missing from the workspace, making them unbuildable.

Solution

Extracted the heavy crypto logic from btc_relay into a new btc_relay_crypto sub-contract. The relay contract now
delegates all crypto operations via #[contractclient] cross-contract calls, keeping each Wasm binary well within
Soroban's size limit.

Changes

  • contracts/Cargo.toml — added all 7 missing contracts to the workspace (btc_relay, btc_relay_crypto,
    flash_loan_guard, htlc, lending_liquidation, multi_hop_swap, rbac)
  • contracts/btc_relay_crypto/ — new sub-contract housing double_sha256, extract_merkle_root, extract_target,
    hash_meets_target, compute_merkle_root
  • contracts/btc_relay/src/lib.rs — removed inline crypto helpers; added BtcCryptoClient cross-contract interface;
    Config now includes crypto_contract: Address
  • contracts/btc_relay/src/test.rs — updated tests to register the crypto sub-contract and pass its address to
    initialize
  • contracts/btc_relay/Cargo.toml — added btc_relay_crypto as a dev-dependency
  • contracts/relayer_slashing/src/lib.rs — fixed pre-existing moved-value compile error
  • contracts/por_validator/src/lib.rs — fixed pre-existing invalid token::Client::total_supply() call; oracle now
    owns circulating_supply

Deployment note

btc_relay_crypto must be deployed first. Its contract address is then passed as crypto_contract when initializing
btc_relay.

Testing

cargo check --workspace passes clean across all 13 contracts.

Closes: #270

…ular architecture

- Extract heavy Bitcoin crypto helpers (double_sha256, merkle proof, PoW
  target decoding) from btc_relay into a new btc_relay_crypto sub-contract
- btc_relay now delegates all crypto ops via BtcCryptoClient cross-contract
  calls, keeping each Wasm binary within Soroban's size limit
- Add crypto_contract: Address to btc_relay Config; update initialize sig
- Register all 7 previously missing contracts in workspace Cargo.toml
- Fix pre-existing moved-value compile error in relayer_slashing
- Fix pre-existing invalid token::Client::total_supply() call in por_validator

Deployment: deploy btc_relay_crypto first, pass its address as crypto_contract
when initializing btc_relay.
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

@devJaja Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Solomonsolomonsolomon Solomonsolomonsolomon merged commit 5c57b54 into gear5labs:master Mar 31, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Contract] Wasm Bytecode Size Optimization for Large Logic

2 participants