Stellar AMM - Normal Finance


Prepared by:

Halborn Logo

HALBORN

Last Updated 08/15/2025

Date of Engagement: June 25th, 2025 - August 5th, 2025

Summary

100% of all REPORTED Findings have been addressed

All findings

12

Critical

0

High

3

Medium

1

Low

2

Informational

6


1. Introduction

Halborn was engaged by the Normal AMM team to perform a targeted security assessment of their Soroban-based automated market maker (AMM) protocol on Stellar. The scope included analyzing the core on-chain components responsible for liquidity management, routing, oracle integration, incentives, and access control. The assessment aimed to verify correctness, safety, and economic robustness.

2. Assessment Summary

A senior blockchain security engineer from Halborn conducted the review full-time. The engineer has extensive experience in Rust, Soroban/Stellar, AMM design, and protocol security, including upgradeability, authorization, and oracle systems.


The codebase components reviewed included:

    • Contracts: pool, pool_router, oracle_registry, pool_plane, pool_swap_fee, insurance_fund, liquidity_calculator, token

    • Shared modules: access_control, incentives, utils, upgrade


The review focused on verifying economic invariants (such as pricing, fees, and shares), oracle validation and safeguards, privilege boundaries, emergency controls, and upgrade procedures.


Engagement objectives included:

    • Ensuring that new and modified functions behave as intended and are resistant to misuse and edge cases.

    • Identifying vulnerabilities that could lead to fund loss, invariant violations, incorrect state transitions, oracle manipulation, privilege escalation, or denial of service.

    • Highlighting areas where stronger invariants, defensive checks, or clearer authorization controls can reduce operational and economic risks.


3. Test Approach and Methodology

To ensure comprehensive and cross-cutting coverage, the assessment employed a consistent methodology across all first-party contracts and shared modules within the workspace:

    • Contracts: buffer, insurance_fund, liquidity_calculator, oracle_registry, pool, pool_plane, pool_router, pool_swap_fee, token

    • Shared modules: access_control, incentives, pool_tokens, upgrade, utils

    • Integration tests located in: contracts/integration_tests


The approach combined architecture mapping, manual expert review, static and dynamic analysis, property-based testing, and adversarial scenario simulations:


1) Repository-wide inventory and architecture mapping

    • Mapped all public entry points declared in interface.rs and within #[contractimpl] blocks; analyzed data and control flows among pool, pool_router, oracle_registry, pool_plane, liquidity_calculator, insurance_fund, and token contracts.

    • Identified trust boundaries, administrative roles, kill switches, upgrade paths, and oracle dependencies; documented invariants for each component.


2) Manual line-by-line review (across all crates)

    • Examined each contract’s contract.rs, storage.rs, errors.rs, and events.rs files:

    • Verified authorization and role checks via modules/access_control.

    • Assessed storage keys, data lifetimes, bumping strategies, and differentiated between persistent and temporary data usage.

    • Analyzed mathematical invariants within pool.rs, liquidity_calculator, pool_swap_fee, utils::math, and incentives mechanisms.

    • Reviewed cross-contract calls (router, oracle, plane, token) for error propagation, potential DoS vulnerabilities, and reentrancy issues.

    • Verified upgrade flows via modules/upgrade across upgradable contracts.

    • Assessed emergency/kill toggles, expiry, and settlement transition mechanisms.

    • Ensured event schemas are consistent and correctly implemented.


3) Static analysis and linting (workspace-wide)

    • Applied linting tools and targeted grep scans to identify anti-patterns, including:

    • Unchecked type conversions, saturation underflows, panics affecting user flows.

    • Misuse of U256 and fixed-point math, including rounding errors.

    • Incomplete authorization checks and role management inconsistencies.


4) Property-based testing and fuzzing for critical math routines

Focused on:

    • Swap route correctness, fee adjustments, and invariant violations (such as fee residues).

    • Precision in receive computations and boundary condition handling.

    • Price functions (peg_price, get_delta_a) and rolling metrics.

    • Incentives accumulation and distribution, including per-user and per-pool calculations, with correct handling of pagination constants.

    • Tested edge cases involving zero or near-zero values, maximum fees, large reserves, and rounding boundaries.


