[GHSA-x4xq-7w28-q486] Smart contract Marginal v1 performs unsafe downcast,...#7337
Open
donnyoregon wants to merge 1 commit intodonnyoregon/advisory-improvement-7337from
Open
[GHSA-x4xq-7w28-q486] Smart contract Marginal v1 performs unsafe downcast,...#7337donnyoregon wants to merge 1 commit intodonnyoregon/advisory-improvement-7337from
donnyoregon wants to merge 1 commit intodonnyoregon/advisory-improvement-7337from
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates
Comments
The previous Moderate severity rating significantly underrepresents the exploitability and
impact of this vulnerability. The correct severity is Critical (CVSS 9.1,
AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:H/A:H) for the following reasons:
EXPLOITABILITY (AV:N, AC:L, PR:N, UI:N):
The attack requires no account privileges, no user interaction, and is executable
atomically in a single on-chain transaction. An attacker takes out a flash loan, which is
a permissionless primitive available to any address on any block. There is no off-chain
coordination required. Attack complexity is Low.
IMPACT (I:H, A:H):
A successful exploit allows settlement of an arbitrarily large debt position for as little
as 57,005 wei. The corrupted margin value causes the protocol to accept repayment of a
debt that does not reflect the true obligation, resulting in direct, irreversible asset
loss to liquidity providers. Both integrity (corrupted on-chain state) and availability
(liquidity provider collateral rendered unrecoverable) are fully compromised.
SCOPE CHANGE (S:C):
The attacker manipulates their own position's stored margin value (position.margin), but
the financial loss is borne by liquidity providers — a separate trust boundary. This
cross-boundary impact satisfies the Scope:Changed criterion under CVSS 3.1.
BYTECODE EVIDENCE OF VULNERABILITY:
The adjust() function in MarginalV1Pool (proxy: 0x3A6C55Ce74d940A9B5dDDE1E57eF6e70bC8757A7)
performs a direct, unchecked cast of a calculated margin value into a uint128 container:
In Solidity, explicit casts do not revert on overflow. When margin0 exceeds
type(uint128).max, the upper bits are silently discarded via a bitwise AND operation.
The deployed bytecode confirms this at program counter 0x069c:
No GT opcode. No REVERT. The truncation is unconditional and silent.
PATCH EVIDENCE (independently verifiable on-chain):
The protocol maintainers confirmed the vulnerability by patching the exact unsafe downcast
(uint128(margin0)) with OpenZeppelin's SafeCast.toUint128(), which reverts on overflow.
Timeline:
trace, and recommended fix
The proxy uses Storage Slot 6 (EIP-1967 implementation slot
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc) to track its active
implementation. That slot changed at block 24,386,649 as follows:
Decompilation of the patched implementation confirms the addition of OpenZeppelin's
SafeCast library. The following error string is present in the patched bytecode and
completely absent from the vulnerable implementation:
Verification commands (requires cast from the Foundry toolchain):
cast storage 0x3A6C55Ce74d940A9B5dDDE1E57eF6e70bC8757A7 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
cast code 0xd8be1b2571b7c43b77ff3ae87bc6f0a23fa224b8
cast code 0xfb1bffc9d739b8d520daf37df666da4c687191ea
CVE ASSIGNMENT:
CERT/CC assigned CVE-2026-4931 (CERT/CC Vulnerability Note VU#643748) following
independent review, consistent with critical severity for a remotely exploitable,
zero-privilege, fund-draining arithmetic vulnerability in a deployed DeFi protocol.
Reference: https://nvd.nist.gov/vuln/detail/CVE-2026-4931