Skip to content

chore: Enhance error handling for staking operations in LiquidStaking#4811

Open
sergei-boiko-trustwallet wants to merge 4 commits into
masterfrom
chore/enhance-liquid-staking-error
Open

chore: Enhance error handling for staking operations in LiquidStaking#4811
sergei-boiko-trustwallet wants to merge 4 commits into
masterfrom
chore/enhance-liquid-staking-error

Conversation

@sergei-boiko-trustwallet

Copy link
Copy Markdown
Contributor

This pull request enhances error handling and robustness in the liquid staking module by updating internal handler functions to return detailed error information, and propagating these errors to the output when operations are not supported. Additionally, a new test case is added to verify correct error reporting for unsupported operations.

Error handling improvements:

  • Updated the handleStake, handleUnstake, and handleWithdraw functions in LiquidStaking.cpp to return a Result<void> type, allowing them to signal specific errors when a protocol or operation is not supported, rather than failing silently.
  • Modified the buildStraderEVM and buildLidoEVM builder functions to check the result of handler calls and set the output status with an appropriate error code and message if an operation is not supported. [1] [2]

Code quality and maintainability:

  • Replaced repeated registry lookups with more efficient iterator usage in handler functions, reducing redundant code and improving clarity.
  • Added missing include for Result.h in LiquidStaking.cpp to support the new error handling mechanism.

Testing:

  • Added a new test case StraderBnbWithdrawError to verify that attempting to withdraw with the Strader protocol on BNB_BSC correctly returns an error status, ensuring the new error handling is functioning as intended.

@octane-security-app

Copy link
Copy Markdown

Summary by Octane

New Contracts

No new contracts were added.

Updated Contracts

  • LiquidStaking.cpp: The smart contract now returns result objects for error handling in staking operations and checks protocol support before proceeding.

🔗 Commit Hash: 034371b

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves robustness in the LiquidStaking EVM builders by having the internal Strader/Lido action handlers report detailed failures (instead of silently producing incomplete transaction data) and propagating “operation not supported” errors into the Proto::Output status. It also adds a regression test to ensure unsupported Strader operations on BNB_BSC correctly return an error.

Changes:

  • Updated handleStake, handleUnstake, and handleWithdraw to return Result<void> and detect unsupported protocol/action combinations.
  • Updated buildStraderEVM and buildLidoEVM to check handler results and populate output.status on failure.
  • Added a test for Strader withdraw on BNB_BSC returning ERROR_OPERATION_NOT_SUPPORTED_BY_PROTOCOL.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/LiquidStaking/LiquidStaking.cpp Introduces Result<void>-based handler error propagation and updates builders to surface unsupported-operation failures.
tests/common/LiquidStaking/LiquidStakingTests.cpp Adds a new test asserting an error for unsupported Strader withdraw on BNB_BSC.
Comments suppressed due to low confidence (1)

src/LiquidStaking/LiquidStaking.cpp:258

  • In buildLidoEVM, the non-stake action path sets an error status but still falls through to setTransferDataAndAmount(transfer, payload, amount). In that branch amount is uninitialized, and even if it were initialized the function should not build a transaction after marking the output as an error.
        } else {
            *output.mutable_status() = generateError(Proto::ERROR_OPERATION_NOT_SUPPORTED_BY_PROTOCOL, "Lido protocol only support stake action for now");
        }

        internal::setTransferDataAndAmount(transfer, payload, amount);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/LiquidStaking/LiquidStaking.cpp Outdated
Comment thread src/LiquidStaking/LiquidStaking.cpp Outdated
Comment thread src/LiquidStaking/LiquidStaking.cpp Outdated
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown

Binary size comparison

➡️ aarch64-apple-ios: 14.31 MB

➡️ aarch64-apple-ios-sim: 14.32 MB

➡️ aarch64-linux-android: 18.73 MB

➡️ armv7-linux-androideabi: 16.17 MB

➡️ wasm32-unknown-emscripten: 13.66 MB

@octane-security-app

Copy link
Copy Markdown

Overview

Warnings found: 1                                                                                

Warnings

src/LiquidStaking/LiquidStaking.cpp

  • Soft-error handling returns signable EVM input on error in LiquidStaking builder causes zero-value contract calls and gas waste. See more

🔗 Commit Hash: 034371b
🛡️ Octane Dashboard: All vulnerabilities

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.

2 participants