5) Stateful adversarial testing and PoC development

    • Designed multi-step scenarios across contracts to detect emergent behaviors:

    • Upgrade commit, apply, and revert; emergency mode activation and deactivation within deadlines.

    • Kill/un-kill toggles; roles for pausing versus emergency pauses.

    • Handling of oracle data volatility and staleness, cached versus fresh data paths, with safeguards.

    • Insurance fund claims constrained by tiers and thresholds.

    • Router orchestration and liquidity calculator during failures.

    • Prototype calculations for NAV/share underpricing during rebalancing, supported by mathematical proof independent from harness dependencies.


6) Integration testing and cross-contract orchestration

    • Utilized existing integration tests and created custom scenarios:

    • Deployment of contracts using contractimport! for pool_plane, liquidity_calculator, pool_router, and oracle_registry.

    • End-to-end testing covering initialization, deposits, swaps, withdrawals, incentives, claims, rebalancing, upgrades, and emergency procedures.

    • Used functions like utils::test_utils::jump to manipulate time for testing staleness, delays, and expiry conditions.


7) Permission boundary testing (positive and negative cases)

    • Systematically verified role-based permissions for Admin, EmergencyAdmin, RewardsAdmin, OperationsAdmin, PauseAdmin, and EmergencyPauseAdmin. Patterns followed those in each crate’s test_permissions.rs.

    • Reviewed ownership transfer workflows and deadline enforcement for correctness.


8) Oracle validation and economic safety assessment

    • Validated oracle safeguards, including volatility thresholds, staleness limits, clamping, TWAP updates, and cached versus live data handling.

    • Assessed core economic invariants such as:

    • Enforcement of AMM invariant, accurate fee accounting, and residue handling.

    • Share valuation consistency aligned with pool NAV during rebalancing.

    • Limits on insurance coverage per tier, as well as revenue withdrawals and settlement procedures.


9) Token interactions and assumptions testing

    • Verified token helper functions (utils::token), pool token management (pool_tokens), and behaviors regarding allowances and transfers.

    • Analyzed dependencies on standard token implementations and error handling pathways for non-standard tokens in strict-receive and refund scenarios.


10) Performance, resource consumption, and reliability evaluations

    • Considered ledger instruction limits, storage growth, and pagination (e.g., PAGE_SIZE).

    • Examined pool_plane updates for potential liveness issues and recommended implementing soft-fail patterns where appropriate to improve reliability.


11) Test execution and validation strategy

    • Developed targeted tests and proofs of concept to validate identified risks and invariants, including snapshot captures of critical error pathways.


This methodology achieved full coverage of the codebase with focused depth on high-risk areas such as oracle integration, upgradeability, access control, AMM mathematics, and incentives, enabling the detection of both correctness and economic vulnerabilities.

4. RISK METHODOLOGY

Every vulnerability and issue observed by Halborn is ranked based on two sets of Metrics and a Severity Coefficient. This system is inspired by the industry standard Common Vulnerability Scoring System.
The two Metric sets are: Exploitability and Impact. Exploitability captures the ease and technical means by which vulnerabilities can be exploited and Impact describes the consequences of a successful exploit.
The Severity Coefficients is designed to further refine the accuracy of the ranking with two factors: Reversibility and Scope. These capture the impact of the vulnerability on the environment as well as the number of users and smart contracts affected.
The final score is a value between 0-10 rounded up to 1 decimal place and 10 corresponding to the highest security risk. This provides an objective and accurate rating of the severity of security vulnerabilities in smart contracts.
The system is designed to assist in identifying and prioritizing vulnerabilities based on their level of risk to address the most critical issues in a timely manner.

4.1 EXPLOITABILITY

