
Loading...
Loading
Loading...
LoadingLoading audit report...

WalletGuard.ai, powered by Gestalt Labs
Forge fork-validation ran but no findings met the threshold for PoC inclusion. See the per-finding "Forge validated" badges in the report below for individual results.
The analyzed contract is a decentralized orderbook exchange (AMM/DEX variant) supporting token deposits, order placement, fills, and withdrawals. The analysis identified 3 critical, 3 high, 4 medium, 2 low, and 2 informational findings across 8 specialist agents. The single most dangerous pattern is an unchecked arithmetic underflow in the emergencyWithdraw pathway, which allows any user with zero balance to silently wrap their internal balance to near type(uint128).max and drain the entire token reserves of the contract in a single transaction. This contract is unsafe for deployment in its current state; the critical vulnerabilities allow complete fund loss for all depositors and must be remediated before any mainnet use.
Any user, even one with no funds deposited, can call a special emergency withdrawal function with any amount they choose. Because the contract uses unsafe math that does not check for negative results, subtracting a large amount from a zero balance silently produces an astronomically large fake balance instead of reverting. The attacker can then withdraw real tokens belonging to other users, draining the entire contract in one transaction.
The withdrawal function sends tokens to the user before recording that the withdrawal happened. If the token being withdrawn has a callback mechanism (such as ERC-777 tokens), a malicious recipient can re-enter the withdrawal function repeatedly before the balance is reduced, withdrawing the same funds multiple times and draining the contract.
The function that cancels orders does not verify that the person canceling the order is the person who created it. Anyone can cancel any open order belonging to any market maker. An attacker can wipe out all active orders on the entire orderbook, disrupting trading and enabling targeted griefing or front-running of profitable orders.
An attacker first calls emergencyWithdraw with an amount exceeding their zero balance. The unchecked underflow in _processWithdrawal (Finding: emergencyWithdraw has no balance check) wraps balances[attacker][token] to near type(uint128).max. The attacker then calls the standard withdraw function, which checks balances[msg.sender][token] >= amount and passes because the corrupted value is enormous. The safeTransfer sends all real tokens held by the contract to the attacker, fully draining every depositor's funds. The CEI violation in withdraw (Finding: CEI Violation in withdraw()) further compounds this by allowing a re-entrant call during the token transfer if the token has a callback hook, accelerating the drain.
An attacker monitors the mempool for large profitable fill transactions. Using the unauthorized cancel vulnerability (Finding: Unauthorized order cancellation), the attacker cancels the target order before the legitimate fill transaction confirms, causing the filler's transaction to revert. The attacker then re-places a similar order at a manipulated price and fills it themselves, capturing the profit. The incomplete order deletion (Finding: Incomplete order deletion in _cancelOrder) leaves stale linked-list state that could further corrupt orderbook traversal.
Because MAX_PRICE_DEVIATION is never enforced in placeOrder (Finding: MAX_PRICE_DEVIATION constant is defined but never enforced), a malicious maker can place orders at extreme prices. A taker who fills such an order at a large amount may trigger the uint128 truncation bug in fillOrder (Finding: quoteAmount silently truncated when cast to uint128), paying a drastically reduced quote amount while receiving the full base token amount. The maker loses value and the taker profits at their expense.
| Agent | Status | Findings | Severity | Confidence | Duration | Coverage |
|---|---|---|---|---|---|---|
| reentrancy | success | 4 | 2C | 87% | 40.6s | Cross-function reentrancy in withdraw() and emergencyWithdraw(), CEI (Checks-Effects-Interactions) pattern compliance across all state-mutating functions, unchecked arithmetic blocks in _processWithdrawal, Integer overflow/truncation in fillOrder quoteAmount uint128 cast, Access control on emergencyWithdraw, ERC-777 callback reentrancy risk on safeTransfer calls, Linked list integrity in placeOrder, cancel, fillOrder, Balance accounting consistency across deposit/withdraw/placeOrder/fillOrder, uint128 overflow in balance additions, Order existence checks and authorization |
| access control | success | 4 | 89% | 38.6s | Access control on all state-modifying functions (deposit, withdraw, placeOrder, cancel, fillOrder, emergencyWithdraw), Authorization checks: who can cancel orders, who can call emergencyWithdraw, Unchecked arithmetic in _processWithdrawal and its impact on balance underflow, Integer overflow/truncation in fillOrder quoteAmount cast from uint256 to uint128, Linked list integrity in order insertion, cancellation, and fill removal, Reentrancy: CEI pattern compliance in withdraw, fillOrder, emergencyWithdraw, ERC20 safeTransfer/safeTransferFrom usage, Signature/authentication patterns (none present), Initializer protection (no upgradeable proxy, not applicable), Delegatecall patterns (none present), tx.origin usage (not present) | |
| economic | success | 6 | 1C2H1M1L | 88% | 52.7s | Flash loan attack surface on balance-based order pricing, Oracle dependency (none found — pure orderbook, no price oracle), Access control on all state-mutating functions (cancel, emergencyWithdraw), Integer overflow/underflow in unchecked arithmetic blocks, Safe downcasting from uint256 to uint128 in fillOrder quoteAmount, Reentrancy via safeTransfer (CEI ordering checked in withdraw, fillOrder, emergencyWithdraw), Linked list integrity after cancel and fill operations, Sandwich/MEV exposure on order fills, Governance attack vectors (none present), Fee-on-transfer and rebasing token interactions, First-depositor inflation attacks (no LP share minting), Price deviation constant enforcement |
| logic validation | success | 5 | 1C1H2M | 88% | 52.9s | Input validation on all external functions (deposit, withdraw, placeOrder, cancel, fillOrder, emergencyWithdraw), Unchecked arithmetic blocks for underflow/overflow (found critical issue in _processWithdrawal), Authorization checks on order management functions (found missing auth in cancel), Integer overflow and truncation in quoteAmount cast to uint128, Precision loss and rounding direction in fillOrder quote calculation, Linked list integrity in order insertion, cancellation, and removal, State cleanup completeness in _cancelOrder and _removeFilledOrder, Reentrancy: SafeERC20 used, CEI pattern generally followed, ERC-20 standard compliance via OpenZeppelin imports, totalDeposits accounting correctness, getOrders linked list traversal for DoS via unbounded loop |
| code quality | success | 8 | 1L | 87% | 1.2m | Reentrancy in withdraw and emergencyWithdraw, Access control on emergencyWithdraw and cancel, Integer overflow/underflow in unchecked blocks, Unsafe downcasts from uint256 to uint128, Linked list integrity in placeOrder, cancel, and fillOrder, CEI pattern compliance, ERC-20 standard compliance for deposit/withdraw, Precision loss in price calculations, Dead code analysis, Constant/immutable usage |
| compiler bugs | success | 4 | 1C | 88% | 42.1s | Access control on cancel(), placeOrder(), fillOrder(), emergencyWithdraw(), Arithmetic overflow/underflow in unchecked blocks (_processWithdrawal), Integer truncation in fillOrder quoteAmount casting, Reentrancy in deposit(), withdraw(), fillOrder() — all follow CEI or use SafeERC20 with balance-before-transfer pattern, Linked list integrity in order insertion/removal (_cancelOrder, _removeFilledOrder), ERC20 transfer safety — SafeERC20 used throughout public entry points, Compiler bug applicability — pragma ^0.8.20 is outside all known affected ranges, Dust order / MIN_ORDER_SIZE enforcement in placeOrder, MAX_PRICE_DEVIATION constant declared but not enforced in placeOrder |
| assembly safety | success | 5 | 88% | 50.0s | Full codepoint-by-codepoint scan for non-ASCII characters, RTLO (U+202E), zero-width characters (U+200B, U+200C, U+200D), and Cyrillic homoglyphs in all identifiers, function names, and string literals — none found, Inline assembly blocks — none present in this contract, Access control on all external/public state-mutating functions (deposit, withdraw, placeOrder, cancel, fillOrder, emergencyWithdraw), Integer arithmetic including unchecked blocks, uint128/uint256 cast truncation risks, Reentrancy patterns and checks-effects-interactions ordering, Linked list manipulation correctness in placeOrder, cancel, fillOrder, Constant enforcement (MIN_ORDER_SIZE, MAX_PRICE_DEVIATION), MockTIP20 contract for minter access control and mint function safety, SafeERC20 usage correctness, Event emission completeness, Flash loan / price oracle manipulation attack surfaces | |
| l2 specific | success | 7 | 1M1L | 85% | 1.1m | Deposit and withdrawal logic including CEI pattern compliance, emergencyWithdraw unchecked arithmetic and access control, Order placement, cancellation, and fill logic, Authorization checks in cancel() and placeOrder(), Integer overflow/underflow in fillOrder quoteAmount cast, Linked list integrity in _cancelOrder and _removeFilledOrder, MAX_PRICE_DEVIATION enforcement (or lack thereof), Fee-on-transfer token compatibility, Reentrancy vectors across deposit/withdraw/fillOrder, uint128 overflow in balance accumulation, getOrders view function for unbounded loop / DoS, MockTIP20 minter access control, Chain-agnostic analysis (no L2-specific markers found) |
This automated audit has inherent limitations. The following areas are not covered.
This report is an automated point-in-time assessment and does not guarantee protection against all possible attacks. It does not cover off-chain components, economic modeling, or business logic correctness unless explicitly noted. Changes to the contract after the audit commit are not reviewed. This is not financial or legal advice. WalletGuard, powered by Gestalt Labs, provides this analysis as-is with no warranty of completeness.
[](https://walletguard.ai/audit/c82b6d5e-384e-421e-94ac-a81edc3fe419)
<a href="https://walletguard.ai/audit/c82b6d5e-384e-421e-94ac-a81edc3fe419"> <img src="https://walletguard.ai/api/badge/c82b6d5e-384e-421e-94ac-a81edc3fe419" alt="WalletGuard Audit Badge" /> </a>