| name | security-review |
| description | Security review for blockchain and cryptographic code. Use when reviewing PRs, auditing code, checking for vulnerabilities, or when security is mentioned. |
| allowed-tools | Read, Grep, Glob |
Security Review
Checklist for reviewing ZChain code for security issues.
Cryptographic Security
Hash Function Usage
// GOOD: All block data in hash
var hashInput = $"{block.Height}{block.ParentHash}{block.Transaction}{nonce}";
// BAD: Missing fields allows hash collision attacks
var hashInput = $"{nonce}";
Random Number Generation
// GOOD: Cryptographically secure
using var rng = RandomNumberGenerator.Create();
byte[] bytes = new byte[32];
rng.GetBytes(bytes);
// BAD: Predictable
var random = new Random();
Blockchain Integrity
Block Validation
State Machine Security
Concurrency Issues
Thread Safety
// GOOD: Thread-safe mined value setting
lock (_minedLock)
{
if (State == BlockState.Mined) return;
_hash = hash;
_nonce = nonce;
State = BlockState.Mined;
}
Cancellation
Input Validation
Public API Boundaries
// GOOD: Proper validation
public Block(T transaction, int difficulty)
{
ArgumentNullException.ThrowIfNull(transaction);
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(difficulty);
}
Sensitive Data
Logging and Output
Serialization
// BAD: Allows arbitrary type instantiation
JsonConvert.DeserializeObject<Block>(json, new JsonSerializerSettings {
TypeNameHandling = TypeNameHandling.All // DANGEROUS
});
// GOOD: Explicit type, no type handling
JsonConvert.DeserializeObject<Block<MoneyTransferTransaction>>(json);
Dependency Security
Review Commands
# Search for potential issues
grep -r "Random()" src/
grep -r "MD5\|SHA1" src/
grep -r "TypeNameHandling" src/
grep -r "Process.Start\|Shell" src/
# Check for hardcoded secrets
grep -r "password\|secret\|key\|token" src/ --include="*.cs"
Severity Levels
| Level |
Description |
Action |
| Critical |
Exploitable vulnerability |
Block merge, fix immediately |
| High |
Security weakness |
Should fix before merge |
| Medium |
Defense in depth issue |
Track for future fix |
| Low |
Best practice deviation |
Note in review |