Attack Origin (AO):
Captures whether the attack requires compromising a specific account.
Attack Cost (AC):
Captures the cost of exploiting the vulnerability incurred by the attacker relative to sending a single transaction on the relevant blockchain. Includes but is not limited to financial and computational cost.
Attack Complexity (AX):
Describes the conditions beyond the attacker’s control that must exist in order to exploit the vulnerability. Includes but is not limited to macro situation, available third-party liquidity and regulatory challenges.
Metrics:
EXPLOITABILITY METRIC (mem_e)METRIC VALUENUMERICAL VALUE
Attack Origin (AO)Arbitrary (AO:A)
Specific (AO:S)
1
0.2
Attack Cost (AC)Low (AC:L)
Medium (AC:M)
High (AC:H)
1
0.67
0.33
Attack Complexity (AX)Low (AX:L)
Medium (AX:M)
High (AX:H)
1
0.67
0.33
Exploitability EE is calculated using the following formula:

E=meE = \prod m_e

4.2 IMPACT

Confidentiality (C):
Measures the impact to the confidentiality of the information resources managed by the contract due to a successfully exploited vulnerability. Confidentiality refers to limiting access to authorized users only.
Integrity (I):
Measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of data stored and/or processed on-chain. Integrity impact directly affecting Deposit or Yield records is excluded.
Availability (A):
Measures the impact to the availability of the impacted component resulting from a successfully exploited vulnerability. This metric refers to smart contract features and functionality, not state. Availability impact directly affecting Deposit or Yield is excluded.
Deposit (D):
Measures the impact to the deposits made to the contract by either users or owners.
Yield (Y):
Measures the impact to the yield generated by the contract for either users or owners.
Metrics:
IMPACT METRIC (mIm_I)METRIC VALUENUMERICAL VALUE
Confidentiality (C)None (C:N)
Low (C:L)
Medium (C:M)
High (C:H)
Critical (C:C)
0
0.25
0.5
0.75
1
Integrity (I)None (I:N)
Low (I:L)
Medium (I:M)
High (I:H)
Critical (I:C)
0
0.25
0.5
0.75
1
Availability (A)None (A:N)
Low (A:L)
Medium (A:M)
High (A:H)
Critical (A:C)
0
0.25
0.5
0.75
1
Deposit (D)None (D:N)
Low (D:L)
Medium (D:M)
High (D:H)
Critical (D:C)
0
0.25
0.5
0.75
1
Yield (Y)None (Y:N)
Low (Y:L)
Medium (Y:M)
High (Y:H)
Critical (Y:C)
0
0.25
0.5
0.75
1
Impact II is calculated using the following formula:

I=max(mI)+mImax(mI)4I = max(m_I) + \frac{\sum{m_I} - max(m_I)}{4}

4.3 SEVERITY COEFFICIENT

Reversibility (R):
Describes the share of the exploited vulnerability effects that can be reversed. For upgradeable contracts, assume the contract private key is available.
Scope (S):
Captures whether a vulnerability in one vulnerable contract impacts resources in other contracts.
Metrics:
SEVERITY COEFFICIENT (CC)COEFFICIENT VALUENUMERICAL VALUE
Reversibility (rr)None (R:N)
Partial (R:P)
Full (R:F)
1
0.5
0.25
Scope (ss)Changed (S:C)
Unchanged (S:U)
1.25
1
Severity Coefficient CC is obtained by the following product:

C=rsC = rs

The Vulnerability Severity Score SS is obtained by:

S=min(10,EIC10)S = min(10, EIC * 10)

The score is rounded up to 1 decimal places.
SeverityScore Value Range
Critical9 - 10
High7 - 8.9
Medium4.5 - 6.9
Low2 - 4.4
Informational0 - 1.9

5. SCOPE

REPOSITORY
(a) Repository: normal-stellar-amm
(b) Assessed Commit ID: 5e746ed
(c) Items in scope:
  • insurance_fund
  • oracle_registry
  • pool
↓ Expand ↓
Remediation Commit ID:
  • 1c76060
  • bf069b9
  • ad15b98
  • 281bb6a
  • c9e27d6
  • 6443f8b
  • d8a2755
  • 9b274e9
  • 3361556
  • dc12345
  • 211a138
