Skip to content

fix: Solidity move basic-oracle-manipulation test annotation to the matched line - #3997

Merged
malaverdiere merged 1 commit into
developfrom
marc-andre/fix-oracle-manipulation-solidity-line
Jul 29, 2026
Merged

fix: Solidity move basic-oracle-manipulation test annotation to the matched line#3997
malaverdiere merged 1 commit into
developfrom
marc-andre/fix-oracle-manipulation-solidity-line

Conversation

@malaverdiere

@malaverdiere malaverdiere commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Relates to the Solidity grammar update from https://github.com/semgrep/semgrep-proprietary/pull/6721 and others..

Summary

The basic-oracle-manipulation test's pattern: $X.div($Y) match for underlyingUnit.mul(balanceWithInvested()).div(totalSupply()) is textually on the : (else) branch line of a multi-line ternary, not the line where the enclosing assignment starts. The // ruleid: annotation was placed one line above the wrong branch.

Confirmed by parsing the snippet directly with tree-sitter-solidity v1.2.13 (via semgrep/ocaml-tree-sitter-semgrep#626):

(ternary_expression
  (expression ...)                    ; condition: totalSupply() == 0
  (expression ...)                    ; then: underlyingUnit
  (expression (call_expression ...))) ; else: underlyingUnit.mul(...).div(...) -- entirely on its own line

The .div(...) call is entirely on the : branch's line — there's no way for a textually-accurate match to be reported one line earlier. This surfaced as a CI failure (1 false negative, 1 false positive) in semgrep-proprietary#6721, which bumps tree-sitter-solidity to v1.2.13 and produces a more precise AST for this multi-line ternary than whatever it replaced.

Change

Moves the // ruleid: basic-oracle-manipulation annotation from immediately above the assignment to immediately above the actual matched (:) branch. No line count change, so no ripple to other annotations later in the file.

Test plan

  • Verified via direct tree-sitter parse that the matched sub-expression's span is on the line the annotation now precedes.
  • CI green on this PR (semgrep-core test suite should now pass basic-oracle-manipulation.yaml).

🤖 Generated with Claude Code

@malaverdiere malaverdiere changed the title fix(solidity): move basic-oracle-manipulation test annotation to the matched line fix: Solidity move basic-oracle-manipulation test annotation to the matched line Jul 11, 2026
…nary precedence

The updated Solidity tree-sitter grammar correctly parses `cond ? x : y.div(z)`
as `cond ? x : (y.div(z))` (member access binds tighter than the ternary
operator). The basic-oracle-manipulation finding now points at the actual
`.div` call line rather than the start of the enclosing ternary, so move the
`ruleid` annotation to the corrected line.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@malaverdiere
malaverdiere force-pushed the marc-andre/fix-oracle-manipulation-solidity-line branch 2 times, most recently from 9f1890d to f2b6518 Compare July 28, 2026 22:01
@malaverdiere
malaverdiere requested review from kopecs and removed request for brandonspark July 28, 2026 22:09
@kopecs

kopecs commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Actually @malaverdiere you may need to make this change in https://github.com/semgrep/semgrep-rules-jsonnet to have it be properly handled

@malaverdiere

Copy link
Copy Markdown
Contributor Author

Actually @malaverdiere you may need to make this change in https://github.com/semgrep/semgrep-rules-jsonnet to have it be properly handled

That repo does not have a basic-oracle-manipulation.sol

@malaverdiere
malaverdiere merged commit 947bf05 into develop Jul 29, 2026
9 of 10 checks passed
@malaverdiere
malaverdiere deleted the marc-andre/fix-oracle-manipulation-solidity-line branch July 29, 2026 23:47
jmgrosen pushed a commit to semgrep/semgrep that referenced this pull request Aug 10, 2026
…proprietary#6563)

What:
Updates the `semgrep-solidity` tree-sitter grammar submodule (LANG-207)
and adapts the OCaml CST-to-generic mapping
(`Parse_solidity_tree_sitter.ml`) to the new grammar. Also bumps
`semgrep-rules` for the matching Solidity test annotation fix.

Pinned to the regenerated parser from
[semgrep/ocaml-tree-sitter-semgrep#605](semgrep/ocaml-tree-sitter-semgrep#605)
/
[semgrep/semgrep-solidity#4](semgrep/semgrep-solidity#4)
(`2f369b5`, tree-sitter **0.26.3**), and
[semgrep/semgrep-rules#3997](semgrep/semgrep-rules#3997).

New language support:
- **Transient storage** (EIP-1153): `transient` state location, `tload`,
`tstore`
- **Named mapping parameters**: `mapping(address owner => uint256
balance)`
- **Storage layout specifier** (0.8.29): `contract C layout at <expr>`
- **Assembly flags**: `assembly ("memory-safe") { ... }`
- **`global` using-directives** and **braced using-aliases**: `using {f,
g} for T`
- **Top-level events and using-directives**
- **EVM Cancun builtins**: `mcopy`, `blobhash`, `blobbasefee`,
`basefee`, `blobfee`, `prevrandao`

Removed (not valid Solidity): `>>>`, `>>>=`, `!==`, unary `+`

Behavioral fix: member access now binds tighter than the ternary `?:`
operator. Previously `cond ? x : y.div(z)` parsed as `(cond ? x :
y).div(z)`; it now correctly parses as `cond ? x : (y.div(z))`.

Why:
Bring Semgrep's Solidity parser in line with current Solidity /
tree-sitter-solidity so newer language features parse correctly and
ternary vs member-access precedence matches the language (LANG-207).

Test plan:
- [x] `make core` builds clean (tree-sitter 0.26.3)
- [x] Solidity parsing fixtures: 13/13 pass
- [x] Solidity-filtered OSS tests (`-s solidity`): 51 successful (50
pass, 1 xfail)
- [x] `semgrep-rules` pin includes the `basic-oracle-manipulation`
annotation fix for the precedence change

synced from Pro 4d3b802b1d97220fe51caf37895a5f72f5981036
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.

3 participants