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
3 changes: 3 additions & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
artifacts/
cache/
19 changes: 19 additions & 0 deletions contracts/docs/SC_004_BENCHMARKS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SC-004 Verification Submission Engine - Gas Benchmarks

## Overview
This document outlines the gas cost benchmarks for the TruthBounty VerificationEngine smart contract. Measurements were taken via Hardhat local network tests.

## Results

| Operation | Gas Used | Notes |
| :--- | :--- | :--- |
| **First Verification Submission** | `259,608` | Gas for allocating `_verifierToVerificationId`, `_claimVerificationIds` arrays, and `_verificationById`, plus stake token transfer. |
| **Subsequent Verification Submission** | `208,320` | Lower gas as `_claimVerificationIds` array length update is already warm. |
| **Duplicate Prevention Revert** | `< 30,000` | Fails fast via mapping lookup on `_verifierToVerificationId`. |
| **Retrieval Operations** | `N/A (view)` | `getVerification`, `getClaimVerifications`, `getVerificationCount`, `hasVerified` and `getVerifierStake` do not modify state and execute locally for free. |

## Optimizations Made
- Used custom errors (e.g. `error AlreadyVerified()`) instead of string reverts to save deployment and execution gas.
- Minimized storage variables by using a `_verifierToVerificationId` mapping instead of duplicating the entire `Verification` struct.
- Reordered the `Verification` struct to pack fields (`verifier`, `submittedAt`, `verdict`) reducing the storage footprint per verification.
- Kept the engine completely deterministic without expensive cross-contract loops.
12 changes: 12 additions & 0 deletions contracts/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.20",
paths: {
sources: "./src",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts"
},
};
Loading