Out-of-Scope: New features/implementations after the remediation commit IDs.

6. Assessment Summary & Findings Overview

Critical

0

High

3

Medium

1

Low

2

Informational

6

Security analysisRisk levelRemediation Date
Oracle Registry Argument Swap Triggers Panic on Price Up-TicksHighSolved - 08/01/2025
Sanitize New Price Underflows On Price Drop, Triggering Protocol Wide PanicHighSolved - 08/01/2025
NAV Underpricing via Fixed Share MintingHighSolved - 08/04/2025
PoolRouter Reward Front-Run Enables Zero-Emission GriefingMediumSolved - 08/01/2025
Dust-Initialisation / Fee-Skimming Risk — totalLP Can Fall to 0LowSolved - 07/29/2025
Stale-delay Allows Frozen or Cached Prices to Look FreshLowSolved - 08/01/2025
Zero-Amount Deposits AllowedInformationalSolved - 07/30/2025
Zero-Amount Stake AcceptedInformationalSolved - 07/30/2025
Price-override Cooldown can be BypassedInformationalSolved - 08/01/2025
Redundant Ownership-Transfer: Future Owner Can Equal Current OwnerInformationalSolved - 08/01/2025
sanitize_clamp_denominator is Unchecked (Division-by-Zero Risk)InformationalSolved - 07/31/2025
Unbounded Synthetic-Minting During “Reduce-Only” ModeInformationalSolved - 08/01/2025

7. Findings & Tech Details

7.1 Oracle Registry Argument Swap Triggers Panic on Price Up-Ticks

//

High

Description
Proof of Concept
BVSS
Recommendation
Remediation Comment
Remediation Hash

7.2 Sanitize New Price Underflows On Price Drop, Triggering Protocol Wide Panic

//

High

Description
Proof of Concept
BVSS
Recommendation
Remediation Comment
Remediation Hash

7.3 NAV Underpricing via Fixed Share Minting

//

High

Description
BVSS
Recommendation
Remediation Comment
Remediation Hash

7.4 PoolRouter Reward Front-Run Enables Zero-Emission Griefing

//

Medium

Description
BVSS
Recommendation
Remediation Comment
Remediation Hash

7.5 Dust-Initialisation / Fee-Skimming Risk — totalLP Can Fall to 0

//

Low

Description
BVSS
Recommendation
Remediation Comment
Remediation Hash
References
Uniswap V2 Whitepaper, section 3.4 “Minimum Liquidity”
Uniswap V2 Core implementation — MINIMUM_LIQUIDITY = 1000 burned to address(0)

7.6 Stale-delay Allows Frozen or Cached Prices to Look Fresh

//

Low

Description
BVSS
Recommendation
Remediation Comment
Remediation Hash

7.7 Zero-Amount Deposits Allowed

//

Informational

Description
BVSS
Recommendation
Remediation Comment
Remediation Hash

7.8 Zero-Amount Stake Accepted

//

Informational

Description
BVSS
Recommendation
Remediation Comment
Remediation Hash

7.9 Price-override Cooldown can be Bypassed

//

Informational

Description
BVSS
Recommendation
Remediation Comment
Remediation Hash

7.10 Redundant Ownership-Transfer: Future Owner Can Equal Current Owner

//

Informational

Description
BVSS
Recommendation
Remediation Comment
Remediation Hash

7.11 sanitize_clamp_denominator is Unchecked (Division-by-Zero Risk)

//

Informational

Description
BVSS
Recommendation
Remediation Comment
Remediation Hash

7.12 Unbounded Synthetic-Minting During “Reduce-Only” Mode

//

Informational

Description
BVSS
Recommendation
Remediation Comment
Remediation Hash

Halborn strongly recommends conducting a follow-up assessment of the project either within six months or immediately following any material changes to the codebase, whichever comes first. This approach is crucial for maintaining the project’s integrity and addressing potential vulnerabilities introduced by code modifications.