Описание
The rs-soroban-sdk #[contractimpl] macro calls inherent function instead of trait function when names collide
Impact
The #[contractimpl] macro contains a bug in how it wires up function calls.
In Rust, you can define functions on a type in two ways:
- Directly on the type as an inherent function:
impl MyContract { fn value() { ... } }
- Through a trait
impl Trait for MyContract { fn value() { ... } }
These are two separate functions that happen to share the same name. Rust has rules for which one gets called. When you write MyContract::value(), Rust always picks the one defined directly on the type, not the trait version.
The bug is that #[contractimpl] generates code that uses MyContract::value() style calls even when it's processing the trait version. This means if an inherent function is also defined with the same name, the inherent function gets called instead of the trait function.
This means the Wasm-exported entry point silently calls the wrong function when two conditions are met simultaneously:
- A
impl Trait for MyContractblock is defined with one or more functions, with#[contractimpl]applied. - A
impl MyContractblock is defined with one or more identically named functions, without#[contractimpl]applied.
If the trait version contains important security checks, such as verifying the caller is authorized, that the inherent version does not, those checks are bypassed. Anyone interacting with the contract through its public interface will call the wrong function.
For example:
Patches
The problem is patched in soroban-sdk-macros version 25.1.1. The fix changes the generated call from <Type>::func() to <Type as Trait>::func() when processing trait implementations, ensuring Rust resolves to the trait associated function regardless of whether an inherent function with the same name exists.
Users should upgrade to soroban-sdk-macros >= 25.1.1 and recompile their contracts.
Workarounds
If upgrading is not immediately possible, contract developers can avoid the issue by ensuring that no inherent associated function on the contract type shares a name with any function in the trait implementation. Renaming or removing the conflicting inherent function eliminates the ambiguity and causes the macro-generated code to correctly resolve to the trait function.
Ссылки
- https://github.com/stellar/rs-soroban-sdk/security/advisories/GHSA-4chv-4c6w-w254
- https://nvd.nist.gov/vuln/detail/CVE-2026-26267
- https://github.com/stellar/rs-soroban-sdk/pull/1729
- https://github.com/stellar/rs-soroban-sdk/pull/1730
- https://github.com/stellar/rs-soroban-sdk/pull/1731
- https://github.com/stellar/rs-soroban-sdk/commit/e92a3933e5f92dc09da3c740cf6a360d55709a2b
Пакеты
soroban-sdk-macros
>= 25.0.0, <= 25.1.0
25.1.1
soroban-sdk-macros
>= 23.0.0, <= 23.5.1
23.5.2
soroban-sdk-macros
<= 22.0.9
22.0.10
Связанные уязвимости
soroban-sdk is a Rust SDK for Soroban contracts. Prior to versions 22.0.10, 23.5.2, and 25.1.1, the `#[contractimpl]` macro contains a bug in how it wires up function calls. `#[contractimpl]` generates code that uses `MyContract::value()` style calls even when it's processing the trait version. This means if an inherent function is also defined with the same name, the inherent function gets called instead of the trait function. This means the Wasm-exported entry point silently calls the wrong function when two conditions are met simultaneously: First, an `impl Trait for MyContract` block is defined with one or more functions, with `#[contractimpl]` applied. Second, an `impl MyContract` block is defined with one or more identically named functions, without `#[contractimpl]` applied. If the trait version contains important security checks, such as verifying the caller is authorized, that the inherent version does not, those checks are bypassed. Anyone interacting with the contract throug