solidity-argus 0.1.8 → 0.3.0
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/AGENTS.md +3 -3
- package/README.md +229 -13
- package/package.json +37 -8
- package/skills/INVENTORY.md +88 -57
- package/skills/README.md +72 -6
- package/skills/case-studies/beanstalk-governance/SKILL.md +52 -0
- package/skills/case-studies/bzx-flash-loan/SKILL.md +53 -0
- package/skills/case-studies/cream-finance/SKILL.md +52 -0
- package/skills/case-studies/curve-reentrancy/SKILL.md +52 -0
- package/skills/case-studies/dao-hack/SKILL.md +51 -0
- package/skills/case-studies/euler-finance/SKILL.md +52 -0
- package/skills/case-studies/harvest-finance/SKILL.md +52 -0
- package/skills/case-studies/level-finance/SKILL.md +51 -0
- package/skills/case-studies/mango-markets/SKILL.md +53 -0
- package/skills/case-studies/nomad-bridge/SKILL.md +51 -0
- package/skills/case-studies/parity-multisig/SKILL.md +55 -0
- package/skills/case-studies/poly-network/SKILL.md +51 -0
- package/skills/case-studies/rari-fuse/SKILL.md +51 -0
- package/skills/case-studies/ronin-bridge/SKILL.md +52 -0
- package/skills/case-studies/wormhole-bridge/SKILL.md +51 -0
- package/skills/checklists/cyfrin-defi-core/SKILL.md +3 -0
- package/skills/manifests/cyfrin.json +16 -0
- package/skills/manifests/defifofum.json +25 -0
- package/skills/manifests/kadenzipfel.json +48 -0
- package/skills/manifests/scvd.json +9 -0
- package/skills/manifests/smartbugs.json +9 -0
- package/skills/manifests/solodit.json +9 -0
- package/skills/manifests/sunweb3sec.json +9 -0
- package/skills/manifests/trailofbits.json +9 -0
- package/skills/methodology/audit-workflow/SKILL.md +3 -0
- package/skills/protocol-patterns/amm-dex/SKILL.md +3 -0
- package/skills/references/exploit-reference/SKILL.md +3 -0
- package/skills/vulnerability-patterns/access-control/SKILL.md +27 -0
- package/skills/vulnerability-patterns/arbitrary-storage-location/SKILL.md +13 -1
- package/skills/vulnerability-patterns/assert-violation/SKILL.md +8 -1
- package/skills/vulnerability-patterns/asserting-contract-from-code-size/SKILL.md +12 -1
- package/skills/vulnerability-patterns/authorization-txorigin/SKILL.md +8 -1
- package/skills/vulnerability-patterns/cross-chain-bridge-vulnerabilities/SKILL.md +217 -0
- package/skills/vulnerability-patterns/default-visibility/SKILL.md +13 -1
- package/skills/vulnerability-patterns/delegatecall-untrusted-callee/SKILL.md +8 -1
- package/skills/vulnerability-patterns/dos-gas-limit/SKILL.md +8 -1
- package/skills/vulnerability-patterns/dos-revert/SKILL.md +14 -1
- package/skills/vulnerability-patterns/erc4626-exchange-rate-manipulation/SKILL.md +64 -0
- package/skills/vulnerability-patterns/fee-on-transfer-tokens/SKILL.md +93 -0
- package/skills/vulnerability-patterns/flash-loan-attacks/SKILL.md +13 -0
- package/skills/vulnerability-patterns/floating-pragma/SKILL.md +8 -1
- package/skills/vulnerability-patterns/front-running-attacks/SKILL.md +209 -0
- package/skills/vulnerability-patterns/gas-optimization-patterns/SKILL.md +203 -0
- package/skills/vulnerability-patterns/governance-attacks/SKILL.md +208 -0
- package/skills/vulnerability-patterns/hash-collision/SKILL.md +8 -1
- package/skills/vulnerability-patterns/inadherence-to-standards/SKILL.md +12 -1
- package/skills/vulnerability-patterns/incorrect-constructor/SKILL.md +8 -1
- package/skills/vulnerability-patterns/incorrect-inheritance-order/SKILL.md +8 -1
- package/skills/vulnerability-patterns/insufficient-gas-griefing/SKILL.md +12 -1
- package/skills/vulnerability-patterns/lack-of-precision/SKILL.md +7 -1
- package/skills/vulnerability-patterns/logic-errors/SKILL.md +10 -0
- package/skills/vulnerability-patterns/missing-parameter-bounds/SKILL.md +44 -0
- package/skills/vulnerability-patterns/missing-protection-signature-replay/SKILL.md +17 -1
- package/skills/vulnerability-patterns/msgvalue-loop/SKILL.md +12 -1
- package/skills/vulnerability-patterns/off-by-one/SKILL.md +7 -1
- package/skills/vulnerability-patterns/oracle-manipulation/SKILL.md +22 -0
- package/skills/vulnerability-patterns/outdated-compiler-version/SKILL.md +8 -1
- package/skills/vulnerability-patterns/overflow-underflow/SKILL.md +11 -1
- package/skills/vulnerability-patterns/proxy-vulnerabilities/SKILL.md +209 -0
- package/skills/vulnerability-patterns/reentrancy/SKILL.md +22 -0
- package/skills/vulnerability-patterns/shadowing-state-variables/SKILL.md +8 -1
- package/skills/vulnerability-patterns/share-accounting-desynchronization/SKILL.md +44 -0
- package/skills/vulnerability-patterns/signature-malleability/SKILL.md +11 -1
- package/skills/vulnerability-patterns/stateful-parameter-update-drift/SKILL.md +44 -0
- package/skills/vulnerability-patterns/unbounded-return-data/SKILL.md +12 -1
- package/skills/vulnerability-patterns/unchecked-return-values/SKILL.md +13 -1
- package/skills/vulnerability-patterns/unencrypted-private-data-on-chain/SKILL.md +8 -1
- package/skills/vulnerability-patterns/unexpected-ecrecover-null-address/SKILL.md +8 -1
- package/skills/vulnerability-patterns/uninitialized-storage-pointer/SKILL.md +8 -1
- package/skills/vulnerability-patterns/unsafe-erc20-transfers/SKILL.md +132 -0
- package/skills/vulnerability-patterns/unsafe-low-level-call/SKILL.md +12 -1
- package/skills/vulnerability-patterns/unsecure-signatures/SKILL.md +12 -1
- package/skills/vulnerability-patterns/unsupported-opcodes/SKILL.md +11 -1
- package/skills/vulnerability-patterns/unused-variables/SKILL.md +8 -1
- package/skills/vulnerability-patterns/use-of-deprecated-functions/SKILL.md +8 -1
- package/skills/vulnerability-patterns/weak-sources-randomness/SKILL.md +8 -1
- package/skills/vulnerability-patterns/weird-tokens/SKILL.md +10 -0
- package/skills/vulnerability-patterns/zero-address-misconfiguration/SKILL.md +48 -0
- package/src/agents/argus-prompt.ts +27 -10
- package/src/agents/pythia-prompt.ts +7 -8
- package/src/agents/scribe-prompt.ts +10 -5
- package/src/agents/sentinel-prompt.ts +36 -7
- package/src/cli/cli-output.ts +16 -0
- package/src/cli/cli-program.ts +29 -22
- package/src/cli/commands/check-skills.ts +135 -0
- package/src/cli/commands/doctor.ts +303 -23
- package/src/cli/commands/init.ts +8 -6
- package/src/cli/commands/install.ts +10 -8
- package/src/cli/commands/lint-skills.ts +118 -0
- package/src/cli/index.ts +5 -5
- package/src/cli/tui-prompts.ts +4 -2
- package/src/cli/types.ts +3 -3
- package/src/config/index.ts +1 -1
- package/src/config/loader.ts +4 -6
- package/src/config/schema.ts +6 -5
- package/src/config/types.ts +2 -2
- package/src/constants/defaults.ts +2 -0
- package/src/create-hooks.ts +225 -29
- package/src/create-managers.ts +10 -8
- package/src/create-tools.ts +14 -8
- package/src/features/background-agent/background-manager.ts +93 -87
- package/src/features/background-agent/index.ts +1 -1
- package/src/features/context-monitor/context-monitor.ts +3 -3
- package/src/features/context-monitor/index.ts +2 -2
- package/src/features/error-recovery/session-recovery.ts +2 -4
- package/src/features/error-recovery/tool-error-recovery.ts +79 -19
- package/src/features/index.ts +5 -5
- package/src/features/persistent-state/audit-state-manager.ts +158 -52
- package/src/features/persistent-state/global-run-index.ts +38 -0
- package/src/features/persistent-state/index.ts +1 -1
- package/src/features/persistent-state/run-journal.ts +86 -0
- package/src/hooks/agent-tracker.ts +53 -0
- package/src/hooks/compaction-hook.ts +46 -37
- package/src/hooks/config-handler.ts +31 -11
- package/src/hooks/context-budget.ts +42 -0
- package/src/hooks/event-hook.ts +48 -23
- package/src/hooks/hook-system.ts +4 -4
- package/src/hooks/index.ts +5 -5
- package/src/hooks/knowledge-sync-hook.ts +19 -21
- package/src/hooks/recon-context-builder.ts +66 -0
- package/src/hooks/safe-create-hook.ts +9 -11
- package/src/hooks/system-prompt-hook.ts +128 -0
- package/src/hooks/tool-tracking-hook.ts +162 -29
- package/src/hooks/types.ts +2 -1
- package/src/index.ts +23 -13
- package/src/knowledge/retry.ts +53 -0
- package/src/knowledge/scvd-client.ts +103 -83
- package/src/knowledge/scvd-errors.ts +89 -0
- package/src/knowledge/scvd-index.ts +110 -62
- package/src/knowledge/scvd-sync.ts +223 -47
- package/src/knowledge/source-manifest.ts +102 -0
- package/src/managers/index.ts +1 -1
- package/src/managers/types.ts +19 -14
- package/src/plugin-interface.ts +19 -8
- package/src/shared/binary-utils.ts +44 -34
- package/src/shared/deep-merge.ts +55 -36
- package/src/shared/file-utils.ts +21 -19
- package/src/shared/index.ts +11 -5
- package/src/shared/jsonc-parser.ts +123 -28
- package/src/shared/logger.ts +91 -17
- package/src/shared/project-utils.ts +30 -0
- package/src/skills/analysis/cluster.ts +414 -0
- package/src/skills/analysis/gates.ts +227 -0
- package/src/skills/analysis/index.ts +33 -0
- package/src/skills/analysis/normalize.ts +217 -0
- package/src/skills/analysis/similarity.ts +224 -0
- package/src/skills/argus-skill-resolver.ts +237 -0
- package/src/skills/skill-schema.ts +99 -0
- package/src/solodit-lifecycle.ts +202 -0
- package/src/state/audit-state.ts +10 -8
- package/src/state/finding-store.ts +68 -55
- package/src/state/types.ts +96 -44
- package/src/tools/argus-skill-load-tool.ts +78 -0
- package/src/tools/contract-analyzer-tool.ts +60 -77
- package/src/tools/forge-coverage-tool.ts +226 -0
- package/src/tools/forge-fuzz-tool.ts +127 -127
- package/src/tools/forge-test-tool.ts +153 -157
- package/src/tools/gas-analysis-tool.ts +264 -0
- package/src/tools/pattern-checker-tool.ts +206 -167
- package/src/tools/pattern-loader.ts +77 -0
- package/src/tools/pattern-schema.ts +51 -0
- package/src/tools/proxy-detection-tool.ts +224 -0
- package/src/tools/report-generator-tool.ts +333 -142
- package/src/tools/slither-tool.ts +300 -210
- package/src/tools/solodit-search-tool.ts +255 -80
- package/src/tools/sync-knowledge-tool.ts +7 -11
- package/src/utils/audit-artifact-detector.ts +118 -0
- package/src/utils/dependency-scanner.ts +93 -0
- package/src/utils/project-detector.ts +175 -86
- package/src/utils/solidity-parser.ts +112 -67
- package/src/utils/solodit-health.ts +29 -0
- package/src/hooks/event-hook-v2.ts +0 -99
- package/src/state/plugin-state.ts +0 -14
|
@@ -1,177 +1,180 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ToolContext, tool } from "@opencode-ai/plugin"
|
|
2
|
+
import { resolveProjectDir } from "../shared/project-utils"
|
|
2
3
|
|
|
3
4
|
type ForgeFuzzArgs = {
|
|
4
|
-
target?: string
|
|
5
|
-
match_test?: string
|
|
6
|
-
runs?: number
|
|
7
|
-
seed?: number
|
|
8
|
-
fork_url?: string
|
|
9
|
-
}
|
|
5
|
+
target?: string
|
|
6
|
+
match_test?: string
|
|
7
|
+
runs?: number
|
|
8
|
+
seed?: number
|
|
9
|
+
fork_url?: string
|
|
10
|
+
}
|
|
10
11
|
|
|
11
12
|
type NormalizedForgeFuzzArgs = {
|
|
12
|
-
target: string
|
|
13
|
-
match_test?: string
|
|
14
|
-
runs: number
|
|
15
|
-
seed?: number
|
|
16
|
-
fork_url?: string
|
|
17
|
-
}
|
|
13
|
+
target: string
|
|
14
|
+
match_test?: string
|
|
15
|
+
runs: number
|
|
16
|
+
seed?: number
|
|
17
|
+
fork_url?: string
|
|
18
|
+
}
|
|
18
19
|
|
|
19
20
|
type ForgeFuzzResultItem = {
|
|
20
|
-
testName: string
|
|
21
|
-
status: "pass" | "fail"
|
|
22
|
-
runs: number
|
|
23
|
-
gas: number
|
|
24
|
-
}
|
|
21
|
+
testName: string
|
|
22
|
+
status: "pass" | "fail"
|
|
23
|
+
runs: number
|
|
24
|
+
gas: number
|
|
25
|
+
}
|
|
25
26
|
|
|
26
27
|
type ForgeFuzzCounterexample = {
|
|
27
|
-
testName: string
|
|
28
|
-
inputs: Record<string, string
|
|
29
|
-
revertReason?: string
|
|
30
|
-
}
|
|
28
|
+
testName: string
|
|
29
|
+
inputs: Record<string, string>
|
|
30
|
+
revertReason?: string
|
|
31
|
+
}
|
|
31
32
|
|
|
32
33
|
type ForgeFuzzResult = {
|
|
33
|
-
success: boolean
|
|
34
|
-
results: ForgeFuzzResultItem[]
|
|
35
|
-
counterexamples: ForgeFuzzCounterexample[]
|
|
36
|
-
totalRuns: number
|
|
37
|
-
executionTime: number
|
|
38
|
-
error?: string
|
|
39
|
-
}
|
|
34
|
+
success: boolean
|
|
35
|
+
results: ForgeFuzzResultItem[]
|
|
36
|
+
counterexamples: ForgeFuzzCounterexample[]
|
|
37
|
+
totalRuns: number
|
|
38
|
+
executionTime: number
|
|
39
|
+
error?: string
|
|
40
|
+
}
|
|
40
41
|
|
|
41
42
|
export type ForgeFuzzCommandResult = {
|
|
42
|
-
stdout: string
|
|
43
|
-
stderr: string
|
|
44
|
-
exitCode: number
|
|
45
|
-
}
|
|
43
|
+
stdout: string
|
|
44
|
+
stderr: string
|
|
45
|
+
exitCode: number
|
|
46
|
+
}
|
|
46
47
|
|
|
47
48
|
type RunForgeFuzzCommand = (
|
|
48
49
|
command: string[],
|
|
49
50
|
signal: AbortSignal,
|
|
50
51
|
cwd: string,
|
|
51
|
-
env: Record<string, string
|
|
52
|
-
) => Promise<ForgeFuzzCommandResult
|
|
52
|
+
env: Record<string, string>,
|
|
53
|
+
) => Promise<ForgeFuzzCommandResult>
|
|
53
54
|
|
|
54
|
-
function normalizeArgs(args: ForgeFuzzArgs): NormalizedForgeFuzzArgs {
|
|
55
|
-
const requestedRuns =
|
|
56
|
-
|
|
55
|
+
function normalizeArgs(args: ForgeFuzzArgs, context: ToolContext): NormalizedForgeFuzzArgs {
|
|
56
|
+
const requestedRuns =
|
|
57
|
+
typeof args.runs === "number" && Number.isFinite(args.runs) ? args.runs : 256
|
|
58
|
+
const clampedRuns = Math.max(1, Math.min(10000, Math.floor(requestedRuns)))
|
|
59
|
+
const target = args.target && args.target !== "." ? args.target : resolveProjectDir(context)
|
|
57
60
|
|
|
58
61
|
return {
|
|
59
|
-
target
|
|
62
|
+
target,
|
|
60
63
|
match_test: args.match_test,
|
|
61
64
|
runs: clampedRuns,
|
|
62
65
|
seed: args.seed,
|
|
63
66
|
fork_url: args.fork_url,
|
|
64
|
-
}
|
|
67
|
+
}
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
function buildForgeFuzzCommand(args: NormalizedForgeFuzzArgs): string[] {
|
|
68
|
-
const command = ["forge", "test", "--fuzz-runs", String(args.runs)]
|
|
71
|
+
const command = ["forge", "test", "--fuzz-runs", String(args.runs)]
|
|
69
72
|
|
|
70
73
|
if (args.match_test) {
|
|
71
|
-
command.push("--match-test", args.match_test)
|
|
74
|
+
command.push("--match-test", args.match_test)
|
|
72
75
|
}
|
|
73
76
|
if (typeof args.seed === "number" && Number.isFinite(args.seed)) {
|
|
74
|
-
command.push("--fuzz-seed", String(Math.floor(args.seed)))
|
|
77
|
+
command.push("--fuzz-seed", String(Math.floor(args.seed)))
|
|
75
78
|
}
|
|
76
79
|
if (args.fork_url) {
|
|
77
|
-
command.push("--fork-url", args.fork_url)
|
|
80
|
+
command.push("--fork-url", args.fork_url)
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
command.push("-v")
|
|
81
|
-
return command
|
|
83
|
+
command.push("-v")
|
|
84
|
+
return command
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
function parseNumber(input?: string): number {
|
|
85
88
|
if (!input) {
|
|
86
|
-
return 0
|
|
89
|
+
return 0
|
|
87
90
|
}
|
|
88
|
-
const normalized = input.replaceAll("_", "").trim()
|
|
89
|
-
const value = Number.parseInt(normalized, 10)
|
|
90
|
-
return Number.isFinite(value) ? value : 0
|
|
91
|
+
const normalized = input.replaceAll("_", "").trim()
|
|
92
|
+
const value = Number.parseInt(normalized, 10)
|
|
93
|
+
return Number.isFinite(value) ? value : 0
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
function splitArgsList(input: string): string[] {
|
|
94
|
-
const values: string[] = []
|
|
95
|
-
let current = ""
|
|
96
|
-
let depth = 0
|
|
97
|
+
const values: string[] = []
|
|
98
|
+
let current = ""
|
|
99
|
+
let depth = 0
|
|
97
100
|
|
|
98
101
|
for (let i = 0; i < input.length; i += 1) {
|
|
99
|
-
const ch = input[i] ?? ""
|
|
102
|
+
const ch = input[i] ?? ""
|
|
100
103
|
if (ch === "(" || ch === "[" || ch === "{") {
|
|
101
|
-
depth += 1
|
|
102
|
-
current += ch
|
|
103
|
-
continue
|
|
104
|
+
depth += 1
|
|
105
|
+
current += ch
|
|
106
|
+
continue
|
|
104
107
|
}
|
|
105
108
|
if (ch === ")" || ch === "]" || ch === "}") {
|
|
106
|
-
depth = Math.max(0, depth - 1)
|
|
107
|
-
current += ch
|
|
108
|
-
continue
|
|
109
|
+
depth = Math.max(0, depth - 1)
|
|
110
|
+
current += ch
|
|
111
|
+
continue
|
|
109
112
|
}
|
|
110
113
|
if (ch === "," && depth === 0) {
|
|
111
|
-
values.push(current.trim())
|
|
112
|
-
current = ""
|
|
113
|
-
continue
|
|
114
|
+
values.push(current.trim())
|
|
115
|
+
current = ""
|
|
116
|
+
continue
|
|
114
117
|
}
|
|
115
|
-
current += ch
|
|
118
|
+
current += ch
|
|
116
119
|
}
|
|
117
120
|
|
|
118
121
|
if (current.trim().length > 0) {
|
|
119
|
-
values.push(current.trim())
|
|
122
|
+
values.push(current.trim())
|
|
120
123
|
}
|
|
121
124
|
|
|
122
|
-
return values.filter((value) => value.length > 0)
|
|
125
|
+
return values.filter((value) => value.length > 0)
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
function parseInputsFromArgs(argsBlob: string): Record<string, string> {
|
|
126
|
-
const values = splitArgsList(argsBlob.trim())
|
|
127
|
-
const inputs: Record<string, string> = {}
|
|
129
|
+
const values = splitArgsList(argsBlob.trim())
|
|
130
|
+
const inputs: Record<string, string> = {}
|
|
128
131
|
|
|
129
132
|
values.forEach((value, index) => {
|
|
130
|
-
inputs[`arg${index}`] = value
|
|
131
|
-
})
|
|
133
|
+
inputs[`arg${index}`] = value
|
|
134
|
+
})
|
|
132
135
|
|
|
133
|
-
return inputs
|
|
136
|
+
return inputs
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
function parseResultLine(line: string): ForgeFuzzResultItem | undefined {
|
|
137
140
|
const match = line.match(
|
|
138
|
-
/^\[(PASS|FAIL)[^\]]*\]\s*(.+?)\s*\(runs:\s*([\d_]+)(?:,\s*(?:\u03bc|mean):\s*([\d_]+))?/i
|
|
139
|
-
)
|
|
141
|
+
/^\[(PASS|FAIL)[^\]]*\]\s*(.+?)\s*\(runs:\s*([\d_]+)(?:,\s*(?:\u03bc|mean):\s*([\d_]+))?/i,
|
|
142
|
+
)
|
|
140
143
|
if (!match) {
|
|
141
|
-
return undefined
|
|
144
|
+
return undefined
|
|
142
145
|
}
|
|
143
146
|
|
|
144
|
-
const status = match[1]?.toUpperCase() === "PASS" ? "pass" : "fail"
|
|
147
|
+
const status = match[1]?.toUpperCase() === "PASS" ? "pass" : "fail"
|
|
145
148
|
return {
|
|
146
149
|
testName: (match[2] ?? "unknown-test").trim(),
|
|
147
150
|
status,
|
|
148
151
|
runs: parseNumber(match[3]),
|
|
149
152
|
gas: parseNumber(match[4]),
|
|
150
|
-
}
|
|
153
|
+
}
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
function parseCounterexampleLine(line: string):
|
|
154
157
|
| {
|
|
155
|
-
testName?: string
|
|
156
|
-
inputs: Record<string, string
|
|
158
|
+
testName?: string
|
|
159
|
+
inputs: Record<string, string>
|
|
157
160
|
}
|
|
158
161
|
| undefined {
|
|
159
162
|
if (!line.includes("Counterexample:")) {
|
|
160
|
-
return undefined
|
|
163
|
+
return undefined
|
|
161
164
|
}
|
|
162
165
|
|
|
163
|
-
const argsMatch = line.match(/Counterexample:\s*.*?args=\((.*?)\)\]/)
|
|
166
|
+
const argsMatch = line.match(/Counterexample:\s*.*?args=\((.*?)\)\]/)
|
|
164
167
|
if (!argsMatch) {
|
|
165
|
-
return undefined
|
|
168
|
+
return undefined
|
|
166
169
|
}
|
|
167
170
|
|
|
168
|
-
const trailing = line.match(/\]\s*(.+)$/)
|
|
169
|
-
const possibleTest = trailing?.[1]?.replace(/\s*\(runs:.*$/, "").trim()
|
|
171
|
+
const trailing = line.match(/\]\s*(.+)$/)
|
|
172
|
+
const possibleTest = trailing?.[1]?.replace(/\s*\(runs:.*$/, "").trim()
|
|
170
173
|
|
|
171
174
|
return {
|
|
172
175
|
testName: possibleTest && possibleTest.length > 0 ? possibleTest : undefined,
|
|
173
176
|
inputs: parseInputsFromArgs(argsMatch[1] ?? ""),
|
|
174
|
-
}
|
|
177
|
+
}
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
const runForgeFuzzCommand: RunForgeFuzzCommand = async (command, signal, cwd, env) => {
|
|
@@ -181,29 +184,29 @@ const runForgeFuzzCommand: RunForgeFuzzCommand = async (command, signal, cwd, en
|
|
|
181
184
|
stderr: "pipe",
|
|
182
185
|
signal,
|
|
183
186
|
env,
|
|
184
|
-
})
|
|
187
|
+
})
|
|
185
188
|
|
|
186
189
|
const [exitCode, stdout, stderr] = await Promise.all([
|
|
187
190
|
child.exited,
|
|
188
191
|
new Response(child.stdout).text(),
|
|
189
192
|
new Response(child.stderr).text(),
|
|
190
|
-
])
|
|
193
|
+
])
|
|
191
194
|
|
|
192
195
|
return {
|
|
193
196
|
stdout,
|
|
194
197
|
stderr,
|
|
195
198
|
exitCode,
|
|
196
|
-
}
|
|
197
|
-
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
198
201
|
|
|
199
202
|
export async function executeForgeFuzz(
|
|
200
203
|
args: ForgeFuzzArgs,
|
|
201
204
|
context: ToolContext,
|
|
202
|
-
runCommand: RunForgeFuzzCommand = runForgeFuzzCommand
|
|
205
|
+
runCommand: RunForgeFuzzCommand = runForgeFuzzCommand,
|
|
203
206
|
): Promise<ForgeFuzzResult> {
|
|
204
|
-
const startedAt = Date.now()
|
|
205
|
-
const normalized = normalizeArgs(args)
|
|
206
|
-
context.metadata({ title: `Run forge fuzz: ${normalized.target}` })
|
|
207
|
+
const startedAt = Date.now()
|
|
208
|
+
const normalized = normalizeArgs(args, context)
|
|
209
|
+
context.metadata({ title: `Run forge fuzz: ${normalized.target}` })
|
|
207
210
|
|
|
208
211
|
const fail = (error: string): ForgeFuzzResult => ({
|
|
209
212
|
success: false,
|
|
@@ -212,85 +215,82 @@ export async function executeForgeFuzz(
|
|
|
212
215
|
totalRuns: 0,
|
|
213
216
|
executionTime: Date.now() - startedAt,
|
|
214
217
|
error,
|
|
215
|
-
})
|
|
218
|
+
})
|
|
216
219
|
|
|
217
220
|
try {
|
|
218
221
|
const env = {
|
|
219
222
|
...Bun.env,
|
|
220
223
|
FOUNDRY_FUZZ_RUNS: String(normalized.runs),
|
|
221
|
-
}
|
|
224
|
+
}
|
|
222
225
|
|
|
223
226
|
const runResult = await runCommand(
|
|
224
227
|
buildForgeFuzzCommand(normalized),
|
|
225
228
|
context.abort,
|
|
226
229
|
normalized.target,
|
|
227
|
-
env
|
|
228
|
-
)
|
|
230
|
+
env,
|
|
231
|
+
)
|
|
229
232
|
|
|
230
233
|
const lines = `${runResult.stdout}\n${runResult.stderr}`
|
|
231
234
|
.split(/\r?\n/)
|
|
232
235
|
.map((line) => line.trim())
|
|
233
|
-
.filter((line) => line.length > 0)
|
|
236
|
+
.filter((line) => line.length > 0)
|
|
234
237
|
|
|
235
|
-
const results: ForgeFuzzResultItem[] = []
|
|
236
|
-
const counterexamples: ForgeFuzzCounterexample[] = []
|
|
237
|
-
let lastTestName: string | undefined
|
|
238
|
+
const results: ForgeFuzzResultItem[] = []
|
|
239
|
+
const counterexamples: ForgeFuzzCounterexample[] = []
|
|
240
|
+
let lastTestName: string | undefined
|
|
238
241
|
|
|
239
242
|
for (let i = 0; i < lines.length; i += 1) {
|
|
240
|
-
const line = lines[i] ?? ""
|
|
241
|
-
const parsedResult = parseResultLine(line)
|
|
243
|
+
const line = lines[i] ?? ""
|
|
244
|
+
const parsedResult = parseResultLine(line)
|
|
242
245
|
if (parsedResult) {
|
|
243
|
-
results.push(parsedResult)
|
|
244
|
-
lastTestName = parsedResult.testName
|
|
246
|
+
results.push(parsedResult)
|
|
247
|
+
lastTestName = parsedResult.testName
|
|
245
248
|
}
|
|
246
249
|
|
|
247
|
-
const parsedCounterexample = parseCounterexampleLine(line)
|
|
250
|
+
const parsedCounterexample = parseCounterexampleLine(line)
|
|
248
251
|
if (!parsedCounterexample) {
|
|
249
|
-
continue
|
|
252
|
+
continue
|
|
250
253
|
}
|
|
251
254
|
|
|
252
|
-
const fallbackName = parsedCounterexample.testName ?? lastTestName ?? "unknown-test"
|
|
253
|
-
const nextLine = lines[i + 1] ?? ""
|
|
254
|
-
const reasonMatch = nextLine.match(/^(?:Reason|Error):\s*(.+)$/i)
|
|
255
|
+
const fallbackName = parsedCounterexample.testName ?? lastTestName ?? "unknown-test"
|
|
256
|
+
const nextLine = lines[i + 1] ?? ""
|
|
257
|
+
const reasonMatch = nextLine.match(/^(?:Reason|Error):\s*(.+)$/i)
|
|
255
258
|
counterexamples.push({
|
|
256
259
|
testName: fallbackName,
|
|
257
260
|
inputs: parsedCounterexample.inputs,
|
|
258
261
|
...(reasonMatch?.[1] ? { revertReason: reasonMatch[1].trim() } : {}),
|
|
259
|
-
})
|
|
262
|
+
})
|
|
260
263
|
}
|
|
261
264
|
|
|
262
|
-
const totalRuns = results.reduce((sum, item) => sum + item.runs, 0)
|
|
263
|
-
const failedCount = results.filter((item) => item.status === "fail").length
|
|
265
|
+
const totalRuns = results.reduce((sum, item) => sum + item.runs, 0)
|
|
266
|
+
const failedCount = results.filter((item) => item.status === "fail").length
|
|
264
267
|
const output: ForgeFuzzResult = {
|
|
265
268
|
success: runResult.exitCode === 0 && failedCount === 0,
|
|
266
269
|
results,
|
|
267
270
|
counterexamples,
|
|
268
271
|
totalRuns,
|
|
269
272
|
executionTime: Date.now() - startedAt,
|
|
270
|
-
}
|
|
273
|
+
}
|
|
271
274
|
|
|
272
275
|
if (runResult.exitCode !== 0 && failedCount === 0) {
|
|
273
|
-
output.error = runResult.stderr.trim() || `forge fuzz exited with code ${runResult.exitCode}
|
|
276
|
+
output.error = runResult.stderr.trim() || `forge fuzz exited with code ${runResult.exitCode}`
|
|
274
277
|
}
|
|
275
278
|
|
|
276
|
-
return output
|
|
279
|
+
return output
|
|
277
280
|
} catch (error) {
|
|
278
281
|
if (context.abort.aborted || (error instanceof DOMException && error.name === "AbortError")) {
|
|
279
|
-
return fail("forge fuzz aborted")
|
|
282
|
+
return fail("forge fuzz aborted")
|
|
280
283
|
}
|
|
281
284
|
|
|
282
|
-
const maybeError = error as Error & { code?: string }
|
|
285
|
+
const maybeError = error as Error & { code?: string }
|
|
283
286
|
if (maybeError.code === "ENOENT") {
|
|
284
|
-
return fail("Foundry not found. Install: curl -L https://foundry.paradigm.xyz | bash")
|
|
287
|
+
return fail("Foundry not found. Install: curl -L https://foundry.paradigm.xyz | bash")
|
|
285
288
|
}
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
maybeError.message.toLowerCase().includes("timed out")
|
|
289
|
-
) {
|
|
290
|
-
return fail("forge fuzz timed out");
|
|
289
|
+
if (maybeError.code === "ETIMEDOUT" || maybeError.message.toLowerCase().includes("timed out")) {
|
|
290
|
+
return fail("forge fuzz timed out")
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
return fail(maybeError.message || "forge fuzz failed")
|
|
293
|
+
return fail(maybeError.message || "forge fuzz failed")
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
|
|
@@ -305,7 +305,7 @@ export const forgeFuzzTool = tool({
|
|
|
305
305
|
fork_url: tool.schema.string().optional(),
|
|
306
306
|
},
|
|
307
307
|
async execute(args, context) {
|
|
308
|
-
const result = await executeForgeFuzz(args, context)
|
|
309
|
-
return JSON.stringify(result)
|
|
308
|
+
const result = await executeForgeFuzz(args, context)
|
|
309
|
+
return JSON.stringify(result)
|
|
310
310
|
},
|
|
311
|
-
})
|
|
311
|
+
})
|