Module M004
Advanced Input Validation
DirectEd x CATS Hackathon
Aiken Development Workshop Series
Duration: 2 hours
Format: 1 hour lecture + 1 hour exercises
Advanced Input Validation
DirectEd x CATS Hackathon
Aiken Development Workshop Series
Duration: 2 hours
Format: 1 hour lecture + 1 hour exercises
In M003, you learned various validation techniques. Now we focus deep on one critical aspect: INPUT VALIDATION.
Inputs are the UTxOs being consumed in a transaction.
Use find_input() to locate which UTxO your validator is checking.
find_input(inputs, ref) returns Option<Input>
Filter inputs to find how many are from your script address.
inputs_at(inputs, address) returns List<Input>
The most dangerous validator vulnerability!
2 UTxOs
Same Validator
Each requires
5 ADA payment
Attacker Pays
5 ADA ONCE
But validator checks
global outputs
BOTH Unlock!
Exploit Success
Attacker gets
2x value for 1x cost
Step-by-step attack scenario:
Bob locks 2 UTxOs at vulnerable validator:
Solution: Ensure only ONE input from your validator per transaction.
Vodka provides a utility that does both checks in one:
Check that inputs contain the expected ADA and tokens.
Access inline datums from transaction inputs.
InlineDatum(data) → cast to type → validate fields
Combining all techniques for production-ready validators:
Test all scenarios to ensure your validator is secure:
Test with exactly 1 script input (should pass)
Test with 2+ script inputs (should fail - double-satisfaction)
Test with sufficient ADA and tokens (should pass)
Test with too little ADA or tokens (should fail)
Test with valid and invalid datum fields
Time to build secure validators! 🔒
Filter inputs by script address and ensure single input
Build payment validator with double-satisfaction prevention
Validate minimum ADA and token requirements
Extract and validate inline datums from inputs
Combine ALL techniques into production-ready validator
Check: Input reference matches, address is correct, not multiple inputs
Verify: Policy ID and asset name are correct hex-encoded ByteArrays
Use pattern matching: expect InlineDatum(data) = output.datum
You can now:
✅ Understand transaction input structure
✅ Prevent double-satisfaction attacks
✅ Filter inputs by script address
✅ Validate input values (ADA & tokens)
✅ Extract and validate input datums
✅ Implement production-ready input patterns
✅ Write comprehensive input validation tests
single_script_input() in every validatorModule M004 Complete
You can now build secure validators with proper input validation!
Your contracts are now safe from double-satisfaction 🛡️
See you in M005! 🚀