Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/hardhat-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
cache/
artifacts/
typechain-types/
audit.md
coverage/
44 changes: 44 additions & 0 deletions examples/hardhat-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ChainProof Hardhat Example

Example Hardhat project demonstrating `@chainproof/hardhat-plugin`.

## Setup

From the repository root:

```bash
npm install
npm run build
cd examples/hardhat-project
npm install
```

## Tasks

```bash
# Full audit
npx hardhat chainproof

# Fast CI check (exit code 1 on critical/high)
npx hardhat chainproof:check

# Generate report file
npx hardhat chainproof:report --format markdown --output audit.md
```

## Compile hook

Enable automatic scans after compile in `hardhat.config.ts`:

```typescript
chainproof: {
runOnCompile: true,
failOnCompile: false,
}
```

Then run `npx hardhat compile`.

## Test footer

When running tests on the Hardhat Network (`npx hardhat test`), ChainProof prints a security summary footer after test output.
35 changes: 35 additions & 0 deletions examples/hardhat-project/contracts/VulnerableToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
* @title VulnerableToken
* @notice Intentionally vulnerable contract for ChainProof Hardhat plugin demos.
*/
contract VulnerableToken {
address public owner;
mapping(address => uint256) public balances;

constructor() {
owner = msg.sender;
}

modifier onlyOwner() {
require(tx.origin == owner, "Not owner");
_;
}

function deposit() external payable {
balances[msg.sender] += msg.value;
}

function withdraw(uint256 amount) external {
require(balances[msg.sender] >= amount, "Insufficient balance");
(bool success, ) = msg.sender.call{value: amount}("");
require(success, "Transfer failed");
balances[msg.sender] -= amount;
}

function mint(address to, uint256 amount) external onlyOwner {
balances[to] += amount;
}
}
17 changes: 17 additions & 0 deletions examples/hardhat-project/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@chainproof/hardhat-plugin";

const config: HardhatUserConfig = {
solidity: "0.8.20",
chainproof: {
targets: ["contracts/"],
minSeverity: "high",
useSlither: false,
useLLM: false,
runOnCompile: false,
failOnCompile: false,
},
};

export default config;
Loading