| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Convex.ThreatModel.ValueUnderpayment
Description
Threat model for detecting Value Underpayment vulnerabilities.
A Value Underpayment Attack exploits validators that don't properly verify that the actual ADA value in an output matches the expected value based on the datum. If a validator tracks a "balance" in the datum but doesn't verify the actual ADA matches, an attacker can modify transactions to underpay.
Example Vulnerability ==
Consider a bank contract where the account datum tracks a balance:
data AccountDatum = AccountDatum { balance :: Integer, owner :: PubKeyHash }
If the deposit action (IncreaseBalance) only checks that: - The output datum has an increased balance - But doesn't verify that the actual ADA value increased by the same amount
Then an attacker can "deposit" by increasing the datum balance without adding any actual ADA to the output.
Consequences ==
- Free balance increases: Attacker gains balance without depositing funds
- Theft of pooled funds: If the bank pays out based on datum balance, the attacker can withdraw more than they deposited
- Insolvency: Multiple attackers can drain the bank's pooled funds
Root Cause ==
Validators that: - Track value in datum without verifying actual UTxO value matches - Only check datum changes without checking corresponding value changes - Allow balance increases without requiring matching fund increases
Mitigation ==
A secure validator should: - Verify output value matches expected value based on datum - Check that fund_difference == balance_change for deposits/withdrawals - Never rely solely on datum for balance tracking
This threat model tests if a script output can have its ADA value reduced while keeping the datum unchanged. If the transaction still validates, the validator has a Value Underpayment vulnerability.
Synopsis
Documentation
valueUnderpaymentAttack :: ThreatModel () Source #
Check for Value Underpayment vulnerabilities by halving the ADA value.
This is the default configuration that reduces the ADA in a script output by 50%. If the transaction still validates, the script doesn't properly verify that output values match expected amounts.
valueUnderpaymentAttackWith :: Double -> ThreatModel () Source #
Check for Value Underpayment vulnerabilities with a configurable reduction factor.
For a transaction with script outputs:
- Find a script output with ADA value
- Reduce its ADA value by the given factor (e.g., 0.5 = halve it)
- Keep the datum unchanged
- If the transaction still validates, the script doesn't verify that output value matches the expected amount based on datum.
reductionFactor should be between 0 and 1:
- 0.5 means reduce to 50% of original value
- 0.25 means reduce to 25% of original value
- 0.9 means reduce to 10% of original value (keep only 10%)
The attack ensures at least minOutputAda remains to avoid min-UTxO failures.