/scalus:smart-contract-security-reviewfrom scalus
Reviews Scalus/Cardano smart contracts for vulnerabilities including redirect attacks, inexact value validation, missing token verification, broken token lifecycle invariants, and more. Use before deploying validators.
Ships in scalus. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Analyze Scalus/Cardano smart contracts for security vulnerabilities.
Find on-chain code by searching for:
@Compile annotationValidator, DataParameterizedValidator, or ParameterizedValidatorPlutusV3.compile(), PlutusV2.compile(), or PlutusV1.compile()Search patterns:
grep -rn "@Compile" --include="*.scala" <path>
grep -rn "extends Validator" --include="*.scala" <path>
grep -rn "extends DataParameterizedValidator" --include="*.scala" <path>
@Compile annotated code in specified pathScope: review the whole validator, every purpose and every branch, and the validators that read its UTxOs, even when you were asked about one change or one diff. A fix is safe only if the contract around it is: most findings in a fixed branch come from the branches next to it.
A contract that identifies its UTxO by a token is secure only if an invariant holds for every UTxO that carries the token: it sits at the script address, with a valid inline datum, and there is one of it. Prove it by induction, one row per transaction kind:
| Step | Must hold | Check |
|---|---|---|
| Base: mint | The minted token goes to an output at the own script, with an inline datum of the state type that passes the state's own rules (non-zero rate, deadline in the future, ...) | out.address.credential === ScriptCredential(policyId) (one script mints and spends) or the whole address; out.value.hasNft(policyId, name); out.datum.inlineOrFail[State](msg) plus the state checks. Missing: V038 |
| Step: each spend branch that continues | The continuing output keeps the token and a valid datum | hasNft on the continuing output (V002), datum checks (V015, V017) |
| End: burn | Burning the token happens only through a spend branch that allows it | the policy's burn branch allows only negative quantities (onlyBurnsUnder(policyId), V003); the spend branch checks the exact burn |
Report a missing base case or step. Then list the checks the invariant makes redundant (for
example a datum.isDefined guard on the token-holding UTxO) for optimize-contract; do not
report them as vulnerabilities.
An attack trace asks whether a bad transaction passes. Also ask whether every good transaction
passes. For each require on a continuing output, build the honest transaction of that branch and
trace it, with these variations:
=== or an exact lovelace equality
rejects it: the UTxO can get stuck (V039).A check that rejects an honest transaction is a finding even though no attacker gains value.
Based on Cardano Developer Portal security guidelines and Scalus-specific patterns.
For detailed patterns and code examples, see references/vulnerabilities.md.
Taxonomy IDs are family-number (DS double satisfaction, VP value preservation, AU
authentication, MI minting, TI time, DT datum, IX index, PU purpose, EV evaluation, AR
arithmetic, RS resources, DE design). "Fixed by" names the Scalus operation or idiom that
closes the class; "design" means no operation can, review the design.
| ID | Taxonomy | Name | Risk | Detection | Fixed by |
|---|---|---|---|---|---|
| V001 | VP-3 | Redirect Attack | Funds stolen via output redirection | outputs.at(idx) without a whole-address check | findContinuingOutputOrFail(ownInput, msg) |
| V002 | AU-1 | Token/NFT Not Verified | State token excluded | No hasNft / hasOnly on the continuing output | out.value.hasNft(policy, name) |
| V003 | MI-1 / MI-3 | Inexact Burn/Mint | Extra tokens minted, partial burn | >= instead of ===; quantityOf alone; forall(_._2 < 0) on a possibly empty map; a Burn redeemer branch that accepts any quantities (true): the Burn redeemer then mints | tx.mint.hasOnly(policy, name, signedQty); tx.onlyBurnsUnder(policy) |
| V004 | AR-1 | Rounding Direction (on-chain Integer is unbounded; there is no overflow) | Remainder harvested per split action; negative amounts | / on fees or shares without a stated direction; redeemer amounts without > 0 | a divCeil b / a divFloor b (round against the party that benefits: contract payouts down, amounts owed to the contract up) |
| V005 | DS-1 / DS-2 | Double Satisfaction | Pay once, satisfy many | outputs.exists without unique linking; >= payouts | inputs.findUniqueOrFail(_.resolved.address.credential === ownCred, msg) or hasPaidTagged(addr, value, tag) |
| V026 | VP-1 | Value Not Preserved on Continuing Output | Continuing UTxO drained while the datum looks right | Datum transition checked, .value never read; datum balance not tied to quantityOf | out.value.hasSameTokensAndAtLeastAda(expected); bind datum balances with quantityOf. Not === on a continuing output (V039) |
| V027 | VP-2 | ADA-Only Value Comparison | Native tokens stripped while lovelace matches | getLovelace as the only value check on a script UTxO (reading the amount with it is fine); getAdaFromOutputs / getAdaFromInputs | whole Value: valuePaidTo(addr), valueSpentFrom(addr), ===; or withoutLovelace.isZero at the boundary |
| V028 | MI-2 | One-Shot Seed Not Bound | "Unique" NFT mintable forever | TxOutRef parameter never compared with an input's outRef | findInputOrFail(seed, msg) or inputs.at(i).outRef === seed; seed.deriveTokenName; mint.hasOnly |
| V029 | IX-2 | Missed Input | A script input no index names is spent unchecked | Loop over redeemer indices, no walk over tx.inputs | walk tx.inputs; UtxoIndexer.multiOneToOneNoRedeemer |
| V038 | MI-4 | State Token Not Placed at Mint | The "authentic" token lives in a wallet or in a UTxO with no or an invalid datum; consumers trust it | A mint branch that checks the seed and hasOnly but no output: nothing says where the token goes or with which datum | require an output at the own script with hasNft(policyId, name) and a valid inline datum (token lifecycle table) |
| ID | Taxonomy | Name | Risk | Detection | Fixed by |
|---|---|---|---|---|---|
| V006 | IX-1 | Index Validation Missing | Wrong element behind an index | .at(idx) from the redeemer with no check on the element | findInputOrFail, findUniqueOrFail, singleOrFail |
| V007 | DE-3 | Self-Dealing/Shill Bidding | Price manipulation | No seller/bidder separation | design: require(!(bidder === seller)) |
| V008 | IX-1 | Double Spend via Index | Same UTxO processed twice | Index lists without uniqueness; zip truncation | strictly ascending indices; UtxoIndexer |
| V009 | VP-4 | Inexact Refund Amount | Fund manipulation, enables V005 | >= for refunds instead of === | out.value === Value.lovelace(n) (whole value); hasPaidTagged |
| V010 | PU-1 | Other Redeemer Attack | Bypass via different redeemer or purpose | Several purposes/branches with weaker checks; StakeValidator.spendMinimal alone | plugin default fail for unimplemented purposes (false positive for single-purpose objects, see below); StakeValidator.spend with a redeemer validator |
| V011 | MI-1 | Other Token Name Attack | Unauthorized token minting | quantityOf on one name, rest of the policy unchecked | tx.mint.hasOnly(policy, name, qty); mint.tokens(policy) === expected.tokens(policy) |
| V012 | AU-1 / AU-5 | Missing UTxO Authentication | Fake UTxO or planted reference-input datum | No auth token on own input or reference input | ownInput.resolved.value.hasNft(authPolicy, name); one-shot policy (V028) |
| V025 | DE-2 | Oracle Data Validation | Price manipulation, stale data | Oracle data without signature/freshness | design: verifyEd25519Signature + domain separation (V031), freshness vs validToOrFail |
| V030 | EV-1 | Evaluation-Order Trap | Security check never evaluated | Check on the right of || or in an untaken branch; pattern callback ending in a Boolean | one obligation per require; callbacks return Unit |
| V031 | AU-7 | Signature Domain Separation | Off-chain signature replayed across instances | verifyEd25519Signature over a payload without script hash and nonce | design: payload commits to domain tag, own script hash, spent TxOutRef |
| V032 | PU-3 | Certificate Purposes Unguarded | Deregistration griefing, deposit theft | certify body () or permissive case _ => () | plugin default fail; explicit TxCert match with failing default |
| V039 | VP-7 | Over-Strict Continuing Value | Honest transition rejected; UTxO stuck when the new datum needs more min-ADA | out.value === ownInput.resolved.value or out.value.getLovelace === amount on a continuing output whose datum changes | out.value.hasSameTokensAndAtLeastAda(expected); if a datum field records the lovelace, require it to equal the new getLovelace |
| ID | Taxonomy | Name | Risk | Detection | Fixed by |
|---|---|---|---|---|---|
| V013 | TI-1 / TI-2 | Time Handling | Unbounded range read as time 0; wrong inclusivity | getValidityStartTime (removed in 1.4.0, returns 0 when unbounded); raw bound compared | validFromOrFail(msg) (inclusive) / validToOrFail(msg) (exclusive); isEntirelyAfter/Before |
| V014 | AU-2 | Missing Signature | Unauthorized actions; script owner cannot sign | No isSignedBy on a branch; isSignedBy on a script hash | isSignedBy / isSignedByAny for keys; for a script authority prove it ran (withdrawal or spent input) |
| V015 | DT-1 | Datum Mutation | Unauthorized state change | Field-by-field comparison with a field missing | out.hasInlineDatum(old.copy(...)) |
| V016 | AU-4 | Insufficient Staking Control | Reward redirection (franken address) | address.credential ===, === Address.fromScriptHash(h), credential-only finders on the continuing output | findContinuingOutputOrFail; or require(out.address === ownInput.resolved.address) |
| V017 | DT-3 | Arbitrary Datum | Unspendable UTxOs, datum-hash bricking | No datum validation; hash-only datum accepted | out.datum.inlineOrFail[T](msg); out.hasInlineDatum(x) |
| V024 | AU-6 | Parameterization Verification | Script substitution (varies) | ParameterizedValidator with auth params, no token | auth NFT via hasNft + one-shot policy; design |
| V033 | PU-4 | Voting / Proposing Purposes Unguarded | Governance actions approved silently | Hand-written ScriptInfo dispatcher with case _ => () | plugin default fail; explicit vote / propose with authorization |
| V034 | VP-5 | Value-Map Normalisation | Locked UTxO or false equality on a non-canonical Value | Value field in datum/redeemer compared with === | Value.valueFromDataWithValidation at the boundary; ledger values are canonical |
| V035 | VP-6 | Min-ADA Griefing | Forced output pushed below min-ADA, UTxO stuck | Whole-value preservation on a UTxO anyone can pay into | bound the token set at deposit: withoutLovelace.isZero, hasSameTokensAndAtLeastAda |
| V036 | DE-4 | Hash Grinding | Attacker grinds a hash-derived outcome | tx.id / out-ref hash used as randomness | design: commit-reveal |
| ID | Taxonomy | Name | Risk | Detection | Fixed by |
|---|---|---|---|---|---|
| V018 | RS-1 | Unbounded Value | UTxO size limit, min-ADA lever | Unlimited tokens in output | withoutLovelace.isZero; hasSameTokensAndAtLeastAda pins the token set |
| V019 | RS-2 | Unbounded Datum | Resource exhaustion | Growing datum size | design: bound every list |
| V020 | RS-3 | Unbounded Inputs | TX limit exceeded | Many required UTxOs | design: batching |
| V021 | RS-5 | UTxO Contention / Concurrency DoS | Bottleneck, DoS | Shared global state, no rate limit | design: per-user UTxOs |
| V022 | RS-6 | Cheap Spam/Dust | Operation obstruction | No minimum amounts | design: minimum require |
| V023 | DE-1 | Locked Value | Permanent lock | Missing exit paths | design: exit path per state |
| V037 | RS-7 | Reference-Script Size | Fee blow-up, size cap exceeded | Large compiled scripts, many per transaction | design: report script size, split logic |
Checklist rules:
object does not define is completed by the compiler
plugin with a body that fails, so an undefined purpose is never an entry point. Report only
purposes the object defines.Address.fromScriptHash never proves the
continuing output; only the whole address does..getLovelace, ask whether tokens can be in the
UTxO before asking whether one output can serve two inputs.getValidityStartTime is a finding; a validFromOrFail / validToOrFail is not.hasSameTokensAndAtLeastAda is both.Before you report a vulnerability, verify that it is exploitable: trace the code with a concrete attack transaction. A pattern match alone produces false positives.
For each potential vulnerability:
Construct a concrete attack transaction
Execute the validator logic mentally with this transaction
require() statement - does it pass or fail?If a require fails, the attack fails: the finding is a false positive.
Report the finding only if every require passes with the attack transaction.
Potential vulnerability detected: handlePay sums the seller's outputs by credential without unique linking.
Construct attack transaction:
Inputs:
- EscrowA: 12 ADA, datum={seller=S, buyer=B, escrowAmount=10, initAmount=2}
- EscrowB: 12 ADA, datum={seller=S, buyer=B, escrowAmount=10, initAmount=2}
Outputs:
- 12 ADA to seller S (single output for both!)
- 1 ADA to buyer B
Signatories: [B]
Trace execution for EscrowA:
// Line 58-61, before any handler:
txInfo.inputs.findUniqueOrFail(
_.resolved.address.credential === contractAddress.credential,
"Exactly one escrow input may be spent"
)
// → inputs at the script credential: [EscrowA, EscrowB] → two matches → FAILS ❌
// Line 63: never reached
val contractBalance = txInfo.valueSpentFrom(contractAddress).getLovelace
Result: Attack transaction fails at line 58-61. V005 is a FALSE POSITIVE.
Second look at the same lines (V027): contractBalance and the seller sum are compared on
.getLovelace only. Attack transaction 2: EscrowA holds 12 ADA + 500 USDM; outputs 12 ADA to S
and 500 USDM to B. Both lovelace checks pass, the tokens leave. This is a V027 finding unless
the contract proves the UTxO is ADA-only at the boundary; EscrowValidator does
(handleDeposit: txInfo.valuePaidTo(contractAddress) === Value.lovelace(escrowAmount + initializationAmount)),
so here it is not reported. Without that proof, report it.
If the attack trace is complex or you're uncertain, write an actual test:
test("V005: Double satisfaction attack should fail") {
// Setup: Create two escrow UTxOs with same seller
val escrowA = createEscrowUtxo(seller = S, buyer = B, amount = 10.ada)
val escrowB = createEscrowUtxo(seller = S, buyer = B, amount = 10.ada)
// Attack: Try to spend both with single output to seller
val attackTx = Transaction(
inputs = List(escrowA, escrowB),
outputs = List(TxOut(sellerAddress, 12.ada)), // Only pay once!
redeemers = Map(escrowA -> Pay, escrowB -> Pay)
)
// Verify: Should this pass or fail?
// If it passes → Real vulnerability
// If it fails → False positive
evaluateValidator(EscrowValidator, escrowA, attackTx) shouldBe failure
}
Before reporting, answer these questions:
| Question | Answer Required |
|---|---|
| What is the specific attack transaction? | Inputs, outputs, redeemers, signatories |
| Which line would the attacker exploit? | File:line reference |
| Did you trace through EVERY require in the code path? | Yes/No |
| Does the attack pass ALL requires? | Yes (report) / No (false positive) |
| What value does the attacker gain? | Concrete amount/asset |
These rules apply to attack findings. A liveness finding (V039, V023) needs a traced honest transaction that the validator rejects instead.
require() in the code path would fail the attackUse clickable file_path:line_number format for all code locations.
For each vulnerability found, output in this format:
### [SEVERITY] ID: Vulnerability Name
**Location:** `full/path/to/File.scala:LINE`
**Method:** methodName
**Issue:** Brief description of what's wrong
**Vulnerable code** (`full/path/to/File.scala:LINE-LINE`):
```scala
// actual code from file
Fix:
// proposed fix
### Summary Table
At the end, provide a summary with clickable locations:
| ID | Severity | Location | Issue | Status |
|---|---|---|---|---|
| C-01 | Critical | path/File.scala:123 | Missing mint validation | Fixed |
| H-01 | High | path/File.scala:87 | Token not in output | Declined |
| M-01 | Medium | path/File.scala:200 | Missing signature | False Positive |
| ID | Location | Reason |
|---|---|---|
| M-01 | path/File.scala:200 | Authorization is done via NFT ownership in verifyAuth helper |
Security Grade: A/B/C/D/F
### Location Format Rules
1. Always use full path from project root: `scalus-examples/jvm/src/.../File.scala:123`
2. For ranges use: `File.scala:123-145`
3. For method references: `File.scala:123` (methodName)
4. Make locations clickable by using backticks
## Interactive Workflow
For each finding:
1. Display issue with location and proposed fix
2. Prompt: "Apply fix? [y/n/s/d/f]"
- y: Apply fix, mark completed, verify with `sbtn compile`
- n: Skip, log as "declined"
- s: Skip without logging
- d: Show more details (attack scenario)
- f: Mark as false positive (prompts for reason, logged to summary)
3. After all findings: run `sbtn quick` to verify fixes
4. Generate summary report including:
- Fixed issues
- Declined issues
- False positives with reasons
## Reference
For detailed vulnerability patterns and code examples, see:
- `references/vulnerabilities.md` - Full pattern documentation with Scalus-specific examples
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
cardano, scalus, smart-contract-audit, plutus, validator-analysis
7 skills in this plugin
/contractGuide for developing Scalus smart contracts. Use when writing or modifying Cardano validators in Scala 3 with Scalus./contract-testGuide for testing Scalus smart contracts. Use when writing unit, property, budget, or Emulator tests for Cardano validators./local-developmentUse when developing or testing Scalus smart contracts with the local Emulator and TxBuilder. Covers how to create an Emulator provider, submit transactions, test negative validator cases, and test confirmation delay and rollbacks.npx claudepluginhub scalus3/scalus --plugin scalusOther plugins' skills for the same job