-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Halmos assert mode #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,14 +21,41 @@ export function parseAddressBook(input: string): AddressBook { | |||||||||||||
|
|
||||||||||||||
| export function parseFailedProperties(input: string): Set<string> { | ||||||||||||||
| const set = new Set<string>(); | ||||||||||||||
| // 1) Regular FAIL lines, capture function name without params | ||||||||||||||
| const re = /^\[FAIL\]\s+([^\(\[]+)/gm; | ||||||||||||||
| let m: RegExpExecArray | null; | ||||||||||||||
| while ((m = re.exec(input))) { | ||||||||||||||
| set.add(m[1].trim()); | ||||||||||||||
| } | ||||||||||||||
| // 2) Inline assertion failures | ||||||||||||||
| // Example: Assertion failure detected in CryticToFoundry.doomsday_increment_never_reverts() | ||||||||||||||
| const assertionRe = /Assertion failure detected in\s+[\w$]+\.([^\)]+)\(\)/g; | ||||||||||||||
| const targetFns = parseTargetFunctions(input); // Full names incl. params, e.g. foo(uint256) or bar() | ||||||||||||||
| while ((m = assertionRe.exec(input))) { | ||||||||||||||
| const fn = (m[1] || "").trim(); // name without parens | ||||||||||||||
| // Only count as failed if it's one of the initial target functions (by name only) | ||||||||||||||
| const matchInTargets = Array.from(targetFns).some((full) => full.replace(/\(.*/, "") === fn); | ||||||||||||||
| if (matchInTargets) set.add(fn); | ||||||||||||||
| } | ||||||||||||||
| return set; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Parse list of target function signatures from the "Initial Invariant Target Functions" section | ||||||||||||||
| export function parseTargetFunctions(input: string): Set<string> { | ||||||||||||||
| const out = new Set<string>(); | ||||||||||||||
| const section = /Initial Invariant Target Functions([\s\S]*?)\n╰/m.exec(input); | ||||||||||||||
| if (!section) return out; | ||||||||||||||
| const body = section[1]; | ||||||||||||||
| // Lines look like: "│ ├── add_new_asset(uint8)" or "│ └── switchActor(uint256)" | ||||||||||||||
| const lineRe = /^[\s\u2502]+[├└]──\s+([^\s]+\([^)]*\))/gm; | ||||||||||||||
| let m: RegExpExecArray | null; | ||||||||||||||
| while ((m = lineRe.exec(body))) { | ||||||||||||||
| const sig = (m[1] || "").trim(); // e.g., add_new_asset(uint8) | ||||||||||||||
| if (sig) out.add(sig); | ||||||||||||||
| } | ||||||||||||||
| return out; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| interface CounterexampleBlock { | ||||||||||||||
| headerLine: string; // The [FAIL] line | ||||||||||||||
| traceFirstLine: string; // The first CALL line of the Trace: block (the final failing call) | ||||||||||||||
|
|
@@ -177,17 +204,34 @@ function renderFoundryTest( | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Render final call from Trace first line, always last | ||||||||||||||
| // But avoid duplication when the same function already appears in the Sequence | ||||||||||||||
| if (block.traceFirstLine) { | ||||||||||||||
| const traceFn = extractFnNameFromCall(block.traceFirstLine); | ||||||||||||||
| const seqFns = new Set( | ||||||||||||||
| block.sequenceCalls.map((s) => extractFnNameFromCall(s)).filter((x): x is string => !!x) | ||||||||||||||
| ); | ||||||||||||||
| const duplicate = traceFn && seqFns.has(traceFn); | ||||||||||||||
| if (!duplicate) { | ||||||||||||||
| const { call, prank, pre } = renderCall(block.traceFirstLine, block.counterexampleVars, addressBook); | ||||||||||||||
| if (pre && pre.length) pre.forEach((l) => bodyLines.push(` ${l}`)); | ||||||||||||||
| if (prank) bodyLines.push(` vm.prank(${prank});`); | ||||||||||||||
| bodyLines.push(` ${call};`); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const footer = "}"; | ||||||||||||||
| return [header, ...bodyLines, footer].join("\n"); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function extractFnNameFromCall(traceCallLine: string): string | null { | ||||||||||||||
| const sanitized = stripMetaTags(traceCallLine).replace(/^\s+/, ""); | ||||||||||||||
| const m1 = /^CALL\s+[^:]+::([^\(]+)\(/.exec(sanitized); | ||||||||||||||
| if (m1 && m1[1]) return m1[1].trim(); | ||||||||||||||
| const m2 = /^CALL\s+(0x[a-fA-F0-9]{8,40})::([^\(]+)\(/.exec(sanitized); | ||||||||||||||
| if (m2 && m2[2]) return m2[2].trim(); | ||||||||||||||
|
Comment on lines
+228
to
+231
|
||||||||||||||
| const m1 = /^CALL\s+[^:]+::([^\(]+)\(/.exec(sanitized); | |
| if (m1 && m1[1]) return m1[1].trim(); | |
| const m2 = /^CALL\s+(0x[a-fA-F0-9]{8,40})::([^\(]+)\(/.exec(sanitized); | |
| if (m2 && m2[2]) return m2[2].trim(); | |
| const m = /^CALL\s+(?:[^:]+|(0x[a-fA-F0-9]{8,40}))::([^\(]+)\(/.exec(sanitized); | |
| if (m && m[2]) return m[2].trim(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern has an unescaped closing parenthesis
)inside the character class. This should be escaped as\)to match a literal closing parenthesis.