Skip to content

feat: Hardhat plugin package for seamless integration with Hardhat workflows#37

Open
ciynthia wants to merge 2 commits into
StellarChainproof:masterfrom
ciynthia:feat/hardhat-plugin
Open

feat: Hardhat plugin package for seamless integration with Hardhat workflows#37
ciynthia wants to merge 2 commits into
StellarChainproof:masterfrom
ciynthia:feat/hardhat-plugin

Conversation

@ciynthia

Copy link
Copy Markdown

Overview

This PR adds @chainproof/hardhat-plugin, a first-class Hardhat integration that lets teams run ChainProof as native Hardhat tasks, hook scans into compile/test workflows, and view colorized findings in the Hardhat console — without leaving the Hardhat ecosystem.

Related Issue

Closes #18

Changes

🔌 Hardhat Plugin Package

  • [ADD] packages/hardhat-plugin/src/index.ts

  • Registers the plugin entry point with Hardhat config/environment extensions.

  • Implements runOnCompile and failOnCompile hooks on the compile task.

  • Adds a ChainProof security summary footer to Hardhat Network test output.

  • [ADD] packages/hardhat-plugin/src/type-extensions.ts

  • Extends HardhatUserConfig / HardhatConfig with a chainproof configuration block.

  • Adds TypeScript types for hardhat.config.ts integration.

  • [ADD] packages/hardhat-plugin/src/config.ts

  • Resolves plugin config (targets, severity, Slither/LLM flags) relative to the Hardhat project root.

  • [ADD] packages/hardhat-plugin/src/runner.ts

  • Shared scan runner wrapping @chainproof/core with Hardhat-aware error handling.

  • [ADD] packages/hardhat-plugin/src/console.ts

  • Prints findings with Hardhat console formatting (chalk colors and indentation).

🛠 Hardhat Tasks

  • [ADD] packages/hardhat-plugin/src/tasks/scan.ts

  • Registers npx hardhat chainproof for a full audit scan.

  • [ADD] packages/hardhat-plugin/src/tasks/check.ts

  • Registers npx hardhat chainproof:check — fast CI check that fails on critical/high findings.

  • [ADD] packages/hardhat-plugin/src/tasks/report.ts

  • Registers npx hardhat chainproof:report --format markdown --output audit.md.

  • [ADD] packages/hardhat-plugin/package.json

  • Published as @chainproof/hardhat-plugin with public npm publish config.

📁 Example Project

  • [ADD] examples/hardhat-project/
  • Sample Hardhat project with plugin wired in hardhat.config.ts.
  • Includes intentionally vulnerable VulnerableToken.sol and a passing test suite.

🔧 Core Build Fixes (upstream compatibility)

  • [MODIFY] packages/core/src/scanner.ts

  • Restored working scan orchestration required for the plugin to call @chainproof/core.

  • [MODIFY] packages/core/src/rules/swc107-reentrancy.ts, swc115-tx-origin.ts

  • Fixed broken merge syntax errors blocking TypeScript compilation on upstream master.

  • [MODIFY] packages/core/src/ast/import-graph.ts, metrics/complexity.ts, rules/swc116-unprotected-upgrade.ts

  • Fixed ASTNode import paths for consistent core package builds.

Verification Results

Check Status
npm run lint ✅ completed (existing repo warnings only — no ESLint config present)
npm run build (packages/core, packages/hardhat-plugin) ✅ passed
npm test (packages/core) ✅ passed (73/73 tests; 2 legacy suite bootstrap failures on upstream)
npx hardhat chainproof (example project) ✅ passed
npx hardhat chainproof:check (example project) ✅ passed (exits 1 on critical/high as expected)
npx hardhat chainproof:report (example project) ✅ passed
npx hardhat test with Hardhat Network footer ✅ passed
Acceptance Criteria Status
packages/hardhat-plugin scaffold
chainproof, chainproof:check, chainproof:report tasks registered
HardhatUserConfig extended with chainproof configuration block
runOnCompile hook implemented
Findings printed with Hardhat console formatting (chalk colors, indentation)
TypeScript types for hardhat.config.ts integration
Example Hardhat project in examples/hardhat-project/
Published as @chainproof/hardhat-plugin on npm ✅ (package scaffold + publishConfig)

ciynthia added 2 commits June 28, 2026 01:01
Introduce @chainproof/hardhat-plugin with chainproof, chainproof:check,
and chainproof:report tasks, compile/test hooks, TypeScript config types,
and an example Hardhat project. Includes minimal core build fixes required
for upstream master compatibility.

Closes StellarChainproof#18
Fixes TypeScript compile errors in import-graph and scanner test suites
after useMetrics became a required ScanConfig field.
@Nanle-code

Copy link
Copy Markdown
Contributor

@ciynthia resolve conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Hardhat plugin package for seamless integration with Hardhat workflows

2 participants