Skip to content

fix(oft): address bridge contract logic audit findings - #38

Open
sirpy wants to merge 2 commits into
masterfrom
fix/oft-bridge-audit-logic
Open

sirpy wants to merge 2 commits into
masterfrom
fix/oft-bridge-audit-logic

Conversation

@sirpy

@sirpy sirpy commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements fixes, documentation updates, and regression tests addressing the logic audit of GoodDollarOFTAdapter, GoodDollarOFTMinterBurner, and LayerZero/bridge configuration.

Changes by Audit Finding

  1. Source-chain bridge fee deduction (GoodDollarOFTAdapter)

    • Overrode _debitView to deduct _takeFee(amountSentLD) on the source chain and dust-align amountReceivedLD = _removeDust(amountSentLD - fee). Any sub-shared-decimal rounding dust from fee calculation stays in fee = amountSentLD - amountReceivedLD (transferred to feeRecipient), ensuring 1:1 cross-chain supply conservation and real minAmountLD slippage protection (SlippageExceeded).
    • Updated _debit to transfer amountReceivedLD to minterBurner and burn it (skipping when 0), and transfer fee directly from _from to feeRecipient (verifying exact balance delta and emitting FeeCollected).
    • Updated _credit to mint the full received _amountLD on the destination chain (no destination-side fee deduction, so in-flight and 7-day parked requests are immune to post-send fee changes).
    • Populated oftFeeDetails in quoteOFT with OFTFeeDetail(int256(fee), "Bridge fee") when fee > 0.
    • Updated _send to enforce bridge limits against the net bridged amountReceivedLD so transfers whose post-fee amount falls below minAmount revert cleanly on the source chain instead of being parked on destination.
  2. Optimistic window vs. DAO governance latency (GoodDollarOFTAdapter)

    • Increased OPTIMISTIC_WINDOW from 3 days to 7 days (keeping all other approval/rejection/pause access controls unchanged).
    • Updated unit and reentrancy tests to verify that 3 days is no longer sufficient and 7 days is required for permissionless approval.
  3. approveFailedRequest whitelist behavior (GoodDollarOFTAdapter)

    • Documented in approveFailedRequest NatSpec that skipping bridgeLimits.onlyWhitelisted on approval is intentional: whitelist eligibility is already enforced when _lzReceive parks the request, only isClosed gates approval, and rejectFailedRequest is available if the owner wants to block a parked request.
  4. Missing SEND_AND_CALL enforced options & parking gas/state mutation (layerzero.config.ts, GoodDollarOFTAdapter)

    • Added enforced LZ_RECEIVE gas (250000) for msgType: 2 (SEND_AND_CALL) in scripts/oft/layerzero.config.ts alongside msgType: 1 (SEND).
    • Moved _resetDailyLimitsIfNeeded(bridgeReceiveDailyLimit, account) into the else (accepted) branch of _lzReceive. Because _checkBridgeLimits already evaluates expired 24h windows in read-only mode, this avoids up to ~25k wasted cold SSTORE gas on the parking path and prevents parked receives from mutating lastTransferReset.
  5. Stale storage on rejected requests & check ordering (GoodDollarOFTAdapter)

    • Changed rejectFailedRequest to delete failedReceiveRequests[_guid] (matching approveFailedRequest) so rejected payloads do not linger in storage and gas refunds are reclaimed.
    • Updated failedRequestDetails to require request.failed && request.message.length >= 40 so rejected requests revert with 'no parked message' instead of returning stale details.
    • Reordered approveFailedRequest to check require(request.failed, 'request not failed') before the optimistic window timestamp check.
  6. Ownership transfer vs. LayerZero Endpoint delegate & renounceOwnership (GoodDollarOFTAdapter)

    • Overrode transferOwnership(address newOwner) to also call endpoint.setDelegate(newOwner), preventing the previous owner from retaining LayerZero Endpoint configuration control after ownership transfers.
    • Overrode renounceOwnership() to always revert ('renounceOwnership disabled') so upgrades, pause controls, and failed-request rejection cannot be permanently bricked.
  7. Limit validation, production config & quoteOFT accuracy (GoodDollarOFTAdapter, oft.config.json)

    • Added require(_limits.minAmount <= _limits.accountDailyLimit, 'minAmount > accountDailyLimit') in setBridgeLimits.
    • Aligned production-xdc and production-celo txLimit in scripts/oft/oft.config.json from "100000" to "50000" to match accountDailyLimit ("50000").
    • Updated quoteOFT to use _checkBridgeClosedAndWhitelisted(msg.sender) (returning maxAmountLD = 0 for non-whitelisted callers when onlyWhitelisted is enabled) and dust-align maxAmount via _removeDust(maxAmount).
  8. Defense-in-depth & initialization hardening (GoodDollarOFTAdapter, GoodDollarOFTMinterBurner)

    • Added nonReentrant to _send and _lzReceive (no conflict with approveFailedRequest since replayFailedRequest invokes super._lzReceive).
    • Added require(address(token) != address(0), 'token required') in GoodDollarOFTMinterBurner.initialize.
    • Refined the UPGRADE NOTE comment on FailedReceiveRequest to accurately describe legacy storage slot decoding.

