convex-testing-interface
Safe HaskellSafe-Inferred
LanguageHaskell2010

Convex.ThreatModel.LargeValue

Description

Threat model for detecting Large Value Attack vulnerabilities.

A Large Value Attack exploits validators that don't properly validate the structure of Value in their outputs. If a validator allows spending from a script output without checking what tokens are present in the output's value, an attacker can "bloat" the value with additional junk tokens.

Consequences ==

  1. Increased min-UTxO requirements: Each unique token in a UTxO increases the minimum Ada required. Adding many junk tokens forces the victim to lock more Ada than intended.
  2. Serialization costs: Large values increase transaction size, consuming more of the victim's fee budget when spending the UTxO.
  3. Permanent fund locking: If the value is bloated sufficiently:
  • The transaction required to spend the UTxO may exceed protocol size limits
  • The serialized output may exceed the max-value-size protocol parameter

In these cases, the UTxO becomes permanently unspendable and funds are locked forever with no possibility of recovery.

Root Cause ==

Validators that don't check the Value structure of outputs being created. For example, a validator that only checks:

traceIfFalse "insufficient payment" (valuePaidTo pkh >= expectedAmount)

This allows an attacker to include expectedAmount + junkTokens, satisfying the check while bloating the output.

Mitigation ==

A secure validator should either:

  • Whitelist expected tokens (only allow known policy IDs)
  • Check the token count (e.g., length (flattenValue v) <= maxTokens)
  • Require exact value match (not just >= comparison)
  • Validate that outputs contain only expected assets

This threat model tests if a script output can have arbitrary tokens added to its value via minting. If the transaction still validates, the validator has a Large Value Attack vulnerability.

Synopsis

Documentation

largeValueAttack :: ThreatModel () Source #

Check for Large Value Attack vulnerabilities with 50 junk tokens.

This is the default configuration that mints 50 unique tokens and adds them to a script output. If the transaction still validates, the script doesn't properly validate the value structure of its outputs.

largeValueAttackWith :: Int -> ThreatModel () Source #

Check for Large Value Attack vulnerabilities with a configurable number of junk tokens.

For a transaction with script outputs:

  • Mint n unique junk tokens using an always-succeeds minting policy
  • Add these tokens to a script output's value
  • If the transaction still validates, the script doesn't validate the structure of values being created - it may only check amounts.

This catches a vulnerability where validators use permissive value checks like valuePaidTo addr >= expected instead of exact matching, allowing attackers to inflate UTxO min-Ada requirements or lock funds permanently.