Skip to content

Commit 5a86c8a

Browse files
iajoinerclaude
andauthored
feat: switch to new preprocessor (#1031)
# Rationale for this change Move to a new Yul preprocessor so Yul imports and snippets are handled cleanly (rename to .presl), and to consolidate preprocessing logic under versioned, testable Python code. The commit stream shows “add new Yul preprocessor,” then renames and import fixes to align on the new extension. # What changes are included in this PR? - New preprocessor module & tests Adds solidity/preprocessor/yul_preprocessor.py with pytest tests and a corpus of .presl fixtures covering imports, circular graphs, caching, function dedup, etc. - File/extension migration Renames .pre.sol → .presl; updates Solidity imports and config accordingly. Commits: “rename .pre.sol files to .presl”, “update imports and config”, plus “fix Yul imports.” - Build/Foundry config foundry.toml now ignores .presl for match/coverage/doc, replacing the old .pre.sol ignores. - CI workflow Adds a “Check Yul Preprocessor” job that sets up Python, runs black and pytest for solidity/preprocessor. In the main lint/test job, it removes preprocessor/test_files before coverage to avoid double counting. - Helper scripts & misc Adds solidity/scripts/pre_forge.sh and preprocess_yul_imports.sh; touches Slither config and several .sol files to match the new import pathing. # Are these changes tested? Yes! Dedicated pytest suite runs in CI for the preprocessor. All existing tests also pass. --------- Co-authored-by: Claude <[email protected]>
1 parent 4c35c05 commit 5a86c8a

File tree

115 files changed

+2512
-7912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+2512
-7912
lines changed

.github/workflows/lint-and-test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ jobs:
197197
steps:
198198
- name: Checkout repository
199199
uses: actions/checkout@v4
200+
- name: Set up Python
201+
uses: actions/setup-python@v5
202+
with:
203+
python-version: '3.x'
200204
- name: Install Foundry
201205
uses: foundry-rs/foundry-toolchain@v1
202206
with:
@@ -211,6 +215,8 @@ jobs:
211215
run: solidity/scripts/pre_forge.sh test --optimize
212216
- name: Run tests with via-ir and optimization
213217
run: solidity/scripts/pre_forge.sh test --via-ir --optimize
218+
- name: Remove preprocessor test files (for they are already tested in the check-yul-preprocessor job)
219+
run: rm -rf solidity/preprocessor/test_files
214220
- name: Install lcov
215221
run: sudo apt-get update && sudo apt-get install -y lcov
216222
- name: Check code coverage
@@ -245,6 +251,10 @@ jobs:
245251
steps:
246252
- name: Checkout repository
247253
uses: actions/checkout@v4
254+
- name: Set up Python
255+
uses: actions/setup-python@v5
256+
with:
257+
python-version: '3.x'
248258
- name: Install Foundry
249259
uses: foundry-rs/foundry-toolchain@v1
250260
with:

solidity/foundry.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ out = "out"
44
solc = "0.8.28"
55
libs = ["dependencies"]
66
deny-warnings = true
7-
no-match-path = "**/*.pre.sol"
8-
no-match-coverage = "pre.sol"
7+
no-match-path = "**/*.presl"
8+
no-match-coverage = "presl"
9+
ignored_paths = ["**/*.presl"]
910

1011
[doc]
11-
ignore = ["**/*.pre.sol"]
12+
ignore = ["**/*.presl"]
1213

1314
[dependencies]
1415
forge-std = "1.9.5"

solidity/scripts/README.md

Lines changed: 0 additions & 131 deletions
This file was deleted.

solidity/scripts/pre_forge.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -euo pipefail
33
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
44
cd $SCRIPT_DIR/..
5-
scripts/preprocess_yul_imports.sh src
6-
scripts/preprocess_yul_imports.sh test
5+
# Remove any existing .post.sol files
6+
find . -type f -name '*.post.sol' -delete
7+
python3 preprocessor/yul_preprocessor.py .
78
forge "$@"

solidity/scripts/preprocess_yul_imports.sh

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ library Array {
2828
/// @return __value The element at the specified index
2929
function __getArrayElement(uint256[][1] memory __array, uint256 __index) internal pure returns (uint256 __value) {
3030
assembly {
31-
// IMPORT-YUL Errors.sol
32-
function err(code) {
33-
revert(0, 0)
34-
}
31+
// import err from Errors.sol
3532
function get_array_element(arr_ptr, index) -> value {
3633
let arr := mload(arr_ptr)
3734
let length := mload(arr)
@@ -62,10 +59,7 @@ library Array {
6259
returns (uint256[2][] memory __array)
6360
{
6461
assembly {
65-
// IMPORT-YUL Errors.sol
66-
function err(code) {
67-
revert(0, 0)
68-
}
62+
// import err from Errors.sol
6963
function read_word_array_as_uint512_array(input_array_ptr) -> array_ptr {
7064
array_ptr := mload(FREE_PTR)
7165

@@ -126,10 +120,7 @@ library Array {
126120
returns (uint256 __upper, uint256 __lower)
127121
{
128122
assembly {
129-
// IMPORT-YUL Errors.sol
130-
function err(code) {
131-
revert(0, 0)
132-
}
123+
// import err from Errors.sol
133124
function get_uint512_array_element(arr_ptr, index) -> upper, lower {
134125
let arr := mload(arr_ptr)
135126
let length := mload(arr)
Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pragma solidity ^0.8.28;
44

55
import "./Constants.sol";
6-
import "./SwitchUtil.pre.sol";
6+
import "./SwitchUtil.presl";
77

88
/// @title DataType
99
/// @dev Library providing parsing utilities for different data types
@@ -29,14 +29,8 @@ library DataType {
2929
returns (bytes calldata __exprOut, uint256 __entry)
3030
{
3131
assembly {
32-
// IMPORT-YUL Errors.sol
33-
function err(code) {
34-
revert(0, 0)
35-
}
36-
// IMPORT-YUL SwitchUtil.pre.sol
37-
function case_const(lhs, rhs) {
38-
revert(0, 0)
39-
}
32+
// import err from Errors.sol
33+
// import case_const from SwitchUtil.presl
4034
function read_binary(result_ptr) -> result_ptr_out, entry {
4135
let free_ptr := mload(FREE_PTR)
4236
let len := shr(UINT64_PADDING_BITS, calldataload(result_ptr))
@@ -84,7 +78,7 @@ library DataType {
8478
result_ptr_out := add(result_ptr, len)
8579
}
8680

87-
// slither-disable-next-line cyclomatic-complexity
81+
// slither-disable-start cyclomatic-complexity
8882
function read_entry(result_ptr, data_type_variant) -> result_ptr_out, entry {
8983
result_ptr_out := result_ptr
9084
switch data_type_variant
@@ -152,6 +146,7 @@ library DataType {
152146
}
153147
default { err(ERR_UNSUPPORTED_DATA_TYPE_VARIANT) }
154148
}
149+
// slither-disable-end cyclomatic-complexity
155150
let __exprOutOffset
156151
__exprOutOffset, __entry := read_entry(__expr.offset, __dataTypeVariant)
157152
__exprOut.offset := __exprOutOffset
@@ -179,14 +174,8 @@ library DataType {
179174
returns (bytes calldata __exprOut, uint32 __dataType)
180175
{
181176
assembly {
182-
// IMPORT-YUL Errors.sol
183-
function err(code) {
184-
revert(0, 0)
185-
}
186-
// IMPORT-YUL SwitchUtil.pre.sol
187-
function case_const(lhs, rhs) {
188-
revert(0, 0)
189-
}
177+
// import err from Errors.sol
178+
// import case_const from SwitchUtil.presl
190179
function read_data_type(ptr) -> ptr_out, data_type {
191180
data_type := shr(UINT32_PADDING_BITS, calldataload(ptr))
192181
ptr_out := add(ptr, UINT32_SIZE)

0 commit comments

Comments
 (0)