Testing

  • GoodDollarOFT.test.ts: 54 passing (covering source-chain fee deduction, SlippageExceeded on minAmountLD, quoteOFT oftFeeDetails & whitelist/dust alignment, dust rounding into feeRecipient, zero-burn skip when minFee >= amount, 7-day optimistic window, parking not mutating lastTransferReset, rejectFailedRequest storage deletion + failedRequestDetails revert, transferOwnership delegate sync + renounceOwnership disabled, minAmount > accountDailyLimit, and GoodDollarOFTMinterBurner zero-token init).
  • GoodDollarOFT.reentrancy.test.ts (mock token): 1 passing.
  • GoodDollarOFTAdapter compiled size: 23.284 KB (under the 24.576 KB EIP-170 limit).

- Skip zero-value recipient mint in _credit when fee == amount and document destination-side fee semantics
- Extend OPTIMISTIC_WINDOW from 3 days to 7 days
- Document that approveFailedRequest intentionally skips onlyWhitelisted re-check
- Defer _resetDailyLimitsIfNeeded to accepted receives in _lzReceive and add msgType 2 (SEND_AND_CALL) enforced options
- Delete storage in rejectFailedRequest, require failed flag in failedRequestDetails, and check failed before timestamp in approveFailedRequest
- Sync LayerZero endpoint delegate in transferOwnership and disable renounceOwnership
- Enforce minAmount <= accountDailyLimit, align production txLimit in oft.config.json, and check whitelist + dust-align maxAmount in quoteOFT
- Add nonReentrant on _send/_lzReceive, require non-zero token in GoodDollarOFTMinterBurner.initialize, and refine FailedReceiveRequest upgrade note

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/bridge-contracts/scripts/oft/layerzero.config.ts" line_range="33-38" />
<code_context>
         returns (OFTLimit memory oftLimit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory oftReceipt)
     {
         uint256 maxAmount;
-        if (!isClosed) {
</code_context>
<issue_to_address>
**Composed actions remain unexecuted**

When a caller sends a composed transfer relying on enforced options without supplying its own `LZ_COMPOSE` option, the `msgType: 2` entry enforces only `LZ_RECEIVE` gas, while LayerZero runs the compose callback separately. The payload can be queued without enforced gas for that callback, so the composed action does not complete.

Add an enforced `LZ_COMPOSE` gas option for `msgType: 2`.
</issue_to_address>

### Comment 2
<location path="packages/bridge-contracts/contracts/oft/GoodDollarOFTAdapter.sol" line_range="491" />
<code_context>
             uint256 accountLeft = limits.accountDailyLimit > accountUsed ? limits.accountDailyLimit - accountUsed : 0;
             if (dailyLeft < maxAmount) maxAmount = dailyLeft;
             if (accountLeft < maxAmount) maxAmount = accountLeft;
+            maxAmount = _removeDust(maxAmount);
         }
         oftLimit = OFTLimit(bridgeLimits.minAmount, maxAmount);
</code_context>
<issue_to_address>
**Quoted minimum sends revert**

When the owner configures a `minAmount` that is not aligned to the shared-decimal conversion rate, `quoteOFT` reports the raw minimum, but `_send` removes dust before checking it. The quoted minimum can therefore round below the threshold and revert; when the effective cap equals that minimum, the quote can also report a maximum below its minimum, leaving no valid send amount.

Reject non-dust-aligned `minAmount` values when setting bridge limits.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and the adapter changes how bridged token transfers are checked and credited, and those transfers can mint or burn tokens that cannot be recovered by reverting the contract code. A mistake in the limits, fee, or receive path could therefore leave funds transferred or minted incorrectly; reverting would stop future effects but not undo completed transfers.

Blocking findings: packages/bridge-contracts/scripts/oft/layerzero.config.ts:38, packages/bridge-contracts/contracts/oft/GoodDollarOFTAdapter.sol:491


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +33 to +38
{
msgType: 2,
optionType: ExecutorOptionType.LZ_RECEIVE,
gas: 250000,
value: 0,
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Composed actions remain unexecuted

When a caller sends a composed transfer relying on enforced options without supplying its own LZ_COMPOSE option, the msgType: 2 entry enforces only LZ_RECEIVE gas, while LayerZero runs the compose callback separately. The payload can be queued without enforced gas for that callback, so the composed action does not complete.

Add an enforced LZ_COMPOSE gas option for msgType: 2.

Prompt for AI agents
In `packages/bridge-contracts/scripts/oft/layerzero.config.ts` at lines 33-38:

**Composed actions remain unexecuted**

When a caller sends a composed transfer relying on enforced options without supplying its own `LZ_COMPOSE` option, the `msgType: 2` entry enforces only `LZ_RECEIVE` gas, while LayerZero runs the compose callback separately. The payload can be queued without enforced gas for that callback, so the composed action does not complete.

Add an enforced `LZ_COMPOSE` gas option for `msgType: 2`.

uint256 accountLeft = limits.accountDailyLimit > accountUsed ? limits.accountDailyLimit - accountUsed : 0;
if (dailyLeft < maxAmount) maxAmount = dailyLeft;
if (accountLeft < maxAmount) maxAmount = accountLeft;
maxAmount = _removeDust(maxAmount);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Quoted minimum sends revert

When the owner configures a minAmount that is not aligned to the shared-decimal conversion rate, quoteOFT reports the raw minimum, but _send removes dust before checking it. The quoted minimum can therefore round below the threshold and revert; when the effective cap equals that minimum, the quote can also report a maximum below its minimum, leaving no valid send amount.

Reject non-dust-aligned minAmount values when setting bridge limits.

Prompt for AI agents
In `packages/bridge-contracts/contracts/oft/GoodDollarOFTAdapter.sol` at line 491:

**Quoted minimum sends revert**

When the owner configures a `minAmount` that is not aligned to the shared-decimal conversion rate, `quoteOFT` reports the raw minimum, but `_send` removes dust before checking it. The quoted minimum can therefore round below the threshold and revert; when the effective cap equals that minimum, the quote can also report a maximum below its minimum, leaving no valid send amount.

Reject non-dust-aligned `minAmount` values when setting bridge limits.

- Override _debitView to deduct bridge fees and dust-align amountReceivedLD so minAmountLD slippage protection, OFTSent, and quoteOFT reflect exact net bridged amounts
- Transfer bridge fees directly to feeRecipient in _debit and burn only net amountReceivedLD via minterBurner
- Populate oftFeeDetails in quoteOFT when bridge fees are non-zero
- Enforce send-side bridge limits against net bridged amountReceivedLD
- Mint full received _amountLD in _credit (no destination-side fee deduction)
- Update and expand unit tests for source-chain fee deduction, slippage protection, dust handling, and quoteOFT

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant