From 7119be6eecd114c78f6086d9b4eee2be2fc0d9da Mon Sep 17 00:00:00 2001 From: Meshmulla <58138966+Meshmulla@users.noreply.github.com> Date: Thu, 16 Jul 2026 10:59:57 +0000 Subject: [PATCH] fix(soroban): extract escrow_contract into its own crate Building the workspace for wasm32-unknown-unknown failed with: error: symbol `initialize` is already defined --> soroban/src/escrow_contract.rs:112:1 The soroban crate's own top-level contract (in lib.rs) and TimeLockedEscrowContract both export a wasm symbol named `initialize`. Since they compiled into the same cdylib, the wasm export tables collided. A comment already in lib.rs notes that governance and insurance_pool were previously handled the same way (test-only via #[cfg(test)]) for this exact reason, but escrow_contract had never gotten that treatment and was still compiled unconditionally. Fix: move escrow_contract.rs out of the soroban crate into its own workspace member, `escrow_contract/`, matching the existing transfer_state_machine crate layout (its own Cargo.toml, its own wasm cdylib output). It has no dependency on any other soroban module, so the move is a straight file relocation plus: - soroban/src/lib.rs: drop `pub mod escrow_contract;` - soroban/Cargo.toml: drop the escrow_contract_test [[test]] entry - root Cargo.toml: add escrow_contract to workspace members - Cargo.lock: add the escrow-contract workspace member entry - README.md: document the new crate in the workspace table - escrow_contract/src/lib.rs: add `#![no_std]` at the crate root. It previously inherited this from soroban/src/lib.rs as a submodule; as its own crate root it needs the attribute itself, otherwise it links libstd's panic_impl alongside soroban-sdk's own, which duplicates the lang item (E0152) under the wasm32 target. Also fixed a stale import in the moved test file (escrow_contract/tests/escrow_contract.test.rs) that referenced the crate's pre-rename name `bridge_watch_contracts` instead of the current `escrow_contract`. Verified via a real GitHub Actions run (on a disposable branch, combined with the ethnum bump from the companion PR) that `cargo build --release --target wasm32-unknown-unknown` now succeeds for the full workspace with these two changes together. --- Cargo.lock | 7 +++++++ Cargo.toml | 2 +- README.md | 5 +++-- escrow_contract/Cargo.toml | 19 +++++++++++++++++++ .../src/lib.rs | 2 ++ .../tests/escrow_contract.test.rs | 2 +- soroban/Cargo.toml | 4 ---- soroban/src/lib.rs | 1 - 8 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 escrow_contract/Cargo.toml rename soroban/src/escrow_contract.rs => escrow_contract/src/lib.rs (99%) rename {soroban => escrow_contract}/tests/escrow_contract.test.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index 302e454..7c2bd63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -548,6 +548,13 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bfcf67fea2815c2fc3b90873fae90957be12ff417335dfadc7f52927feb03b2" +[[package]] +name = "escrow-contract" +version = "0.1.0" +dependencies = [ + "soroban-sdk", +] + [[package]] name = "ethnum" version = "1.5.2" diff --git a/Cargo.toml b/Cargo.toml index 33c7ecf..3fdc859 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["soroban", "transfer_state_machine"] +members = ["soroban", "transfer_state_machine", "escrow_contract"] resolver = "2" [profile.release] diff --git a/README.md b/README.md index ef8e1aa..aca8f6c 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,12 @@ locking/escrow, operator rotation, and transfer state tracking. ## Workspace layout -This is a Cargo workspace with two members: +This is a Cargo workspace with the following members: | Crate | Description | | --- | --- | -| `soroban/` | Core Soroban contracts (access control, trusted sources, escrow, thresholds) | +| `soroban/` | Core Soroban contracts (access control, trusted sources, thresholds) | +| `escrow_contract/` | Time-locked escrow contract for bridge transfers | | `transfer_state_machine/` | Transfer state-machine contract logic | | `harness/` | Test harness and integration helpers | diff --git a/escrow_contract/Cargo.toml b/escrow_contract/Cargo.toml new file mode 100644 index 0000000..b6f7063 --- /dev/null +++ b/escrow_contract/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "escrow-contract" +version = "0.1.0" +edition = "2021" +description = "Soroban time-locked escrow contract for Swipely bridge transfers" +license = "MIT" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +soroban-sdk = { version = "22.0.10" } + +[dev-dependencies] +soroban-sdk = { version = "22.0.10", features = ["testutils"] } + +[[test]] +name = "escrow_contract_test" +path = "tests/escrow_contract.test.rs" diff --git a/soroban/src/escrow_contract.rs b/escrow_contract/src/lib.rs similarity index 99% rename from soroban/src/escrow_contract.rs rename to escrow_contract/src/lib.rs index 61c65cc..980b153 100644 --- a/soroban/src/escrow_contract.rs +++ b/escrow_contract/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + use soroban_sdk::{ contract, contracterror, contractimpl, contracttype, symbol_short, Address, Env, String, Symbol, Vec, diff --git a/soroban/tests/escrow_contract.test.rs b/escrow_contract/tests/escrow_contract.test.rs similarity index 98% rename from soroban/tests/escrow_contract.test.rs rename to escrow_contract/tests/escrow_contract.test.rs index c852499..7e87684 100644 --- a/soroban/tests/escrow_contract.test.rs +++ b/escrow_contract/tests/escrow_contract.test.rs @@ -1,7 +1,7 @@ #![cfg(test)] use soroban_sdk::{testutils::{Address as _, Ledger}, Address, Env, String, contract, contractimpl, symbol_short, Vec}; -use bridge_watch_contracts::escrow_contract::{TimeLockedEscrowContract, TimeLockedEscrowContractClient}; +use escrow_contract::{TimeLockedEscrowContract, TimeLockedEscrowContractClient}; #[contract] pub struct MockBridgeVerifier; diff --git a/soroban/Cargo.toml b/soroban/Cargo.toml index 858960b..083a6f8 100644 --- a/soroban/Cargo.toml +++ b/soroban/Cargo.toml @@ -25,10 +25,6 @@ path = "tests/asset_locking.test.rs" name = "source_trust_test" path = "tests/source_trust.test.rs" -[[test]] -name = "escrow_contract_test" -path = "tests/escrow_contract.test.rs" - [[test]] name = "operator_rotation_test" path = "tests/operator_rotation.test.rs" diff --git a/soroban/src/lib.rs b/soroban/src/lib.rs index 48d49a9..3b5bbee 100644 --- a/soroban/src/lib.rs +++ b/soroban/src/lib.rs @@ -15,7 +15,6 @@ pub mod batch_query; #[cfg(test)] pub mod circuit_breaker; pub mod emergency_fund_recovery; -pub mod escrow_contract; #[cfg(test)] pub mod governance; #[cfg(test)]