[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CH66VF1V7AZ3EKZW6P84EC":3,"skill-same:01M7CH66VF1V7AZ3EKZW6P84EC":60},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M7CH66VF1V7AZ3EKZW6P84EC","substrate-vulnerability-scanner",null,"Scans Substrate\u002FPolkadot pallets for 7 critical vulnerabilities including arithmetic overflow, panic DoS, incorrect weights, and bad origin checks. Use when auditing Substrate runtimes or FRAME pallets.","bongkage\u002Ftrailofbits-skills","bongkage","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F101378796?v=4","01M7CH419QTJ16DNJ33P0WCWBE","01M7CH41A9NWK8D2JBRK9F0M2C",1,"CC-BY-SA-4.0","https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fbuilding-secure-contracts\u002Fskills\u002Fsubstrate-vulnerability-scanner\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: substrate-vulnerability-scanner\ndescription: Scans Substrate\u002FPolkadot pallets for 7 critical vulnerabilities including arithmetic overflow, panic DoS, incorrect weights, and bad origin checks. Use when auditing Substrate runtimes or FRAME pallets.\n---\n\n# Substrate Vulnerability Scanner\n\n## 1. Purpose\n\nSystematically scan Substrate runtime modules (pallets) for platform-specific security vulnerabilities that can cause node crashes, DoS attacks, or unauthorized access. This skill encodes 7 critical vulnerability patterns unique to Substrate\u002FFRAME-based chains.\n\n## 2. When to Use This Skill\n\n- Auditing custom Substrate pallets\n- Reviewing FRAME runtime code\n- Pre-launch security assessment of Substrate chains (Polkadot parachains, standalone chains)\n- Validating dispatchable extrinsic functions\n- Reviewing weight calculation functions\n- Assessing unsigned transaction validation logic\n\n## 3. Platform Detection\n\n### File Extensions & Indicators\n- **Rust files**: `.rs`\n\n### Language\u002FFramework Markers\n```rust\n\u002F\u002F Substrate\u002FFRAME indicators\n#[pallet]\npub mod pallet {\n    use frame_support::pallet_prelude::*;\n    use frame_system::pallet_prelude::*;\n\n    #[pallet::config]\n    pub trait Config: frame_system::Config { }\n\n    #[pallet::call]\n    impl\u003CT: Config> Pallet\u003CT> {\n        #[pallet::weight(10_000)]\n        pub fn example_function(origin: OriginFor\u003CT>) -> DispatchResult { }\n    }\n}\n\n\u002F\u002F Common patterns\nDispatchResult, DispatchError\nensure!, ensure_signed, ensure_root\nStorageValue, StorageMap, StorageDoubleMap\n#[pallet::storage]\n#[pallet::call]\n#[pallet::weight]\n#[pallet::validate_unsigned]\n```\n\n### Project Structure\n- `pallets\u002F*\u002Flib.rs` - Pallet implementations\n- `runtime\u002Flib.rs` - Runtime configuration\n- `benchmarking.rs` - Weight benchmarks\n- `Cargo.toml` with `frame-*` dependencies\n\n### Tool Support\n- **cargo-fuzz**: Fuzz testing for Rust\n- **test-fuzz**: Property-based testing framework\n- **benchmarking framework**: Built-in weight calculation\n- **try-runtime**: Runtime migration testing\n\n---\n\n## 4. How This Skill Works\n\nWhen invoked, I will:\n\n1. **Search your codebase** for Substrate pallets\n2. **Analyze each pallet** for the 7 vulnerability patterns\n3. **Report findings** with file references and severity, above them a coverage table carrying a verdict for every pattern\n4. **Provide fixes** for each identified issue\n5. **Check weight calculations** and origin validation\n\n---\n\n## 5. Vulnerability Patterns (7 Critical Patterns)\n\nI check for 7 critical vulnerability patterns unique to Substrate\u002FFRAME. For detailed detection patterns, code examples, mitigations, and testing strategies, see [VULNERABILITY_PATTERNS.md](resources\u002FVULNERABILITY_PATTERNS.md).\n\n### Pattern Summary:\n\n1. **Arithmetic Overflow** ⚠️ CRITICAL\n   - Direct `+`, `-`, `*`, `\u002F` operators wrap in release mode\n   - Must use `checked_*` or `saturating_*` methods\n   - Affects balance\u002Ftoken calculations, reward\u002Ffee math\n\n2. **Don't Panic** ⚠️ CRITICAL - DoS\n   - Panics cause node to stop processing blocks\n   - No `unwrap()`, `expect()`, array indexing without bounds check\n   - All user input must be validated with `ensure!`\n\n3. **Weights and Fees** ⚠️ CRITICAL - DoS\n   - Incorrect weights allow spam attacks\n   - Fixed weights for variable-cost operations enable DoS\n   - Must use benchmarking framework, bound all input parameters\n\n4. **Verify First, Write Last** ⚠️ HIGH (Pre-v0.9.25)\n   - Storage writes before validation persist on error (pre-v0.9.25)\n   - Pattern: validate → write → emit event\n   - Upgrade to v0.9.25+ or use manual `#[transactional]`\n\n5. **Unsigned Transaction Validation** ⚠️ HIGH\n   - Insufficient validation allows spam\u002Freplay attacks\n   - Prefer signed transactions\n   - If unsigned: validate parameters, replay protection, authenticate source\n\n6. **Bad Randomness** ⚠️ MEDIUM\n   - `pallet_randomness_collective_flip` vulnerable to collusion\n   - Must use BABE randomness (`pallet_babe::RandomnessFromOneEpochAgo`)\n   - Use `random(subject)` not `random_seed()`\n\n7. **Bad Origin** ⚠️ CRITICAL\n   - `ensure_signed` allows any user for privileged operations\n   - Must use `ensure_root` or custom origins (ForceOrigin, AdminOrigin)\n   - Origin types must be properly configured in runtime\n\nFor complete vulnerability patterns with code examples, see [VULNERABILITY_PATTERNS.md](resources\u002FVULNERABILITY_PATTERNS.md).\n\n---\n\n## 6. Scanning Workflow\n\n### Step 1: Platform Identification\n1. Verify Substrate\u002FFRAME framework usage\n2. Check Substrate version (v0.9.25+ has transactional storage)\n3. Locate pallet implementations (`pallets\u002F*\u002Flib.rs`)\n4. Identify runtime configuration (`runtime\u002Flib.rs`)\n\n### Step 2: Dispatchable Analysis\nFor each `#[pallet::call]` function:\n- [ ] Arithmetic: Uses checked\u002Fsaturating operations?\n- [ ] Panics: No unwrap\u002Fexpect\u002Findexing?\n- [ ] Weights: Proportional to cost, bounded inputs?\n- [ ] Origin: Appropriate validation level?\n- [ ] Validation: All checks before storage writes?\n\n### Step 3: Panic Sweep\n```bash\n# Search for panic-prone patterns\nrg \"unwrap\\(\\)\" pallets\u002F\nrg \"expect\\(\" pallets\u002F\nrg \"\\[.*\\]\" pallets\u002F  # Array indexing\nrg \" as u\\d+\" pallets\u002F  # Type casts\nrg \"\\.unwrap_or\" pallets\u002F\n```\n\n### Step 4: Arithmetic Safety Check\n```bash\n# Find direct arithmetic\nrg \" \\+ |\\+=| - |-=| \\* |\\*=| \u002F |\u002F=\" pallets\u002F\n\n# Should find checked\u002Fsaturating alternatives instead\nrg \"checked_add|checked_sub|checked_mul|checked_div\" pallets\u002F\nrg \"saturating_add|saturating_sub|saturating_mul\" pallets\u002F\n```\n\n### Step 5: Weight Analysis\n- [ ] Run benchmarking: `cargo test --features runtime-benchmarks`\n- [ ] Verify weights match computational cost\n- [ ] Check for bounded input parameters\n- [ ] Review weight calculation functions\n\n### Step 6: Origin & Privilege Review\n```bash\n# Find privileged operations\nrg \"ensure_signed\" pallets\u002F | grep -E \"pause|emergency|admin|force|sudo\"\n\n# Should use ensure_root or custom origins\nrg \"ensure_root|ForceOrigin|AdminOrigin\" pallets\u002F\n```\n\n### Step 7: Testing Review\n- [ ] Unit tests cover all dispatchables\n- [ ] Fuzz tests for panic conditions\n- [ ] Benchmarks for weight calculation\n- [ ] try-runtime tests for migrations\n\n### Step 8: Report Coverage\n\nReport on every pattern in §5, whether or not it turned anything up. This skill has no Finding Template, so the\ntable opens the report and the findings follow it, with all 7 rows present:\n\n| # | Pattern | Verdict | Evidence |\n|---|---------|---------|----------|\n| 1 | Arithmetic Overflow | `found` | `src\u002Flib.rs:212` -- `+` on `BalanceOf\u003CT>` in `do_transfer` |\n| 2 | Don't Panic | | |\n| 3 | Weights and Fees | | |\n| 4 | Verify First, Write Last | | |\n| 5 | Unsigned Transaction Validation | | |\n| 6 | Bad Randomness | | |\n| 7 | Bad Origin | | |\n\nEach verdict is one of:\n\n- **`found`** — cite `file:line` and write the finding up in full after the table.\n- **`clear`** — the pattern applies to this pallet and the pallet handles it. Name the macro, origin check, or\n  arithmetic method you searched for, so a reader can repeat the search.\n- **`n\u002Fa`** — the pattern cannot apply here. Give the reason in one clause (\"this pallet accepts no unsigned\n  transactions\"). Not having looked is not `n\u002Fa`. Note that pattern 4 is version-scoped (pre-v0.9.25): say\n  which runtime version the pallet targets rather than dropping the row.\n\nA table with fewer than 7 rows is an incomplete scan and must be reported as one. A row whose Verdict cell is empty is incomplete in the same way: row 1 above is filled in to show the shape, and every row is filled in the same way before the report is done. Seven `clear` verdicts is a\nresult a reader can act on. A report that covers three patterns and says nothing about the other four reads\nexactly like a clean pallet, and that is the failure this table exists to prevent.\n\n---\n\n## 7. Priority Guidelines\n\n### Critical (Immediate Fix Required)\n- Arithmetic overflow (token creation, balance manipulation)\n- Panic DoS (node crash risk)\n- Bad origin (unauthorized privileged operations)\n\n### High (Fix Before Launch)\n- Incorrect weights (DoS via spam)\n- Verify-first violations (state corruption, pre-v0.9.25)\n- Unsigned validation issues (spam, replay attacks)\n\n### Medium (Address in Audit)\n- Bad randomness (manipulation possible but limited impact)\n\n---\n\n## 8. Testing Recommendations\n\n### Fuzz Testing\n```rust\n\u002F\u002F Use test-fuzz for property-based testing\n#[cfg(test)]\nmod tests {\n    use test_fuzz::test_fuzz;\n\n    #[test_fuzz]\n    fn fuzz_transfer(from: AccountId, to: AccountId, amount: u128) {\n        \u002F\u002F Should never panic\n        let _ = Pallet::transfer(from, to, amount);\n    }\n\n    #[test_fuzz]\n    fn fuzz_no_panics(call: Call) {\n        \u002F\u002F No dispatchable should panic\n        let _ = call.dispatch(origin);\n    }\n}\n```\n\n### Benchmarking\n```bash\n# Run benchmarks to generate weights\ncargo build --release --features runtime-benchmarks\n.\u002Ftarget\u002Frelease\u002Fnode benchmark pallet \\\n    --chain dev \\\n    --pallet pallet_example \\\n    --extrinsic \"*\" \\\n    --steps 50 \\\n    --repeat 20\n```\n\n### try-runtime\n```bash\n# Test runtime upgrades\ncargo build --release --features try-runtime\ntry-runtime --runtime .\u002Ftarget\u002Frelease\u002Fwbuild\u002Fruntime.wasm \\\n    on-runtime-upgrade live --uri wss:\u002F\u002Frpc.polkadot.io\n```\n\n---\n\n## 9. Additional Resources\n\n- **Building Secure Contracts**: `building-secure-contracts\u002Fnot-so-smart-contracts\u002Fsubstrate\u002F`\n- **Substrate Documentation**: https:\u002F\u002Fdocs.substrate.io\u002F\n- **FRAME Documentation**: https:\u002F\u002Fparitytech.github.io\u002Fsubstrate\u002Fmaster\u002Fframe_support\u002F\n- **test-fuzz**: https:\u002F\u002Fgithub.com\u002Ftrailofbits\u002Ftest-fuzz\n- **Substrate StackExchange**: https:\u002F\u002Fsubstrate.stackexchange.com\u002F\n\n---\n\n## 10. Quick Reference Checklist\n\nBefore completing Substrate pallet audit:\n\n**Arithmetic Safety (CRITICAL)**:\n- [ ] No direct `+`, `-`, `*`, `\u002F` operators in dispatchables\n- [ ] All arithmetic uses `checked_*` or `saturating_*`\n- [ ] Type conversions use `try_into()` with error handling\n\n**Panic Prevention (CRITICAL)**:\n- [ ] No `unwrap()` or `expect()` in dispatchables\n- [ ] No direct array\u002Fslice indexing without bounds check\n- [ ] All user inputs validated with `ensure!`\n- [ ] Division operations check for zero divisor\n\n**Weights & DoS (CRITICAL)**:\n- [ ] Weights proportional to computational cost\n- [ ] Input parameters have maximum bounds\n- [ ] Benchmarking used to determine weights\n- [ ] No free (zero-weight) expensive operations\n\n**Access Control (CRITICAL)**:\n- [ ] Privileged operations use `ensure_root` or custom origins\n- [ ] `ensure_signed` only for user-level operations\n- [ ] Origin types properly configured in runtime\n- [ ] Sudo pallet removed before production\n\n**Storage Safety (HIGH)**:\n- [ ] Using Substrate v0.9.25+ OR manual `#[transactional]`\n- [ ] Validation before storage writes\n- [ ] Events emitted after successful operations\n\n**Other (MEDIUM)**:\n- [ ] Unsigned transactions use signed alternative if possible\n- [ ] If unsigned: proper validation, replay protection, authentication\n- [ ] BABE randomness used (not RandomnessCollectiveFlip)\n- [ ] Randomness uses `random(subject)` not `random_seed()`\n\n**Testing**:\n- [ ] Unit tests for all dispatchables\n- [ ] Fuzz tests to find panics\n- [ ] Benchmarks generated and verified\n- [ ] try-runtime tests for migrations\n- [ ] Coverage table emitted with all 7 rows, each carrying a verdict of `found`, `clear` or `n\u002Fa` with a reason\n\n---\n\n## 11. Rationalizations to Reject\n\n- **\"The pallet is small, so most patterns obviously don't apply.\"** Obvious to whom? An `n\u002Fa` costs one\n  clause and makes the judgment reviewable. Silence records nothing, and a reader cannot tell it apart from\n  not having checked.\n- **\"It compiles without warnings, so the arithmetic is fine.\"** Release builds wrap silently. `+` on a\n  `Balance` is pattern 1 whether or not the compiler said anything, and debug assertions do not run on a\n  production node.\n- **\"I checked the patterns that matter for this pallet.\"** Deciding which patterns matter *is* the scan,\n  not a precondition for starting it. Rank by severity after the table is complete, not by leaving rows out.\n- **\"No findings, so there is nothing to report.\"** A zero-finding scan still emits the full coverage table.\n  That table is the deliverable: it is what distinguishes a pallet that was examined from one that was\n  glanced at.\n- **\"`ensure_signed` is an origin check.\"** It establishes that *someone* signed, not that the right someone\n  did. Pattern 7 is about which origin is required, and `ensure_signed` where `ensure_root` belongs passes\n  this rationalization while failing the check.\n- **\"The weight is benchmarked, so it's correct.\"** Benchmarks measure the path they exercise. A dispatchable\n  whose worst case depends on storage size or an unbounded loop is pattern 3 even with a benchmark attached.\n","# Substrate Vulnerability Scanner\n\n## 1. Purpose\n\nSystematically scan Substrate runtime modules (pallets) for platform-specific security vulnerabilities that can cause node crashes, DoS attacks, or unauthorized access. This skill encodes 7 critical vulnerability patterns unique to Substrate\u002FFRAME-based chains.\n\n## 2. When to Use This Skill\n\n- Auditing custom Substrate pallets\n- Reviewing FRAME runtime code\n- Pre-launch security assessment of Substrate chains (Polkadot parachains, standalone chains)\n- Validating dispatchable extrinsic functions\n- Reviewing weight calculation functions\n- Assessing unsigned transaction validation logic\n\n## 3. Platform Detection\n\n### File Extensions & Indicators\n- **Rust files**: `.rs`\n\n### Language\u002FFramework Markers\n```rust\n\u002F\u002F Substrate\u002FFRAME indicators\n#[pallet]\npub mod pallet {\n    use frame_support::pallet_prelude::*;\n    use frame_system::pallet_prelude::*;\n\n    #[pallet::config]\n    pub trait Config: frame_system::Config { }\n\n    #[pallet::call]\n    impl\u003CT: Config> Pallet\u003CT> {\n        #[pallet::weight(10_000)]\n        pub fn example_function(origin: OriginFor\u003CT>) -> DispatchResult { }\n    }\n}\n\n\u002F\u002F Common patterns\nDispatchResult, DispatchError\nensure!, ensure_signed, ensure_root\nStorageValue, StorageMap, StorageDoubleMap\n#[pallet::storage]\n#[pallet::call]\n#[pallet::weight]\n#[pallet::validate_unsigned]\n```\n\n### Project Structure\n- `pallets\u002F*\u002Flib.rs` - Pallet implementations\n- `runtime\u002Flib.rs` - Runtime configuration\n- `benchmarking.rs` - Weight benchmarks\n- `Cargo.toml` with `frame-*` dependencies\n\n### Tool Support\n- **cargo-fuzz**: Fuzz testing for Rust\n- **test-fuzz**: Property-based testing framework\n- **benchmarking framework**: Built-in weight calculation\n- **try-runtime**: Runtime migration testing\n\n---\n\n## 4. How This Skill Works\n\nWhen invoked, I will:\n\n1. **Search your codebase** for Substrate pallets\n2. **Analyze each pallet** for the 7 vulnerability patterns\n3. **Report findings** with file references and severity, above them a coverage table carrying a verdict for every pattern\n4. **Provide fixes** for each identified issue\n5. **Check weight calculations** and origin validation\n\n---\n\n## 5. Vulnerability Patterns (7 Critical Patterns)\n\nI check for 7 critical vulnerability patterns unique to Substrate\u002FFRAME. For detailed detection patterns, code examples, mitigations, and testing strategies, see [VULNERABILITY_PATTERNS.md](resources\u002FVULNERABILITY_PATTERNS.md).\n\n### Pattern Summary:\n\n1. **Arithmetic Overflow** ⚠️ CRITICAL\n   - Direct `+`, `-`, `*`, `\u002F` operators wrap in release mode\n   - Must use `checked_*` or `saturating_*` methods\n   - Affects balance\u002Ftoken calculations, reward\u002Ffee math\n\n2. **Don't Panic** ⚠️ CRITICAL - DoS\n   - Panics cause node to stop processing blocks\n   - No `unwrap()`, `expect()`, array indexing without bounds check\n   - All user input must be validated with `ensure!`\n\n3. **Weights and Fees** ⚠️ CRITICAL - DoS\n   - Incorrect weights allow spam attacks\n   - Fixed weights for variable-cost operations enable DoS\n   - Must use benchmarking framework, bound all input parameters\n\n4. **Verify First, Write Last** ⚠️ HIGH (Pre-v0.9.25)\n   - Storage writes before validation persist on error (pre-v0.9.25)\n   - Pattern: validate → write → emit event\n   - Upgrade to v0.9.25+ or use manual `#[transactional]`\n\n5. **Unsigned Transaction Validation** ⚠️ HIGH\n   - Insufficient validation allows spam\u002Freplay attacks\n   - Prefer signed transactions\n   - If unsigned: validate parameters, replay protection, authenticate source\n\n6. **Bad Randomness** ⚠️ MEDIUM\n   - `pallet_randomness_collective_flip` vulnerable to collusion\n   - Must use BABE randomness (`pallet_babe::RandomnessFromOneEpochAgo`)\n   - Use `random(subject)` not `random_seed()`\n\n7. **Bad Origin** ⚠️ CRITICAL\n   - `ensure_signed` allows any user for privileged operations\n   - Must use `ensure_root` or custom origins (ForceOrigin, AdminOrigin)\n   - Origin types must be properly configured in runtime\n\nFor complete vulnerability patterns with code examples, see [VULNERABILITY_PATTERNS.md](resources\u002FVULNERABILITY_PATTERNS.md).\n\n---\n\n## 6. Scanning Workflow\n\n### Step 1: Platform Identification\n1. Verify Substrate\u002FFRAME framework usage\n2. Check Substrate version (v0.9.25+ has transactional storage)\n3. Locate pallet implementations (`pallets\u002F*\u002Flib.rs`)\n4. Identify runtime configuration (`runtime\u002Flib.rs`)\n\n### Step 2: Dispatchable Analysis\nFor each `#[pallet::call]` function:\n- [ ] Arithmetic: Uses checked\u002Fsaturating operations?\n- [ ] Panics: No unwrap\u002Fexpect\u002Findexing?\n- [ ] Weights: Proportional to cost, bounded inputs?\n- [ ] Origin: Appropriate validation level?\n- [ ] Validation: All checks before storage writes?\n\n### Step 3: Panic Sweep\n```bash\n# Search for panic-prone patterns\nrg \"unwrap\\(\\)\" pallets\u002F\nrg \"expect\\(\" pallets\u002F\nrg \"\\[.*\\]\" pallets\u002F  # Array indexing\nrg \" as u\\d+\" pallets\u002F  # Type casts\nrg \"\\.unwrap_or\" pallets\u002F\n```\n\n### Step 4: Arithmetic Safety Check\n```bash\n# Find direct arithmetic\nrg \" \\+ |\\+=| - |-=| \\* |\\*=| \u002F |\u002F=\" pallets\u002F\n\n# Should find checked\u002Fsaturating alternatives instead\nrg \"checked_add|checked_sub|checked_mul|checked_div\" pallets\u002F\nrg \"saturating_add|saturating_sub|saturating_mul\" pallets\u002F\n```\n\n### Step 5: Weight Analysis\n- [ ] Run benchmarking: `cargo test --features runtime-benchmarks`\n- [ ] Verify weights match computational cost\n- [ ] Check for bounded input parameters\n- [ ] Review weight calculation functions\n\n### Step 6: Origin & Privilege Review\n```bash\n# Find privileged operations\nrg \"ensure_signed\" pallets\u002F | grep -E \"pause|emergency|admin|force|sudo\"\n\n# Should use ensure_root or custom origins\nrg \"ensure_root|ForceOrigin|AdminOrigin\" pallets\u002F\n```\n\n### Step 7: Testing Review\n- [ ] Unit tests cover all dispatchables\n- [ ] Fuzz tests for panic conditions\n- [ ] Benchmarks for weight calculation\n- [ ] try-runtime tests for migrations\n\n### Step 8: Report Coverage\n\nReport on every pattern in §5, whether or not it turned anything up. This skill has no Finding Template, so the\ntable opens the report and the findings follow it, with all 7 rows present:\n\n| # | Pattern | Verdict | Evidence |\n|---|---------|---------|----------|\n| 1 | Arithmetic Overflow | `found` | `src\u002Flib.rs:212` -- `+` on `BalanceOf\u003CT>` in `do_transfer` |\n| 2 | Don't Panic | | |\n| 3 | Weights and Fees | | |\n| 4 | Verify First, Write Last | | |\n| 5 | Unsigned Transaction Validation | | |\n| 6 | Bad Randomness | | |\n| 7 | Bad Origin | | |\n\nEach verdict is one of:\n\n- **`found`** — cite `file:line` and write the finding up in full after the table.\n- **`clear`** — the pattern applies to this pallet and the pallet handles it. Name the macro, origin check, or\n  arithmetic method you searched for, so a reader can repeat the search.\n- **`n\u002Fa`** — the pattern cannot apply here. Give the reason in one clause (\"this pallet accepts no unsigned\n  transactions\"). Not having looked is not `n\u002Fa`. Note that pattern 4 is version-scoped (pre-v0.9.25): say\n  which runtime version the pallet targets rather than dropping the row.\n\nA table with fewer than 7 rows is an incomplete scan and must be reported as one. A row whose Verdict cell is empty is incomplete in the same way: row 1 above is filled in to show the shape, and every row is filled in the same way before the report is done. Seven `clear` verdicts is a\nresult a reader can act on. A report that covers three patterns and says nothing about the other four reads\nexactly like a clean pallet, and that is the failure this table exists to prevent.\n\n---\n\n## 7. Priority Guidelines\n\n### Critical (Immediate Fix Required)\n- Arithmetic overflow (token creation, balance manipulation)\n- Panic DoS (node crash risk)\n- Bad origin (unauthorized privileged operations)\n\n### High (Fix Before Launch)\n- Incorrect weights (DoS via spam)\n- Verify-first violations (state corruption, pre-v0.9.25)\n- Unsigned validation issues (spam, replay attacks)\n\n### Medium (Address in Audit)\n- Bad randomness (manipulation possible but limited impact)\n\n---\n\n## 8. Testing Recommendations\n\n### Fuzz Testing\n```rust\n\u002F\u002F Use test-fuzz for property-based testing\n#[cfg(test)]\nmod tests {\n    use test_fuzz::test_fuzz;\n\n    #[test_fuzz]\n    fn fuzz_transfer(from: AccountId, to: AccountId, amount: u128) {\n        \u002F\u002F Should never panic\n        let _ = Pallet::transfer(from, to, amount);\n    }\n\n    #[test_fuzz]\n    fn fuzz_no_panics(call: Call) {\n        \u002F\u002F No dispatchable should panic\n        let _ = call.dispatch(origin);\n    }\n}\n```\n\n### Benchmarking\n```bash\n# Run benchmarks to generate weights\ncargo build --release --features runtime-benchmarks\n.\u002Ftarget\u002Frelease\u002Fnode benchmark pallet \\\n    --chain dev \\\n    --pallet pallet_example \\\n    --extrinsic \"*\" \\\n    --steps 50 \\\n    --repeat 20\n```\n\n### try-runtime\n```bash\n# Test runtime upgrades\ncargo build --release --features try-runtime\ntry-runtime --runtime .\u002Ftarget\u002Frelease\u002Fwbuild\u002Fruntime.wasm \\\n    on-runtime-upgrade live --uri wss:\u002F\u002Frpc.polkadot.io\n```\n\n---\n\n## 9. Additional Resources\n\n- **Building Secure Contracts**: `building-secure-contracts\u002Fnot-so-smart-contracts\u002Fsubstrate\u002F`\n- **Substrate Documentation**: https:\u002F\u002Fdocs.substrate.io\u002F\n- **FRAME Documentation**: https:\u002F\u002Fparitytech.github.io\u002Fsubstrate\u002Fmaster\u002Fframe_support\u002F\n- **test-fuzz**: https:\u002F\u002Fgithub.com\u002Ftrailofbits\u002Ftest-fuzz\n- **Substrate StackExchange**: https:\u002F\u002Fsubstrate.stackexchange.com\u002F\n\n---\n\n## 10. Quick Reference Checklist\n\nBefore completing Substrate pallet audit:\n\n**Arithmetic Safety (CRITICAL)**:\n- [ ] No direct `+`, `-`, `*`, `\u002F` operators in dispatchables\n- [ ] All arithmetic uses `checked_*` or `saturating_*`\n- [ ] Type conversions use `try_into()` with error handling\n\n**Panic Prevention (CRITICAL)**:\n- [ ] No `unwrap()` or `expect()` in dispatchables\n- [ ] No direct array\u002Fslice indexing without bounds check\n- [ ] All user inputs validated with `ensure!`\n- [ ] Division operations check for zero divisor\n\n**Weights & DoS (CRITICAL)**:\n- [ ] Weights proportional to computational cost\n- [ ] Input parameters have maximum bounds\n- [ ] Benchmarking used to determine weights\n- [ ] No free (zero-weight) expensive operations\n\n**Access Control (CRITICAL)**:\n- [ ] Privileged operations use `ensure_root` or custom origins\n- [ ] `ensure_signed` only for user-level operations\n- [ ] Origin types properly configured in runtime\n- [ ] Sudo pallet removed before production\n\n**Storage Safety (HIGH)**:\n- [ ] Using Substrate v0.9.25+ OR manual `#[transactional]`\n- [ ] Validation before storage writes\n- [ ] Events emitted after successful operations\n\n**Other (MEDIUM)**:\n- [ ] Unsigned transactions use signed alternative if possible\n- [ ] If unsigned: proper validation, replay protection, authentication\n- [ ] BABE randomness used (not RandomnessCollectiveFlip)\n- [ ] Randomness uses `random(subject)` not `random_seed()`\n\n**Testing**:\n- [ ] Unit tests for all dispatchables\n- [ ] Fuzz tests to find panics\n- [ ] Benchmarks generated and verified\n- [ ] try-runtime tests for migrations\n- [ ] Coverage table emitted with all 7 rows, each carrying a verdict of `found`, `clear` or `n\u002Fa` with a reason\n\n---\n\n## 11. Rationalizations to Reject\n\n- **\"The pallet is small, so most patterns obviously don't apply.\"** Obvious to whom? An `n\u002Fa` costs one\n  clause and makes the judgment reviewable. Silence records nothing, and a reader cannot tell it apart from\n  not having checked.\n- **\"It compiles without warnings, so the arithmetic is fine.\"** Release builds wrap silently. `+` on a\n  `Balance` is pattern 1 whether or not the compiler said anything, and debug assertions do not run on a\n  production node.\n- **\"I checked the patterns that matter for this pallet.\"** Deciding which patterns matter *is* the scan,\n  not a precondition for starting it. Rank by severity after the table is complete, not by leaving rows out.\n- **\"No findings, so there is nothing to report.\"** A zero-finding scan still emits the full coverage table.\n  That table is the deliverable: it is what distinguishes a pallet that was examined from one that was\n  glanced at.\n- **\"`ensure_signed` is an origin check.\"** It establishes that *someone* signed, not that the right someone\n  did. Pattern 7 is about which origin is required, and `ensure_signed` where `ensure_root` belongs passes\n  this rationalization while failing the check.\n- **\"The weight is benchmarked, so it's correct.\"** Benchmarks measure the path they exercise. A dispatchable\n  whose worst case depends on storage size or an unbounded loop is pattern 3 even with a benchmark attached.\n",{"name":5,"description":7},"main","321ccfe628eca0d314b0ee4eaffcdd8a05639aaf","plugins\u002Fbuilding-secure-contracts\u002Fskills\u002Fsubstrate-vulnerability-scanner",0,"https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills","https:\u002F\u002Fgithub.com\u002Fbongkage","2026-11-06 12:15:06",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add bongkage\u002Ftrailofbits-skills --skill substrate-vulnerability-scanner",{"tool":36,"command":37},"bunx","bunx skills add bongkage\u002Ftrailofbits-skills --skill substrate-vulnerability-scanner",{"tool":39,"command":40},"pnpm","pnpm dlx skills add bongkage\u002Ftrailofbits-skills --skill substrate-vulnerability-scanner","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fbuilding-secure-contracts\u002Fskills\u002Fsubstrate-vulnerability-scanner\u002FSKILL.md",true,[44,50,56],{"path":45,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":48,"sourceHtmlUrl":49},"agents\u002Fopenai.yaml","REFERENCE","参考文档",128,"https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fbuilding-secure-contracts\u002Fskills\u002Fsubstrate-vulnerability-scanner\u002Fagents\u002Fopenai.yaml",{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"assets\u002Ftrail-of-bits-mark.svg","ASSET","资产文件",3084,"https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fbuilding-secure-contracts\u002Fskills\u002Fsubstrate-vulnerability-scanner\u002Fassets\u002Ftrail-of-bits-mark.svg",{"path":57,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":58,"sourceHtmlUrl":59},"resources\u002FVULNERABILITY_PATTERNS.md",24903,"https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fbuilding-secure-contracts\u002Fskills\u002Fsubstrate-vulnerability-scanner\u002Fresources\u002FVULNERABILITY_PATTERNS.md",[61,68,75,82,89,96],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":18},"01M7CHJAESZRWKJXFQG55BMNAA","zeroize-audit","Detects missing zeroization of sensitive data in source code and identifies zeroization removed by compiler optimizations, with assembly-level analysis, and control-flow verification. Use for auditing C\u002FC++\u002FRust code handling secrets, keys, passwords, or other sensitive data.","https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fzeroize-audit\u002Fskills\u002Fzeroize-audit\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":18},"01M7CHJ543G42A9GQC3PJE4F4V","yara-rule-authoring","Guides authoring of high-quality YARA-X detection rules for malware identification. Use when writing, reviewing, or optimizing YARA rules. Covers naming conventions, string selection, performance optimization, migration from legacy YARA, and false positive reduction. Triggers on: YARA, YARA-X, malware detection, threat hunting, IOC, signature, crx module, dex module.","https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fyara-authoring\u002Fskills\u002Fyara-rule-authoring\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":18},"01M7CHHYVFS1AKDTH3YDS1Y4K4","writing-lean-proofs","Writes and reviews structured Lean 4 proofs and designs Lean libraries following Mathlib conventions. Use when proving theorems in Lean, formalizing mathematics or specifications in Lean 4, defining new types or definitions in a Lean library, reviewing Lean proofs for readability and maintainability, refactoring long tactic proofs into lemmas, filling in sorry placeholders in a Lean development, setting up CI or linters for a Lean project, diagnosing slow proofs or maxHeartbeats timeouts, or writing custom tactics, macros, or linters.","https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fwriting-lean-proofs\u002Fskills\u002Fwriting-lean-proofs\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":18},"01M7CHHQXA39M4965MV2RMM5YS","vulnerability-triage-brocards","This skill should be used when the user asks to \"triage a vulnerability report\", \"assess a CVE\", \"evaluate a bug bounty submission\", \"decide if a finding is valid\", \"review a security finding\", \"dismiss a vulnerability\", \"should we fix this CVE\", \"prioritize a vulnerability report\", or needs to determine whether an incoming vulnerability report warrants investigation. Applies 7 brocards (rules of thumb) to systematically accept, dismiss, or request more information on vulnerability reports, or needs to filter raw findings from agentic vulnerability discovery pipelines before human review.","https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fvulnerability-triage-brocards\u002Fskills\u002Fvulnerability-triage-brocards\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":18},"01M7CHHJVQC2ZG2M310GXT0T42","variant-analysis","Hunts for the other instances of a bug already found — the variants of one root cause across a codebase. Use immediately after a vulnerability, logic bug, or bad pattern turns up in a specific file and the question becomes where else it occurs, including the bare conversational form (\"are there others like this?\", \"is this the same bug?\"). Also for generalizing one known instance into a CodeQL or Semgrep query for its whole pattern family, and for triaging a set of look-alike candidates against a known root cause. Not for initial discovery with no bug in hand.","https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fvariant-analysis\u002Fskills\u002Fvariant-analysis\u002FSKILL.md",[],[],{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":18},"01M7CHHC1GM5GH585ZWGP7D03P","vector-forge","Mutation-driven test vector generation. Finds implementations of a cryptographic algorithm or protocol, runs mutation testing to identify escaped mutants, then generates new test vectors that deliberately exercise the uncovered code paths. Compares before\u002Fafter mutation kill rates to prove vector effectiveness. Use when generating cryptographic test vectors, measuring Wycheproof coverage gaps, finding escaped mutants via mutation testing, creating cross-implementation test suites, or improving test vector coverage for crypto primitives.","https:\u002F\u002Fgithub.com\u002Fbongkage\u002Ftrailofbits-skills\u002Fblob\u002Fmain\u002Fplugins\u002Ftrailmark\u002Fskills\u002Fvector-forge\u002FSKILL.md",[],[]]