@elizaos/skills 2.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -0
- package/package.json +53 -0
- package/skills/1password/SKILL.md +70 -0
- package/skills/1password/references/cli-examples.md +29 -0
- package/skills/1password/references/get-started.md +17 -0
- package/skills/apple-notes/SKILL.md +77 -0
- package/skills/apple-reminders/SKILL.md +96 -0
- package/skills/bear-notes/SKILL.md +107 -0
- package/skills/bird/SKILL.md +224 -0
- package/skills/blogwatcher/SKILL.md +69 -0
- package/skills/blucli/SKILL.md +47 -0
- package/skills/bluebubbles/SKILL.md +131 -0
- package/skills/camsnap/SKILL.md +45 -0
- package/skills/canvas/SKILL.md +203 -0
- package/skills/clawhub/SKILL.md +77 -0
- package/skills/coding-agent/SKILL.md +284 -0
- package/skills/discord/SKILL.md +578 -0
- package/skills/eightctl/SKILL.md +50 -0
- package/skills/food-order/SKILL.md +48 -0
- package/skills/gemini/SKILL.md +43 -0
- package/skills/gifgrep/SKILL.md +79 -0
- package/skills/github/SKILL.md +77 -0
- package/skills/gog/SKILL.md +116 -0
- package/skills/goplaces/SKILL.md +52 -0
- package/skills/healthcheck/SKILL.md +245 -0
- package/skills/himalaya/SKILL.md +257 -0
- package/skills/himalaya/references/configuration.md +184 -0
- package/skills/himalaya/references/message-composition.md +199 -0
- package/skills/imsg/SKILL.md +74 -0
- package/skills/local-places/SERVER_README.md +101 -0
- package/skills/local-places/SKILL.md +102 -0
- package/skills/local-places/pyproject.toml +21 -0
- package/skills/local-places/src/local_places/__init__.py +2 -0
- package/skills/local-places/src/local_places/google_places.py +314 -0
- package/skills/local-places/src/local_places/main.py +65 -0
- package/skills/local-places/src/local_places/schemas.py +107 -0
- package/skills/mcporter/SKILL.md +61 -0
- package/skills/model-usage/SKILL.md +69 -0
- package/skills/model-usage/references/codexbar-cli.md +33 -0
- package/skills/model-usage/scripts/model_usage.py +310 -0
- package/skills/nano-banana-pro/SKILL.md +58 -0
- package/skills/nano-banana-pro/scripts/generate_image.py +184 -0
- package/skills/nano-pdf/SKILL.md +38 -0
- package/skills/notion/SKILL.md +172 -0
- package/skills/obsidian/SKILL.md +81 -0
- package/skills/openai-image-gen/SKILL.md +89 -0
- package/skills/openai-image-gen/scripts/gen.py +240 -0
- package/skills/openai-whisper/SKILL.md +38 -0
- package/skills/openai-whisper-api/SKILL.md +52 -0
- package/skills/openai-whisper-api/scripts/transcribe.sh +85 -0
- package/skills/openhue/SKILL.md +51 -0
- package/skills/oracle/SKILL.md +125 -0
- package/skills/ordercli/SKILL.md +78 -0
- package/skills/peekaboo/SKILL.md +190 -0
- package/skills/sag/SKILL.md +87 -0
- package/skills/security-ask-questions-if-underspecified/.claude-plugin/plugin.json +10 -0
- package/skills/security-ask-questions-if-underspecified/README.md +24 -0
- package/skills/security-ask-questions-if-underspecified/skills/ask-questions-if-underspecified/SKILL.md +85 -0
- package/skills/security-audit-context-building/.claude-plugin/plugin.json +10 -0
- package/skills/security-audit-context-building/README.md +58 -0
- package/skills/security-audit-context-building/commands/audit-context.md +21 -0
- package/skills/security-audit-context-building/skills/audit-context-building/SKILL.md +297 -0
- package/skills/security-audit-context-building/skills/audit-context-building/resources/COMPLETENESS_CHECKLIST.md +47 -0
- package/skills/security-audit-context-building/skills/audit-context-building/resources/FUNCTION_MICRO_ANALYSIS_EXAMPLE.md +355 -0
- package/skills/security-audit-context-building/skills/audit-context-building/resources/OUTPUT_REQUIREMENTS.md +71 -0
- package/skills/security-building-secure-contracts/.claude-plugin/plugin.json +10 -0
- package/skills/security-building-secure-contracts/README.md +241 -0
- package/skills/security-building-secure-contracts/skills/algorand-vulnerability-scanner/SKILL.md +284 -0
- package/skills/security-building-secure-contracts/skills/algorand-vulnerability-scanner/resources/VULNERABILITY_PATTERNS.md +405 -0
- package/skills/security-building-secure-contracts/skills/audit-prep-assistant/SKILL.md +409 -0
- package/skills/security-building-secure-contracts/skills/cairo-vulnerability-scanner/SKILL.md +329 -0
- package/skills/security-building-secure-contracts/skills/cairo-vulnerability-scanner/resources/VULNERABILITY_PATTERNS.md +722 -0
- package/skills/security-building-secure-contracts/skills/code-maturity-assessor/SKILL.md +218 -0
- package/skills/security-building-secure-contracts/skills/code-maturity-assessor/resources/ASSESSMENT_CRITERIA.md +355 -0
- package/skills/security-building-secure-contracts/skills/code-maturity-assessor/resources/EXAMPLE_REPORT.md +248 -0
- package/skills/security-building-secure-contracts/skills/code-maturity-assessor/resources/REPORT_FORMAT.md +33 -0
- package/skills/security-building-secure-contracts/skills/cosmos-vulnerability-scanner/SKILL.md +334 -0
- package/skills/security-building-secure-contracts/skills/cosmos-vulnerability-scanner/resources/VULNERABILITY_PATTERNS.md +740 -0
- package/skills/security-building-secure-contracts/skills/guidelines-advisor/SKILL.md +252 -0
- package/skills/security-building-secure-contracts/skills/guidelines-advisor/resources/ASSESSMENT_AREAS.md +329 -0
- package/skills/security-building-secure-contracts/skills/guidelines-advisor/resources/DELIVERABLES.md +118 -0
- package/skills/security-building-secure-contracts/skills/guidelines-advisor/resources/EXAMPLE_REPORT.md +298 -0
- package/skills/security-building-secure-contracts/skills/secure-workflow-guide/SKILL.md +161 -0
- package/skills/security-building-secure-contracts/skills/secure-workflow-guide/resources/EXAMPLE_REPORT.md +279 -0
- package/skills/security-building-secure-contracts/skills/secure-workflow-guide/resources/WORKFLOW_STEPS.md +132 -0
- package/skills/security-building-secure-contracts/skills/solana-vulnerability-scanner/SKILL.md +389 -0
- package/skills/security-building-secure-contracts/skills/solana-vulnerability-scanner/resources/VULNERABILITY_PATTERNS.md +669 -0
- package/skills/security-building-secure-contracts/skills/substrate-vulnerability-scanner/SKILL.md +298 -0
- package/skills/security-building-secure-contracts/skills/substrate-vulnerability-scanner/resources/VULNERABILITY_PATTERNS.md +791 -0
- package/skills/security-building-secure-contracts/skills/token-integration-analyzer/SKILL.md +362 -0
- package/skills/security-building-secure-contracts/skills/token-integration-analyzer/resources/ASSESSMENT_CATEGORIES.md +571 -0
- package/skills/security-building-secure-contracts/skills/token-integration-analyzer/resources/REPORT_TEMPLATES.md +141 -0
- package/skills/security-building-secure-contracts/skills/ton-vulnerability-scanner/SKILL.md +388 -0
- package/skills/security-building-secure-contracts/skills/ton-vulnerability-scanner/resources/VULNERABILITY_PATTERNS.md +595 -0
- package/skills/security-burpsuite-project-parser/.claude-plugin/plugin.json +10 -0
- package/skills/security-burpsuite-project-parser/README.md +103 -0
- package/skills/security-burpsuite-project-parser/commands/burp-search.md +18 -0
- package/skills/security-burpsuite-project-parser/skills/SKILL.md +358 -0
- package/skills/security-burpsuite-project-parser/skills/scripts/burp-search.sh +99 -0
- package/skills/security-claude-in-chrome-troubleshooting/.claude-plugin/plugin.json +8 -0
- package/skills/security-claude-in-chrome-troubleshooting/README.md +31 -0
- package/skills/security-claude-in-chrome-troubleshooting/skills/claude-in-chrome-troubleshooting/SKILL.md +251 -0
- package/skills/security-constant-time-analysis/.claude-plugin/plugin.json +9 -0
- package/skills/security-constant-time-analysis/README.md +381 -0
- package/skills/security-constant-time-analysis/commands/ct-check.md +20 -0
- package/skills/security-constant-time-analysis/ct_analyzer/__init__.py +49 -0
- package/skills/security-constant-time-analysis/ct_analyzer/analyzer.py +1284 -0
- package/skills/security-constant-time-analysis/ct_analyzer/script_analyzers.py +3081 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/__init__.py +1 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_analyzer.py +1397 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/bn_excerpt.js +205 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/decompose_constant_time.c +181 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/decompose_vulnerable.c +74 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/decompose_vulnerable.go +78 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/decompose_vulnerable.rs +92 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/vulnerable.cs +174 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/vulnerable.java +161 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/vulnerable.kt +181 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/vulnerable.php +140 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/vulnerable.py +252 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/vulnerable.rb +188 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/vulnerable.swift +199 -0
- package/skills/security-constant-time-analysis/ct_analyzer/tests/test_samples/vulnerable.ts +154 -0
- package/skills/security-constant-time-analysis/pyproject.toml +52 -0
- package/skills/security-constant-time-analysis/skills/constant-time-analysis/README.md +90 -0
- package/skills/security-constant-time-analysis/skills/constant-time-analysis/SKILL.md +219 -0
- package/skills/security-constant-time-analysis/skills/constant-time-analysis/references/compiled.md +129 -0
- package/skills/security-constant-time-analysis/skills/constant-time-analysis/references/javascript.md +136 -0
- package/skills/security-constant-time-analysis/skills/constant-time-analysis/references/kotlin.md +252 -0
- package/skills/security-constant-time-analysis/skills/constant-time-analysis/references/php.md +172 -0
- package/skills/security-constant-time-analysis/skills/constant-time-analysis/references/python.md +179 -0
- package/skills/security-constant-time-analysis/skills/constant-time-analysis/references/ruby.md +198 -0
- package/skills/security-constant-time-analysis/skills/constant-time-analysis/references/swift.md +288 -0
- package/skills/security-constant-time-analysis/skills/constant-time-analysis/references/vm-compiled.md +354 -0
- package/skills/security-constant-time-analysis/uv.lock +8 -0
- package/skills/security-culture-index/.claude-plugin/plugin.json +8 -0
- package/skills/security-culture-index/README.md +79 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/SKILL.md +293 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/references/anti-patterns.md +255 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/references/conversation-starters.md +408 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/references/interview-trait-signals.md +253 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/references/motivators.md +158 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/references/patterns-archetypes.md +147 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/references/primary-traits.md +307 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/references/secondary-traits.md +228 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/references/team-composition.md +148 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/scripts/check_deps.py +108 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/scripts/culture_index/__init__.py +20 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/scripts/culture_index/constants.py +122 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/scripts/culture_index/extract.py +187 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/scripts/culture_index/models.py +16 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/scripts/culture_index/opencv_extractor.py +520 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/scripts/extract_pdf.py +237 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/scripts/pyproject.toml +18 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/templates/burnout-report.md +113 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/templates/comparison-report.md +103 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/templates/hiring-profile.md +127 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/templates/individual-report.md +85 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/templates/predicted-profile.md +165 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/templates/team-report.md +109 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/analyze-team.md +188 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/coach-manager.md +267 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/compare-profiles.md +188 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/define-hiring-profile.md +220 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/detect-burnout.md +206 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/extract-from-pdf.md +121 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/interpret-individual.md +183 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/interview-debrief.md +234 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/mediate-conflict.md +306 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/plan-onboarding.md +322 -0
- package/skills/security-culture-index/skills/interpreting-culture-index/workflows/predict-from-interview.md +250 -0
- package/skills/security-differential-review/.claude-plugin/plugin.json +10 -0
- package/skills/security-differential-review/README.md +109 -0
- package/skills/security-differential-review/commands/diff-review.md +21 -0
- package/skills/security-differential-review/skills/differential-review/SKILL.md +220 -0
- package/skills/security-differential-review/skills/differential-review/adversarial.md +203 -0
- package/skills/security-differential-review/skills/differential-review/methodology.md +234 -0
- package/skills/security-differential-review/skills/differential-review/patterns.md +300 -0
- package/skills/security-differential-review/skills/differential-review/reporting.md +369 -0
- package/skills/security-dwarf-expert/.claude-plugin/plugin.json +10 -0
- package/skills/security-dwarf-expert/README.md +38 -0
- package/skills/security-dwarf-expert/skills/dwarf-expert/SKILL.md +93 -0
- package/skills/security-dwarf-expert/skills/dwarf-expert/reference/coding.md +31 -0
- package/skills/security-dwarf-expert/skills/dwarf-expert/reference/dwarfdump.md +50 -0
- package/skills/security-dwarf-expert/skills/dwarf-expert/reference/readelf.md +8 -0
- package/skills/security-entry-point-analyzer/.claude-plugin/plugin.json +10 -0
- package/skills/security-entry-point-analyzer/README.md +74 -0
- package/skills/security-entry-point-analyzer/commands/entry-points.md +18 -0
- package/skills/security-entry-point-analyzer/skills/entry-point-analyzer/SKILL.md +251 -0
- package/skills/security-entry-point-analyzer/skills/entry-point-analyzer/references/cosmwasm.md +182 -0
- package/skills/security-entry-point-analyzer/skills/entry-point-analyzer/references/move-aptos.md +107 -0
- package/skills/security-entry-point-analyzer/skills/entry-point-analyzer/references/move-sui.md +87 -0
- package/skills/security-entry-point-analyzer/skills/entry-point-analyzer/references/solana.md +155 -0
- package/skills/security-entry-point-analyzer/skills/entry-point-analyzer/references/solidity.md +135 -0
- package/skills/security-entry-point-analyzer/skills/entry-point-analyzer/references/ton.md +185 -0
- package/skills/security-entry-point-analyzer/skills/entry-point-analyzer/references/vyper.md +141 -0
- package/skills/security-firebase-apk-scanner/.claude-plugin/plugin.json +10 -0
- package/skills/security-firebase-apk-scanner/README.md +85 -0
- package/skills/security-firebase-apk-scanner/commands/scan-apk.md +18 -0
- package/skills/security-firebase-apk-scanner/scanner.sh +1408 -0
- package/skills/security-firebase-apk-scanner/skills/firebase-apk-scanner/SKILL.md +197 -0
- package/skills/security-firebase-apk-scanner/skills/firebase-apk-scanner/references/vulnerabilities.md +803 -0
- package/skills/security-fix-review/.claude-plugin/plugin.json +13 -0
- package/skills/security-fix-review/README.md +118 -0
- package/skills/security-fix-review/commands/fix-review.md +24 -0
- package/skills/security-fix-review/skills/fix-review/SKILL.md +264 -0
- package/skills/security-fix-review/skills/fix-review/references/bug-detection.md +408 -0
- package/skills/security-fix-review/skills/fix-review/references/finding-matching.md +298 -0
- package/skills/security-fix-review/skills/fix-review/references/report-parsing.md +398 -0
- package/skills/security-insecure-defaults/.claude-plugin/plugin.json +10 -0
- package/skills/security-insecure-defaults/README.md +45 -0
- package/skills/security-insecure-defaults/skills/insecure-defaults/SKILL.md +117 -0
- package/skills/security-insecure-defaults/skills/insecure-defaults/references/examples.md +409 -0
- package/skills/security-modern-python/.claude-plugin/plugin.json +10 -0
- package/skills/security-modern-python/README.md +58 -0
- package/skills/security-modern-python/hooks/hooks.json +16 -0
- package/skills/security-modern-python/hooks/intercept-legacy-python.bats +388 -0
- package/skills/security-modern-python/hooks/intercept-legacy-python.sh +109 -0
- package/skills/security-modern-python/hooks/test_helper.bash +75 -0
- package/skills/security-modern-python/skills/modern-python/SKILL.md +333 -0
- package/skills/security-modern-python/skills/modern-python/references/dependabot.md +43 -0
- package/skills/security-modern-python/skills/modern-python/references/migration-checklist.md +141 -0
- package/skills/security-modern-python/skills/modern-python/references/pep723-scripts.md +259 -0
- package/skills/security-modern-python/skills/modern-python/references/prek.md +211 -0
- package/skills/security-modern-python/skills/modern-python/references/pyproject.md +254 -0
- package/skills/security-modern-python/skills/modern-python/references/ruff-config.md +240 -0
- package/skills/security-modern-python/skills/modern-python/references/security-setup.md +255 -0
- package/skills/security-modern-python/skills/modern-python/references/testing.md +284 -0
- package/skills/security-modern-python/skills/modern-python/references/uv-commands.md +200 -0
- package/skills/security-modern-python/skills/modern-python/templates/dependabot.yml +36 -0
- package/skills/security-modern-python/skills/modern-python/templates/pre-commit-config.yaml +66 -0
- package/skills/security-property-based-testing/.claude-plugin/plugin.json +9 -0
- package/skills/security-property-based-testing/README.md +47 -0
- package/skills/security-property-based-testing/skills/property-based-testing/README.md +88 -0
- package/skills/security-property-based-testing/skills/property-based-testing/SKILL.md +109 -0
- package/skills/security-property-based-testing/skills/property-based-testing/references/design.md +191 -0
- package/skills/security-property-based-testing/skills/property-based-testing/references/generating.md +200 -0
- package/skills/security-property-based-testing/skills/property-based-testing/references/libraries.md +130 -0
- package/skills/security-property-based-testing/skills/property-based-testing/references/refactoring.md +181 -0
- package/skills/security-property-based-testing/skills/property-based-testing/references/reviewing.md +209 -0
- package/skills/security-property-based-testing/skills/property-based-testing/references/strategies.md +124 -0
- package/skills/semgrep-rule-creator/.claude-plugin/plugin.json +8 -0
- package/skills/semgrep-rule-creator/README.md +43 -0
- package/skills/semgrep-rule-creator/commands/semgrep-rule.md +26 -0
- package/skills/semgrep-rule-creator/skills/semgrep-rule-creator/SKILL.md +168 -0
- package/skills/semgrep-rule-creator/skills/semgrep-rule-creator/references/quick-reference.md +203 -0
- package/skills/semgrep-rule-creator/skills/semgrep-rule-creator/references/workflow.md +240 -0
- package/skills/semgrep-rule-variant-creator/.claude-plugin/plugin.json +9 -0
- package/skills/semgrep-rule-variant-creator/README.md +86 -0
- package/skills/semgrep-rule-variant-creator/skills/semgrep-rule-variant-creator/SKILL.md +205 -0
- package/skills/semgrep-rule-variant-creator/skills/semgrep-rule-variant-creator/references/applicability-analysis.md +250 -0
- package/skills/semgrep-rule-variant-creator/skills/semgrep-rule-variant-creator/references/language-syntax-guide.md +324 -0
- package/skills/semgrep-rule-variant-creator/skills/semgrep-rule-variant-creator/references/workflow.md +518 -0
- package/skills/session-logs/SKILL.md +115 -0
- package/skills/sharp-edges/.claude-plugin/plugin.json +10 -0
- package/skills/sharp-edges/README.md +48 -0
- package/skills/sharp-edges/skills/sharp-edges/SKILL.md +292 -0
- package/skills/sharp-edges/skills/sharp-edges/references/auth-patterns.md +252 -0
- package/skills/sharp-edges/skills/sharp-edges/references/case-studies.md +274 -0
- package/skills/sharp-edges/skills/sharp-edges/references/config-patterns.md +333 -0
- package/skills/sharp-edges/skills/sharp-edges/references/crypto-apis.md +190 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-c.md +205 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-csharp.md +285 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-go.md +270 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-java.md +263 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-javascript.md +269 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-kotlin.md +265 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-php.md +245 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-python.md +274 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-ruby.md +273 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-rust.md +272 -0
- package/skills/sharp-edges/skills/sharp-edges/references/lang-swift.md +287 -0
- package/skills/sharp-edges/skills/sharp-edges/references/language-specific.md +588 -0
- package/skills/sherpa-onnx-tts/SKILL.md +103 -0
- package/skills/sherpa-onnx-tts/bin/sherpa-onnx-tts +178 -0
- package/skills/skill-creator/SKILL.md +370 -0
- package/skills/skill-creator/license.txt +202 -0
- package/skills/skill-creator/scripts/init_skill.py +378 -0
- package/skills/skill-creator/scripts/package_skill.py +111 -0
- package/skills/skill-creator/scripts/quick_validate.py +101 -0
- package/skills/slack/SKILL.md +144 -0
- package/skills/songsee/SKILL.md +49 -0
- package/skills/sonoscli/SKILL.md +46 -0
- package/skills/spec-to-code-compliance/.claude-plugin/plugin.json +10 -0
- package/skills/spec-to-code-compliance/README.md +67 -0
- package/skills/spec-to-code-compliance/commands/spec-compliance.md +22 -0
- package/skills/spec-to-code-compliance/skills/spec-to-code-compliance/SKILL.md +349 -0
- package/skills/spec-to-code-compliance/skills/spec-to-code-compliance/resources/COMPLETENESS_CHECKLIST.md +69 -0
- package/skills/spec-to-code-compliance/skills/spec-to-code-compliance/resources/IR_EXAMPLES.md +417 -0
- package/skills/spec-to-code-compliance/skills/spec-to-code-compliance/resources/OUTPUT_REQUIREMENTS.md +105 -0
- package/skills/spotify-player/SKILL.md +64 -0
- package/skills/static-analysis/.claude-plugin/plugin.json +8 -0
- package/skills/static-analysis/README.md +59 -0
- package/skills/static-analysis/skills/codeql/SKILL.md +315 -0
- package/skills/static-analysis/skills/sarif-parsing/SKILL.md +479 -0
- package/skills/static-analysis/skills/sarif-parsing/resources/jq-queries.md +162 -0
- package/skills/static-analysis/skills/sarif-parsing/resources/sarif_helpers.py +331 -0
- package/skills/static-analysis/skills/semgrep/SKILL.md +337 -0
- package/skills/summarize/SKILL.md +87 -0
- package/skills/testing-handbook-skills/.claude-plugin/plugin.json +8 -0
- package/skills/testing-handbook-skills/README.md +241 -0
- package/skills/testing-handbook-skills/scripts/pyproject.toml +8 -0
- package/skills/testing-handbook-skills/scripts/validate-skills.py +657 -0
- package/skills/testing-handbook-skills/skills/address-sanitizer/SKILL.md +341 -0
- package/skills/testing-handbook-skills/skills/aflpp/SKILL.md +640 -0
- package/skills/testing-handbook-skills/skills/atheris/SKILL.md +515 -0
- package/skills/testing-handbook-skills/skills/cargo-fuzz/SKILL.md +454 -0
- package/skills/testing-handbook-skills/skills/codeql/SKILL.md +549 -0
- package/skills/testing-handbook-skills/skills/constant-time-testing/SKILL.md +507 -0
- package/skills/testing-handbook-skills/skills/coverage-analysis/SKILL.md +607 -0
- package/skills/testing-handbook-skills/skills/fuzzing-dictionary/SKILL.md +297 -0
- package/skills/testing-handbook-skills/skills/fuzzing-obstacles/SKILL.md +426 -0
- package/skills/testing-handbook-skills/skills/harness-writing/SKILL.md +614 -0
- package/skills/testing-handbook-skills/skills/libafl/SKILL.md +625 -0
- package/skills/testing-handbook-skills/skills/libfuzzer/SKILL.md +795 -0
- package/skills/testing-handbook-skills/skills/ossfuzz/SKILL.md +426 -0
- package/skills/testing-handbook-skills/skills/ruzzy/SKILL.md +443 -0
- package/skills/testing-handbook-skills/skills/semgrep/SKILL.md +601 -0
- package/skills/testing-handbook-skills/skills/testing-handbook-generator/SKILL.md +372 -0
- package/skills/testing-handbook-skills/skills/testing-handbook-generator/agent-prompt.md +280 -0
- package/skills/testing-handbook-skills/skills/testing-handbook-generator/discovery.md +452 -0
- package/skills/testing-handbook-skills/skills/testing-handbook-generator/templates/domain-skill.md +504 -0
- package/skills/testing-handbook-skills/skills/testing-handbook-generator/templates/fuzzer-skill.md +454 -0
- package/skills/testing-handbook-skills/skills/testing-handbook-generator/templates/technique-skill.md +527 -0
- package/skills/testing-handbook-skills/skills/testing-handbook-generator/templates/tool-skill.md +366 -0
- package/skills/testing-handbook-skills/skills/testing-handbook-generator/testing.md +482 -0
- package/skills/testing-handbook-skills/skills/wycheproof/SKILL.md +533 -0
- package/skills/things-mac/SKILL.md +86 -0
- package/skills/tmux/SKILL.md +135 -0
- package/skills/tmux/scripts/find-sessions.sh +112 -0
- package/skills/tmux/scripts/wait-for-text.sh +83 -0
- package/skills/trello/SKILL.md +95 -0
- package/skills/variant-analysis/.claude-plugin/plugin.json +8 -0
- package/skills/variant-analysis/README.md +41 -0
- package/skills/variant-analysis/commands/variants.md +23 -0
- package/skills/variant-analysis/skills/variant-analysis/METHODOLOGY.md +327 -0
- package/skills/variant-analysis/skills/variant-analysis/SKILL.md +142 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/codeql/cpp.ql +119 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/codeql/go.ql +69 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/codeql/java.ql +71 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/codeql/javascript.ql +63 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/codeql/python.ql +80 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/semgrep/cpp.yaml +98 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/semgrep/go.yaml +63 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/semgrep/java.yaml +61 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/semgrep/javascript.yaml +60 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/semgrep/python.yaml +72 -0
- package/skills/variant-analysis/skills/variant-analysis/resources/variant-report-template.md +75 -0
- package/skills/video-frames/SKILL.md +46 -0
- package/skills/video-frames/scripts/frame.sh +81 -0
- package/skills/voice-call/SKILL.md +45 -0
- package/skills/wacli/SKILL.md +72 -0
- package/skills/weather/SKILL.md +54 -0
- package/skills/yara-authoring/.claude-plugin/plugin.json +9 -0
- package/skills/yara-authoring/README.md +131 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/SKILL.md +645 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/examples/MAL_Mac_ProtonRAT_Jan25.yar +99 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/examples/MAL_NPM_SupplyChain_Jan25.yar +170 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/examples/MAL_Win_Remcos_Jan25.yar +103 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/examples/SUSP_CRX_SuspiciousPermissions.yar +134 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/examples/SUSP_JS_Obfuscation_Jan25.yar +185 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/references/crx-module.md +214 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/references/dex-module.md +383 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/references/performance.md +333 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/references/strings.md +433 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/references/style-guide.md +257 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/references/testing.md +399 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/scripts/atom_analyzer.py +526 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/scripts/pyproject.toml +25 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/scripts/yara_lint.py +631 -0
- package/skills/yara-authoring/skills/yara-rule-authoring/workflows/rule-development.md +493 -0
|
@@ -0,0 +1,791 @@
|
|
|
1
|
+
# Substrate Vulnerability Patterns (7 Patterns)
|
|
2
|
+
|
|
3
|
+
This document contains detailed descriptions, detection patterns, and mitigations for 7 critical Substrate/FRAME vulnerabilities.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 6.1 ARITHMETIC OVERFLOW ⚠️ CRITICAL
|
|
8
|
+
|
|
9
|
+
**Description**: Primitive integer types wrap in release mode instead of panicking on overflow/underflow. In debug mode they panic, but production builds silently produce incorrect values.
|
|
10
|
+
|
|
11
|
+
**Detection Patterns**:
|
|
12
|
+
```rust
|
|
13
|
+
// VULNERABLE: Direct arithmetic on primitive types
|
|
14
|
+
#[pallet::call]
|
|
15
|
+
impl<T: Config> Pallet<T> {
|
|
16
|
+
pub fn transfer(origin: OriginFor<T>, amount: u128) -> DispatchResult {
|
|
17
|
+
let sender = ensure_signed(origin)?;
|
|
18
|
+
let mut balance = Self::balance_of(&sender);
|
|
19
|
+
|
|
20
|
+
// OVERFLOW: balance - amount wraps in release mode!
|
|
21
|
+
balance = balance - amount; // If amount > balance, wraps to huge number
|
|
22
|
+
|
|
23
|
+
// UNDERFLOW: balance + amount wraps in release mode!
|
|
24
|
+
balance = balance + amount; // If balance + amount > u128::MAX, wraps to small number
|
|
25
|
+
|
|
26
|
+
Self::set_balance(&sender, balance);
|
|
27
|
+
Ok(())
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// VULNERABLE: Multiplication overflow
|
|
32
|
+
let total = price * quantity; // Wraps if price * quantity > u128::MAX
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**What to Check**:
|
|
36
|
+
- [ ] NO direct arithmetic operators (`+`, `-`, `*`, `/`) on primitive types in dispatchables
|
|
37
|
+
- [ ] ALL arithmetic uses `checked_*`, `saturating_*`, or `overflowing_*` methods
|
|
38
|
+
- [ ] Balance updates use safe arithmetic
|
|
39
|
+
- [ ] Reward/fee calculations use safe arithmetic
|
|
40
|
+
- [ ] Type conversions checked for overflow
|
|
41
|
+
|
|
42
|
+
**Mitigation**:
|
|
43
|
+
```rust
|
|
44
|
+
// SECURE: Use checked arithmetic
|
|
45
|
+
#[pallet::call]
|
|
46
|
+
impl<T: Config> Pallet<T> {
|
|
47
|
+
pub fn transfer(origin: OriginFor<T>, amount: u128) -> DispatchResult {
|
|
48
|
+
let sender = ensure_signed(origin)?;
|
|
49
|
+
let balance = Self::balance_of(&sender);
|
|
50
|
+
|
|
51
|
+
// checked_sub returns None on underflow
|
|
52
|
+
let new_balance = balance.checked_sub(amount)
|
|
53
|
+
.ok_or(Error::<T>::InsufficientBalance)?;
|
|
54
|
+
|
|
55
|
+
Self::set_balance(&sender, new_balance);
|
|
56
|
+
Ok(())
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
pub fn calculate_reward(stakes: u128, rate: u128) -> Result<u128, Error<T>> {
|
|
60
|
+
// checked_mul returns None on overflow
|
|
61
|
+
stakes.checked_mul(rate)
|
|
62
|
+
.ok_or(Error::<T>::ArithmeticOverflow)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// SECURE: Use saturating arithmetic (when clamping is acceptable)
|
|
67
|
+
use sp_runtime::traits::Saturating;
|
|
68
|
+
|
|
69
|
+
let new_value = old_value.saturating_add(increment); // Clamps at u128::MAX
|
|
70
|
+
let new_value = old_value.saturating_sub(decrement); // Clamps at 0
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Available Safe Methods**:
|
|
74
|
+
```rust
|
|
75
|
+
// CheckedAdd, CheckedSub, CheckedMul, CheckedDiv traits
|
|
76
|
+
value.checked_add(other)?
|
|
77
|
+
value.checked_sub(other)?
|
|
78
|
+
value.checked_mul(other)?
|
|
79
|
+
value.checked_div(other)?
|
|
80
|
+
|
|
81
|
+
// Saturating trait (clamps at min/max)
|
|
82
|
+
value.saturating_add(other)
|
|
83
|
+
value.saturating_sub(other)
|
|
84
|
+
value.saturating_mul(other)
|
|
85
|
+
|
|
86
|
+
// Overflowing (returns bool flag)
|
|
87
|
+
let (result, overflowed) = value.overflowing_add(other);
|
|
88
|
+
ensure!(!overflowed, Error::<T>::ArithmeticOverflow);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**References**: building-secure-contracts/not-so-smart-contracts/substrate/arithmetic_overflow
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 4.2 DON'T PANIC ⚠️ CRITICAL - DoS
|
|
96
|
+
|
|
97
|
+
**Description**: Panics in dispatchable functions cause the node to stop processing blocks, enabling DoS attacks. Production runtime must never panic.
|
|
98
|
+
|
|
99
|
+
**Detection Patterns**:
|
|
100
|
+
|
|
101
|
+
### Pattern 1: Array Indexing
|
|
102
|
+
```rust
|
|
103
|
+
// VULNERABLE: Direct array indexing panics on out-of-bounds
|
|
104
|
+
pub fn get_validator(index: u32) -> DispatchResult {
|
|
105
|
+
let validators = Self::validator_set();
|
|
106
|
+
let validator = validators[index as usize]; // PANIC if index >= len!
|
|
107
|
+
// ...
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Pattern 2: unwrap() / expect()
|
|
112
|
+
```rust
|
|
113
|
+
// VULNERABLE: unwrap() panics on None
|
|
114
|
+
pub fn process_data(origin: OriginFor<T>, data: Vec<u8>) -> DispatchResult {
|
|
115
|
+
let value = Self::parse_data(&data).unwrap(); // PANIC on parse error!
|
|
116
|
+
// ...
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// VULNERABLE: expect() also panics
|
|
120
|
+
let sender = ensure_signed(origin).expect("must be signed"); // PANIC!
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Pattern 3: Type Conversions
|
|
124
|
+
```rust
|
|
125
|
+
// VULNERABLE: as casts can panic or produce wrong values
|
|
126
|
+
pub fn set_value(origin: OriginFor<T>, value: u128) -> DispatchResult {
|
|
127
|
+
let small_value = value as u32; // Truncates if value > u32::MAX!
|
|
128
|
+
Self::store_value(small_value);
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Pattern 4: Missing Input Validation
|
|
133
|
+
```rust
|
|
134
|
+
// VULNERABLE: No bounds checking on user input
|
|
135
|
+
pub fn divide(numerator: u128, denominator: u128) -> DispatchResult {
|
|
136
|
+
let result = numerator / denominator; // PANIC if denominator == 0!
|
|
137
|
+
// ...
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**What to Check**:
|
|
142
|
+
- [ ] NO array/slice indexing without bounds check
|
|
143
|
+
- [ ] NO `unwrap()`, `expect()` in dispatchables
|
|
144
|
+
- [ ] NO `as` casts without validation
|
|
145
|
+
- [ ] ALL user input validated before use
|
|
146
|
+
- [ ] Division operations check for zero divisor
|
|
147
|
+
- [ ] All `?` operator paths return DispatchError, not panic
|
|
148
|
+
|
|
149
|
+
**Mitigation**:
|
|
150
|
+
```rust
|
|
151
|
+
// SECURE: Bounds checking for array access
|
|
152
|
+
pub fn get_validator(index: u32) -> DispatchResult {
|
|
153
|
+
let validators = Self::validator_set();
|
|
154
|
+
let validator = validators.get(index as usize)
|
|
155
|
+
.ok_or(Error::<T>::ValidatorIndexOutOfBounds)?;
|
|
156
|
+
// ...
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// SECURE: Handle Result/Option properly
|
|
160
|
+
pub fn process_data(origin: OriginFor<T>, data: Vec<u8>) -> DispatchResult {
|
|
161
|
+
let value = Self::parse_data(&data)
|
|
162
|
+
.map_err(|_| Error::<T>::InvalidData)?;
|
|
163
|
+
// ...
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// SECURE: Safe type conversions
|
|
167
|
+
use sp_runtime::traits::TryConvert;
|
|
168
|
+
|
|
169
|
+
pub fn set_value(origin: OriginFor<T>, value: u128) -> DispatchResult {
|
|
170
|
+
let small_value: u32 = value.try_into()
|
|
171
|
+
.map_err(|_| Error::<T>::ValueTooLarge)?;
|
|
172
|
+
Self::store_value(small_value);
|
|
173
|
+
Ok(())
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// SECURE: Input validation with ensure!
|
|
177
|
+
pub fn divide(numerator: u128, denominator: u128) -> DispatchResult {
|
|
178
|
+
ensure!(denominator != 0, Error::<T>::DivisionByZero);
|
|
179
|
+
let result = numerator / denominator; // Safe now
|
|
180
|
+
// ...
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// SECURE: Comprehensive validation
|
|
184
|
+
#[pallet::call]
|
|
185
|
+
impl<T: Config> Pallet<T> {
|
|
186
|
+
pub fn create_proposal(
|
|
187
|
+
origin: OriginFor<T>,
|
|
188
|
+
title: Vec<u8>,
|
|
189
|
+
description: Vec<u8>,
|
|
190
|
+
) -> DispatchResult {
|
|
191
|
+
let proposer = ensure_signed(origin)?;
|
|
192
|
+
|
|
193
|
+
// Validate all inputs
|
|
194
|
+
ensure!(title.len() <= 100, Error::<T>::TitleTooLong);
|
|
195
|
+
ensure!(description.len() <= 1000, Error::<T>::DescriptionTooLong);
|
|
196
|
+
ensure!(!title.is_empty(), Error::<T>::TitleEmpty);
|
|
197
|
+
|
|
198
|
+
// All validation passed, safe to proceed
|
|
199
|
+
Self::store_proposal(proposer, title, description)?;
|
|
200
|
+
Ok(())
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Testing for Panics**:
|
|
206
|
+
```rust
|
|
207
|
+
// Use test-fuzz to find panic conditions
|
|
208
|
+
#[cfg(test)]
|
|
209
|
+
mod tests {
|
|
210
|
+
use super::*;
|
|
211
|
+
|
|
212
|
+
#[test]
|
|
213
|
+
#[should_panic]
|
|
214
|
+
fn test_panics_on_invalid_input() {
|
|
215
|
+
// This test should NOT panic in production code
|
|
216
|
+
// If it does, you found a vulnerability
|
|
217
|
+
Pallet::divide(100, 0).unwrap();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Fuzz testing
|
|
221
|
+
#[test_fuzz::test_fuzz]
|
|
222
|
+
fn fuzz_transfer(sender: AccountId, amount: u128) {
|
|
223
|
+
// Should never panic regardless of input
|
|
224
|
+
let _ = Pallet::transfer(sender, amount);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**References**: building-secure-contracts/not-so-smart-contracts/substrate/dont_panic
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## 4.3 WEIGHTS AND FEES ⚠️ CRITICAL - DoS
|
|
234
|
+
|
|
235
|
+
**Description**: Incorrect weight functions allow cheap calls to expensive operations, enabling DoS attacks by spamming low-fee transactions that consume excessive resources.
|
|
236
|
+
|
|
237
|
+
**Detection Patterns**:
|
|
238
|
+
```rust
|
|
239
|
+
// VULNERABLE: Fixed weight for variable-cost operation
|
|
240
|
+
#[pallet::weight(10_000)] // Same cost regardless of input!
|
|
241
|
+
pub fn process_items(origin: OriginFor<T>, items: Vec<Item>) -> DispatchResult {
|
|
242
|
+
// Processing cost grows with items.len(), but weight is fixed!
|
|
243
|
+
for item in items {
|
|
244
|
+
Self::expensive_operation(item); // O(n) operation
|
|
245
|
+
}
|
|
246
|
+
Ok(())
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// VULNERABLE: No bounds on input size
|
|
250
|
+
#[pallet::weight(items.len() as u64 * 1000)] // Weight grows with input
|
|
251
|
+
pub fn process_items(origin: OriginFor<T>, items: Vec<Item>) -> DispatchResult {
|
|
252
|
+
// But no maximum limit! Attacker can send items.len() = 1 billion
|
|
253
|
+
// and cause block to exceed weight limit
|
|
254
|
+
Ok(())
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// VULNERABLE: Zero weight for non-trivial operation
|
|
258
|
+
#[pallet::weight(0)] // FREE operation!
|
|
259
|
+
pub fn expensive_computation(origin: OriginFor<T>, data: Vec<u8>) -> DispatchResult {
|
|
260
|
+
let _ = Self::compute_hash_10000_times(&data); // Expensive but free!
|
|
261
|
+
Ok(())
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**What to Check**:
|
|
266
|
+
- [ ] Weight functions account for input size
|
|
267
|
+
- [ ] Loops have bounded iterations
|
|
268
|
+
- [ ] Storage access counted in weight
|
|
269
|
+
- [ ] Upper bounds enforced on Vec/array parameters
|
|
270
|
+
- [ ] Weights determined empirically via benchmarking
|
|
271
|
+
- [ ] No free/zero-weight dispatchables (unless trivial)
|
|
272
|
+
|
|
273
|
+
**Mitigation**:
|
|
274
|
+
```rust
|
|
275
|
+
// SECURE: Weight proportional to input size with bounds
|
|
276
|
+
#[pallet::weight({
|
|
277
|
+
// Ensure items.len() has a reasonable maximum
|
|
278
|
+
let bounded_len = items.len().min(T::MaxItems::get() as usize);
|
|
279
|
+
T::DbWeight::get().reads_writes(bounded_len as u64, bounded_len as u64)
|
|
280
|
+
.saturating_add(T::WeightPerItem::get().saturating_mul(bounded_len as u64))
|
|
281
|
+
})]
|
|
282
|
+
pub fn process_items(origin: OriginFor<T>, items: Vec<Item>) -> DispatchResult {
|
|
283
|
+
// Enforce maximum items
|
|
284
|
+
ensure!(items.len() <= T::MaxItems::get() as usize, Error::<T>::TooManyItems);
|
|
285
|
+
|
|
286
|
+
for item in items {
|
|
287
|
+
Self::expensive_operation(item);
|
|
288
|
+
}
|
|
289
|
+
Ok(())
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// SECURE: Use benchmarking framework
|
|
293
|
+
#[pallet::weight(T::WeightInfo::transfer())]
|
|
294
|
+
pub fn transfer(
|
|
295
|
+
origin: OriginFor<T>,
|
|
296
|
+
dest: T::AccountId,
|
|
297
|
+
amount: BalanceOf<T>,
|
|
298
|
+
) -> DispatchResult {
|
|
299
|
+
// Weight calculated by benchmarking.rs
|
|
300
|
+
// ...
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// BETTER: Benchmark with input parameters
|
|
304
|
+
#[pallet::weight(T::WeightInfo::process_items(items.len() as u32))]
|
|
305
|
+
pub fn process_items(origin: OriginFor<T>, items: Vec<Item>) -> DispatchResult {
|
|
306
|
+
ensure!(items.len() <= T::MaxItems::get() as usize, Error::<T>::TooManyItems);
|
|
307
|
+
// ...
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Benchmarking**:
|
|
312
|
+
```rust
|
|
313
|
+
// benchmarking.rs - Empirically determine weights
|
|
314
|
+
#[benchmarks]
|
|
315
|
+
mod benchmarks {
|
|
316
|
+
use super::*;
|
|
317
|
+
|
|
318
|
+
#[benchmark]
|
|
319
|
+
fn process_items(n: Linear<1, 100>) {
|
|
320
|
+
let items: Vec<Item> = (0..n).map(|i| Item::new(i)).collect();
|
|
321
|
+
|
|
322
|
+
#[extrinsic_call]
|
|
323
|
+
process_items(RawOrigin::Signed(caller), items);
|
|
324
|
+
|
|
325
|
+
// Verify operation succeeded
|
|
326
|
+
assert!(SomeStorage::<T>::get().is_some());
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
**Configuration Constants**:
|
|
332
|
+
```rust
|
|
333
|
+
#[pallet::config]
|
|
334
|
+
pub trait Config: frame_system::Config {
|
|
335
|
+
// Define maximum bounds
|
|
336
|
+
#[pallet::constant]
|
|
337
|
+
type MaxItems: Get<u32>;
|
|
338
|
+
|
|
339
|
+
#[pallet::constant]
|
|
340
|
+
type MaxDataSize: Get<u32>;
|
|
341
|
+
|
|
342
|
+
// Weight info from benchmarking
|
|
343
|
+
type WeightInfo: WeightInfo;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// In runtime/lib.rs
|
|
347
|
+
impl pallet_example::Config for Runtime {
|
|
348
|
+
type MaxItems = ConstU32<100>; // Max 100 items per call
|
|
349
|
+
type MaxDataSize = ConstU32<10_000>; // Max 10KB data
|
|
350
|
+
type WeightInfo = pallet_example::weights::SubstrateWeight<Runtime>;
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
**References**: building-secure-contracts/not-so-smart-contracts/substrate/weights_fees
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## 4.4 VERIFY FIRST, WRITE LAST ⚠️ HIGH (Pre-v0.9.25)
|
|
359
|
+
|
|
360
|
+
**Description**: In Substrate versions before v0.9.25, storage writes before validation persist even if the dispatch later fails, allowing attackers to modify state without paying the full cost.
|
|
361
|
+
|
|
362
|
+
**Detection Patterns**:
|
|
363
|
+
```rust
|
|
364
|
+
// VULNERABLE: Storage write before validation (pre-v0.9.25)
|
|
365
|
+
pub fn claim_reward(origin: OriginFor<T>) -> DispatchResult {
|
|
366
|
+
let claimer = ensure_signed(origin)?;
|
|
367
|
+
|
|
368
|
+
// WRONG: Writing to storage before all validation!
|
|
369
|
+
<ClaimCount<T>>::mutate(|count| *count += 1);
|
|
370
|
+
|
|
371
|
+
// Validation happens AFTER storage write
|
|
372
|
+
let reward = Self::calculate_reward(&claimer)?;
|
|
373
|
+
ensure!(reward > 0, Error::<T>::NoReward);
|
|
374
|
+
|
|
375
|
+
// If this fails, ClaimCount was still incremented!
|
|
376
|
+
Self::transfer_reward(&claimer, reward)?;
|
|
377
|
+
|
|
378
|
+
Ok(())
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// VULNERABLE: Event emitted before validation
|
|
382
|
+
pub fn submit_proposal(origin: OriginFor<T>, data: Vec<u8>) -> DispatchResult {
|
|
383
|
+
let proposer = ensure_signed(origin)?;
|
|
384
|
+
|
|
385
|
+
// WRONG: Event before validation
|
|
386
|
+
Self::deposit_event(Event::ProposalSubmitted(proposer.clone()));
|
|
387
|
+
|
|
388
|
+
// Validation after event
|
|
389
|
+
ensure!(data.len() <= 1000, Error::<T>::DataTooLarge);
|
|
390
|
+
|
|
391
|
+
Ok(())
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
**What to Check**:
|
|
396
|
+
- [ ] Using Substrate v0.9.25+ (transactional storage layer)
|
|
397
|
+
- [ ] OR all validation happens BEFORE any storage writes
|
|
398
|
+
- [ ] OR manual `#[transactional]` attribute used
|
|
399
|
+
- [ ] Events emitted AFTER all validation and state changes
|
|
400
|
+
- [ ] Pattern: validate → write → emit event
|
|
401
|
+
|
|
402
|
+
**Mitigation**:
|
|
403
|
+
```rust
|
|
404
|
+
// OPTION 1: Upgrade to v0.9.25+ (automatic transactional storage)
|
|
405
|
+
// Storage writes automatically rolled back on error
|
|
406
|
+
|
|
407
|
+
// OPTION 2: Verify First, Write Last pattern
|
|
408
|
+
pub fn claim_reward(origin: OriginFor<T>) -> DispatchResult {
|
|
409
|
+
let claimer = ensure_signed(origin)?;
|
|
410
|
+
|
|
411
|
+
// ALL VALIDATION FIRST
|
|
412
|
+
let reward = Self::calculate_reward(&claimer)?;
|
|
413
|
+
ensure!(reward > 0, Error::<T>::NoReward);
|
|
414
|
+
ensure!(Self::can_transfer(&claimer, reward)?, Error::<T>::TransferFailed);
|
|
415
|
+
|
|
416
|
+
// THEN ALL WRITES
|
|
417
|
+
<ClaimCount<T>>::mutate(|count| *count += 1);
|
|
418
|
+
Self::transfer_reward(&claimer, reward)?;
|
|
419
|
+
|
|
420
|
+
// FINALLY EVENTS
|
|
421
|
+
Self::deposit_event(Event::RewardClaimed {
|
|
422
|
+
claimer,
|
|
423
|
+
amount: reward,
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
Ok(())
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// OPTION 3: Manual transactional attribute (pre-v0.9.25)
|
|
430
|
+
use frame_support::transactional;
|
|
431
|
+
|
|
432
|
+
#[transactional] // Rollback all storage on error
|
|
433
|
+
pub fn claim_reward(origin: OriginFor<T>) -> DispatchResult {
|
|
434
|
+
// Storage writes rolled back if function returns Err
|
|
435
|
+
Ok(())
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**References**: building-secure-contracts/not-so-smart-contracts/substrate/verify_first
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## 4.5 UNSIGNED TRANSACTION VALIDATION ⚠️ HIGH
|
|
444
|
+
|
|
445
|
+
**Description**: Insufficient validation in `ValidateUnsigned` trait allows spam, replay attacks, or spoofed data from offchain workers or external sources.
|
|
446
|
+
|
|
447
|
+
**Detection Patterns**:
|
|
448
|
+
```rust
|
|
449
|
+
// VULNERABLE: No validation in validate_unsigned
|
|
450
|
+
#[pallet::validate_unsigned]
|
|
451
|
+
impl<T: Config> ValidateUnsigned for Pallet<T> {
|
|
452
|
+
type Call = Call<T>;
|
|
453
|
+
|
|
454
|
+
fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
|
|
455
|
+
match call {
|
|
456
|
+
Call::submit_price { price, .. } => {
|
|
457
|
+
// WRONG: No validation of price source or replay protection!
|
|
458
|
+
ValidTransaction::with_tag_prefix("OffchainWorker")
|
|
459
|
+
.priority(100)
|
|
460
|
+
.build()
|
|
461
|
+
}
|
|
462
|
+
_ => InvalidTransaction::Call.into(),
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// VULNERABLE: No replay protection
|
|
468
|
+
pub fn submit_data(origin: OriginFor<T>, data: Vec<u8>) -> DispatchResult {
|
|
469
|
+
ensure_none(origin)?; // Unsigned transaction
|
|
470
|
+
// WRONG: Same data can be submitted multiple times!
|
|
471
|
+
Self::process_data(data)?;
|
|
472
|
+
Ok(())
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
**What to Check**:
|
|
477
|
+
- [ ] Consider using signed transactions instead (strongly preferred)
|
|
478
|
+
- [ ] IF unsigned is necessary:
|
|
479
|
+
- [ ] All parameters validated in `validate_unsigned`
|
|
480
|
+
- [ ] Replay protection via nonce or one-time tag
|
|
481
|
+
- [ ] Data source authenticated (cryptographic signature)
|
|
482
|
+
- [ ] Rate limiting or spam protection
|
|
483
|
+
- [ ] Priority set appropriately (high for OCW, low for user-submitted)
|
|
484
|
+
|
|
485
|
+
**Mitigation**:
|
|
486
|
+
```rust
|
|
487
|
+
// OPTION 1: Use signed transactions (PREFERRED)
|
|
488
|
+
#[pallet::call]
|
|
489
|
+
impl<T: Config> Pallet<T> {
|
|
490
|
+
#[pallet::weight(10_000)]
|
|
491
|
+
pub fn submit_price(
|
|
492
|
+
origin: OriginFor<T>, // Signed
|
|
493
|
+
price: u128,
|
|
494
|
+
signature: Signature,
|
|
495
|
+
) -> DispatchResult {
|
|
496
|
+
let signer = ensure_signed(origin)?;
|
|
497
|
+
// Signed transaction provides natural replay protection and authentication
|
|
498
|
+
Ok(())
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// OPTION 2: Proper unsigned validation (if truly necessary)
|
|
503
|
+
#[pallet::validate_unsigned]
|
|
504
|
+
impl<T: Config> ValidateUnsigned for Pallet<T> {
|
|
505
|
+
type Call = Call<T>;
|
|
506
|
+
|
|
507
|
+
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
|
|
508
|
+
match call {
|
|
509
|
+
Call::submit_price { price, block_number, signature } => {
|
|
510
|
+
// 1. Validate signature from authorized source
|
|
511
|
+
let public_key = Self::authority_key();
|
|
512
|
+
ensure!(signature.verify(price, block_number, &public_key),
|
|
513
|
+
InvalidTransaction::BadProof);
|
|
514
|
+
|
|
515
|
+
// 2. Replay protection - check block_number is current
|
|
516
|
+
let current_block = <frame_system::Pallet<T>>::block_number();
|
|
517
|
+
ensure!(block_number == current_block,
|
|
518
|
+
InvalidTransaction::Stale);
|
|
519
|
+
|
|
520
|
+
// 3. One-time submission via unique tag
|
|
521
|
+
let tag = (b"price", block_number).encode();
|
|
522
|
+
|
|
523
|
+
ValidTransaction::with_tag_prefix("OffchainWorker")
|
|
524
|
+
.priority(TransactionPriority::MAX)
|
|
525
|
+
.and_provides(tag) // Prevents duplicate submission
|
|
526
|
+
.longevity(5) // Valid for 5 blocks
|
|
527
|
+
.propagate(true)
|
|
528
|
+
.build()
|
|
529
|
+
}
|
|
530
|
+
_ => InvalidTransaction::Call.into(),
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// With replay protection in dispatch
|
|
536
|
+
pub fn submit_price(
|
|
537
|
+
origin: OriginFor<T>,
|
|
538
|
+
price: u128,
|
|
539
|
+
block_number: T::BlockNumber,
|
|
540
|
+
) -> DispatchResult {
|
|
541
|
+
ensure_none(origin)?;
|
|
542
|
+
|
|
543
|
+
// Check not already processed
|
|
544
|
+
ensure!(!<ProcessedBlocks<T>>::contains_key(block_number),
|
|
545
|
+
Error::<T>::AlreadyProcessed);
|
|
546
|
+
|
|
547
|
+
// Mark as processed
|
|
548
|
+
<ProcessedBlocks<T>>::insert(block_number, true);
|
|
549
|
+
|
|
550
|
+
// Process data
|
|
551
|
+
Self::update_price(price)?;
|
|
552
|
+
|
|
553
|
+
Ok(())
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
**References**: building-secure-contracts/not-so-smart-contracts/substrate/unsigned_validation
|
|
558
|
+
|
|
559
|
+
---
|
|
560
|
+
|
|
561
|
+
## 4.6 BAD RANDOMNESS ⚠️ MEDIUM
|
|
562
|
+
|
|
563
|
+
**Description**: Using low-security randomness source (`pallet_randomness_collective_flip`) in production allows validator collusion or manipulation.
|
|
564
|
+
|
|
565
|
+
**Detection Patterns**:
|
|
566
|
+
```rust
|
|
567
|
+
// VULNERABLE: Using RandomnessCollectiveFlip in production
|
|
568
|
+
impl pallet_example::Config for Runtime {
|
|
569
|
+
type Randomness = pallet_randomness_collective_flip::RandomnessCollectiveFlip;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// VULNERABLE: Using random_seed() instead of random()
|
|
573
|
+
pub fn draw_winner(origin: OriginFor<T>) -> DispatchResult {
|
|
574
|
+
let seed = T::Randomness::random_seed(); // WRONG: Doesn't incorporate subject
|
|
575
|
+
let winner_index = Self::pick_from_seed(&seed);
|
|
576
|
+
// ...
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// VULNERABLE: Using randomness for critical security
|
|
580
|
+
pub fn generate_secret_key(origin: OriginFor<T>) -> DispatchResult {
|
|
581
|
+
let random = T::Randomness::random(&b"secret"[..]);
|
|
582
|
+
// BAD: Even with BABE, not sufficient for cryptographic keys!
|
|
583
|
+
let secret_key = Self::derive_key(random.0);
|
|
584
|
+
// ...
|
|
585
|
+
}
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
**What to Check**:
|
|
589
|
+
- [ ] NOT using `pallet_randomness_collective_flip` in production
|
|
590
|
+
- [ ] Using BABE randomness (`pallet_babe::RandomnessFromOneEpochAgo`)
|
|
591
|
+
- [ ] Using `random(subject)` instead of `random_seed()`
|
|
592
|
+
- [ ] NOT using on-chain randomness for cryptographic keys
|
|
593
|
+
- [ ] Understanding randomness can be influenced by validators
|
|
594
|
+
|
|
595
|
+
**Mitigation**:
|
|
596
|
+
```rust
|
|
597
|
+
// SECURE: Use BABE randomness (production)
|
|
598
|
+
impl pallet_example::Config for Runtime {
|
|
599
|
+
// Use BABE VRF for production randomness
|
|
600
|
+
type Randomness = pallet_babe::RandomnessFromOneEpochAgo<Runtime>;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// SECURE: Use random() with subject, not random_seed()
|
|
604
|
+
pub fn draw_winner(origin: OriginFor<T>) -> DispatchResult {
|
|
605
|
+
let _ = ensure_signed(origin)?;
|
|
606
|
+
|
|
607
|
+
// Incorporate subject to make each call's randomness unique
|
|
608
|
+
let (random_hash, _block_number) = T::Randomness::random(&b"lottery"[..]);
|
|
609
|
+
|
|
610
|
+
// Convert to integer for selection
|
|
611
|
+
let random_number = u32::from_le_bytes([
|
|
612
|
+
random_hash.as_ref()[0],
|
|
613
|
+
random_hash.as_ref()[1],
|
|
614
|
+
random_hash.as_ref()[2],
|
|
615
|
+
random_hash.as_ref()[3],
|
|
616
|
+
]);
|
|
617
|
+
|
|
618
|
+
let winner_index = random_number % Self::participant_count();
|
|
619
|
+
Self::award_prize(winner_index)?;
|
|
620
|
+
|
|
621
|
+
Ok(())
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// SECURE: Don't use on-chain randomness for crypto keys
|
|
625
|
+
// Instead: generate off-chain, store hash on-chain for verification
|
|
626
|
+
pub fn register_key(origin: OriginFor<T>, key_hash: Hash) -> DispatchResult {
|
|
627
|
+
// Store hash of externally-generated key
|
|
628
|
+
// User generates key off-chain with proper entropy
|
|
629
|
+
Ok(())
|
|
630
|
+
}
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
**Randomness Quality by Source**:
|
|
634
|
+
```rust
|
|
635
|
+
// NOT SECURE for production
|
|
636
|
+
pallet_randomness_collective_flip // Low influence, collusion risk
|
|
637
|
+
|
|
638
|
+
// SECURE for production
|
|
639
|
+
pallet_babe::RandomnessFromOneEpochAgo // VRF-based, high security
|
|
640
|
+
|
|
641
|
+
// SECURE for testing only
|
|
642
|
+
pallet_insecure_randomness_collective_flip // Explicit "insecure" naming
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
**References**: building-secure-contracts/not-so-smart-contracts/substrate/randomness
|
|
646
|
+
|
|
647
|
+
---
|
|
648
|
+
|
|
649
|
+
## 4.7 BAD ORIGIN ⚠️ CRITICAL
|
|
650
|
+
|
|
651
|
+
**Description**: Using `ensure_signed` for privileged operations instead of proper origin validation (`ensure_root`, custom origins) allows unauthorized access.
|
|
652
|
+
|
|
653
|
+
**Detection Patterns**:
|
|
654
|
+
```rust
|
|
655
|
+
// VULNERABLE: Using ensure_signed for privileged operation
|
|
656
|
+
#[pallet::call]
|
|
657
|
+
impl<T: Config> Pallet<T> {
|
|
658
|
+
pub fn emergency_pause(origin: OriginFor<T>) -> DispatchResult {
|
|
659
|
+
let _caller = ensure_signed(origin)?; // WRONG: Any signed user!
|
|
660
|
+
<SystemPaused<T>>::put(true); // Critical operation with no real authorization
|
|
661
|
+
Ok(())
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
pub fn set_global_config(
|
|
665
|
+
origin: OriginFor<T>,
|
|
666
|
+
new_fee: Balance,
|
|
667
|
+
) -> DispatchResult {
|
|
668
|
+
let _caller = ensure_signed(origin)?; // WRONG: Any user can change fees!
|
|
669
|
+
<GlobalFee<T>>::put(new_fee);
|
|
670
|
+
Ok(())
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// VULNERABLE: Not using configured ForceOrigin
|
|
675
|
+
pub fn force_transfer(
|
|
676
|
+
origin: OriginFor<T>,
|
|
677
|
+
from: T::AccountId,
|
|
678
|
+
to: T::AccountId,
|
|
679
|
+
) -> DispatchResult {
|
|
680
|
+
let _admin = ensure_signed(origin)?; // WRONG: Should check ForceOrigin!
|
|
681
|
+
// Should be: T::ForceOrigin::ensure_origin(origin)?;
|
|
682
|
+
Self::do_transfer(from, to)?;
|
|
683
|
+
Ok(())
|
|
684
|
+
}
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
**What to Check**:
|
|
688
|
+
- [ ] Root-level operations use `ensure_root(origin)?`
|
|
689
|
+
- [ ] Privileged operations use custom origin types (ForceOrigin, AdminOrigin)
|
|
690
|
+
- [ ] `ensure_signed` only for user-level operations
|
|
691
|
+
- [ ] Origin configuration documented for governance
|
|
692
|
+
- [ ] Sudo privileges removed before production launch
|
|
693
|
+
|
|
694
|
+
**Mitigation**:
|
|
695
|
+
```rust
|
|
696
|
+
// SECURE: Use ensure_root for root operations
|
|
697
|
+
#[pallet::call]
|
|
698
|
+
impl<T: Config> Pallet<T> {
|
|
699
|
+
#[pallet::weight(10_000)]
|
|
700
|
+
pub fn emergency_pause(origin: OriginFor<T>) -> DispatchResult {
|
|
701
|
+
ensure_root(origin)?; // Only root account
|
|
702
|
+
<SystemPaused<T>>::put(true);
|
|
703
|
+
Self::deposit_event(Event::SystemPaused);
|
|
704
|
+
Ok(())
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// SECURE: Use custom origin types for privileged operations
|
|
709
|
+
#[pallet::config]
|
|
710
|
+
pub trait Config: frame_system::Config {
|
|
711
|
+
/// Origin that can execute force operations
|
|
712
|
+
type ForceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
|
713
|
+
|
|
714
|
+
/// Origin that can update parameters
|
|
715
|
+
type UpdateOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
#[pallet::call]
|
|
719
|
+
impl<T: Config> Pallet<T> {
|
|
720
|
+
#[pallet::weight(10_000)]
|
|
721
|
+
pub fn force_transfer(
|
|
722
|
+
origin: OriginFor<T>,
|
|
723
|
+
from: T::AccountId,
|
|
724
|
+
to: T::AccountId,
|
|
725
|
+
amount: BalanceOf<T>,
|
|
726
|
+
) -> DispatchResult {
|
|
727
|
+
// Validate against configured ForceOrigin
|
|
728
|
+
T::ForceOrigin::ensure_origin(origin)?;
|
|
729
|
+
|
|
730
|
+
Self::do_transfer(from, to, amount)?;
|
|
731
|
+
Ok(())
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
#[pallet::weight(10_000)]
|
|
735
|
+
pub fn update_fee(
|
|
736
|
+
origin: OriginFor<T>,
|
|
737
|
+
new_fee: BalanceOf<T>,
|
|
738
|
+
) -> DispatchResult {
|
|
739
|
+
// Validate against configured UpdateOrigin
|
|
740
|
+
T::UpdateOrigin::ensure_origin(origin)?;
|
|
741
|
+
|
|
742
|
+
<GlobalFee<T>>::put(new_fee);
|
|
743
|
+
Self::deposit_event(Event::FeeUpdated { new_fee });
|
|
744
|
+
Ok(())
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
#[pallet::weight(10_000)]
|
|
748
|
+
pub fn transfer(
|
|
749
|
+
origin: OriginFor<T>,
|
|
750
|
+
to: T::AccountId,
|
|
751
|
+
amount: BalanceOf<T>,
|
|
752
|
+
) -> DispatchResult {
|
|
753
|
+
// Regular user operation - ensure_signed is correct
|
|
754
|
+
let from = ensure_signed(origin)?;
|
|
755
|
+
|
|
756
|
+
Self::do_transfer(from, to, amount)?;
|
|
757
|
+
Ok(())
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// Runtime configuration
|
|
762
|
+
impl pallet_example::Config for Runtime {
|
|
763
|
+
// Require governance approval for force operations
|
|
764
|
+
type ForceOrigin = EnsureRootOrHalfCouncil;
|
|
765
|
+
|
|
766
|
+
// Require 2/3 council for parameter updates
|
|
767
|
+
type UpdateOrigin = EnsureRootOrTwoThirdsCouncil;
|
|
768
|
+
}
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
**Origin Types Reference**:
|
|
772
|
+
```rust
|
|
773
|
+
// Built-in origins
|
|
774
|
+
ensure_root(origin)? // Root/sudo only
|
|
775
|
+
ensure_signed(origin)? // Any signed account
|
|
776
|
+
ensure_none(origin)? // Unsigned (use with extreme caution)
|
|
777
|
+
|
|
778
|
+
// Custom origins (configured in runtime)
|
|
779
|
+
T::ForceOrigin::ensure_origin(origin)?
|
|
780
|
+
T::UpdateOrigin::ensure_origin(origin)?
|
|
781
|
+
T::AdminOrigin::ensure_origin(origin)?
|
|
782
|
+
|
|
783
|
+
// Common origin configurations
|
|
784
|
+
EnsureRoot // Root only
|
|
785
|
+
EnsureSigned // Any signed
|
|
786
|
+
EnsureSignedBy<AccountId> // Specific account
|
|
787
|
+
EnsureRootOrHalfCouncil // Root or 50%+ council
|
|
788
|
+
EnsureRootOrTwoThirdsCouncil // Root or 67%+ council
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
**References**: building-secure-contracts/not-so-smart-contracts/substrate/bad_origin
|