Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
115 changes: 115 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,121 @@ lint: rustfmt clippy
build-docs:
cargo doc --no-deps --workspace

.PHONY: foundry-abi-generate
foundry-abi-generate:
python3 benchmarks/foundry-abi/scripts/generate_matrix.py

.PHONY: foundry-abi-build-fe
foundry-abi-build-fe: foundry-abi-generate
cargo run --release -q -p fe -- build --backend sonatina --contract AbiRoundtripFe --out-dir benchmarks/foundry-abi/fe-out benchmarks/foundry-abi/fe/AbiRoundtrip.fe

.PHONY: foundry-abi-test
foundry-abi-test: foundry-abi-build-fe-all
forge test --root benchmarks/foundry-abi --offline

.PHONY: foundry-abi-gas
foundry-abi-gas: foundry-abi-build-fe-all
python3 benchmarks/foundry-abi/scripts/run_gas_report.py

.PHONY: foundry-abi-build-fe-all
foundry-abi-build-fe-all: foundry-abi-build-fe foundry-abi-build-fe-dyn foundry-abi-build-fe-bytes foundry-abi-build-fe-deep foundry-abi-build-fe-fixed foundry-abi-build-fe-ceiling foundry-abi-build-fe-nested

.PHONY: foundry-abi-build-fe-dyn
foundry-abi-build-fe-dyn:
cargo run --release -q -p fe -- build --backend sonatina --contract DynArraySuite --out-dir benchmarks/foundry-abi/fe-out benchmarks/foundry-abi/fe/DynArraySuite.fe

.PHONY: foundry-abi-test-dyn
foundry-abi-test-dyn: foundry-abi-build-fe-dyn
forge test --root benchmarks/foundry-abi --offline --match-path test/DynArraySuiteEquivalence.t.sol

.PHONY: foundry-abi-gas-dyn
foundry-abi-gas-dyn: foundry-abi-build-fe-dyn
forge test --root benchmarks/foundry-abi --offline --match-path test/DynArraySuiteEquivalence.t.sol --gas-report

.PHONY: foundry-abi-build-fe-bytes
foundry-abi-build-fe-bytes:
cargo run --release -q -p fe -- build --backend sonatina --contract BytesSuite --out-dir benchmarks/foundry-abi/fe-out benchmarks/foundry-abi/fe/BytesSuite.fe

.PHONY: foundry-abi-test-bytes
foundry-abi-test-bytes: foundry-abi-build-fe-bytes
forge test --root benchmarks/foundry-abi --offline --match-path test/BytesSuiteEquivalence.t.sol

.PHONY: foundry-abi-gas-bytes
foundry-abi-gas-bytes: foundry-abi-build-fe-bytes
forge test --root benchmarks/foundry-abi --offline --match-path test/BytesSuiteEquivalence.t.sol --gas-report

.PHONY: foundry-abi-build-fe-deep
foundry-abi-build-fe-deep:
cargo run --release -q -p fe -- build --backend sonatina --contract DeepDynamicSuite --out-dir benchmarks/foundry-abi/fe-out benchmarks/foundry-abi/fe/DeepDynamicSuite.fe

.PHONY: foundry-abi-build-fe-fixed
foundry-abi-build-fe-fixed:
cargo run --release -q -p fe -- build --backend sonatina --contract FixedArraySuite --out-dir benchmarks/foundry-abi/fe-out benchmarks/foundry-abi/fe/FixedArraySuite.fe

.PHONY: foundry-abi-build-fe-ceiling
foundry-abi-build-fe-ceiling:
cargo run --release -q -p fe -- build --backend sonatina --contract FixedArrayCeilingSuite --out-dir benchmarks/foundry-abi/fe-out benchmarks/foundry-abi/fe/FixedArrayCeilingSuite.fe

.PHONY: foundry-abi-build-fe-nested
foundry-abi-build-fe-nested:
cargo run --release -q -p fe -- build --backend sonatina --contract NestedTupleSuite --out-dir benchmarks/foundry-abi/fe-out benchmarks/foundry-abi/fe/NestedTupleSuite.fe

.PHONY: foundry-abi-test-deep
foundry-abi-test-deep: foundry-abi-build-fe-deep
forge test --root benchmarks/foundry-abi --offline --match-path test/DeepDynamicSuiteEquivalence.t.sol

.PHONY: foundry-abi-test-fixed
foundry-abi-test-fixed: foundry-abi-build-fe-fixed
forge test --root benchmarks/foundry-abi --offline --match-path test/FixedArraySuiteEquivalence.t.sol

.PHONY: foundry-abi-test-ceiling
foundry-abi-test-ceiling: foundry-abi-build-fe-ceiling
forge test --root benchmarks/foundry-abi --offline --match-path test/FixedArrayCeilingSuiteEquivalence.t.sol

.PHONY: foundry-abi-test-nested
foundry-abi-test-nested: foundry-abi-build-fe-nested
forge test --root benchmarks/foundry-abi --offline --match-path test/NestedTupleSuiteEquivalence.t.sol

.PHONY: foundry-abi-gas-deep
foundry-abi-gas-deep: foundry-abi-build-fe-deep
forge test --root benchmarks/foundry-abi --offline --match-path test/DeepDynamicSuiteEquivalence.t.sol --gas-report

.PHONY: foundry-abi-gas-fixed
foundry-abi-gas-fixed: foundry-abi-build-fe-fixed
forge test --root benchmarks/foundry-abi --offline --match-path test/FixedArraySuiteEquivalence.t.sol --gas-report

.PHONY: foundry-abi-gas-ceiling
foundry-abi-gas-ceiling: foundry-abi-build-fe-ceiling
forge test --root benchmarks/foundry-abi --offline --match-path test/FixedArrayCeilingSuiteEquivalence.t.sol --gas-report

.PHONY: foundry-abi-gas-nested
foundry-abi-gas-nested: foundry-abi-build-fe-nested
forge test --root benchmarks/foundry-abi --offline --match-path test/NestedTupleSuiteEquivalence.t.sol --gas-report

.PHONY: foundry-abi-stress-dyn
foundry-abi-stress-dyn: foundry-abi-build-fe-dyn
forge test --root benchmarks/foundry-abi --offline --threads 0 --fuzz-runs $${FUZZ_RUNS:-20000} --match-path test/DynArraySuiteEquivalence.t.sol

.PHONY: foundry-abi-stress-bytes
foundry-abi-stress-bytes: foundry-abi-build-fe-bytes
forge test --root benchmarks/foundry-abi --offline --threads 0 --fuzz-runs $${FUZZ_RUNS:-20000} --match-path test/BytesSuiteEquivalence.t.sol

.PHONY: foundry-abi-stress-deep
foundry-abi-stress-deep: foundry-abi-build-fe-deep
forge test --root benchmarks/foundry-abi --offline --threads 0 --fuzz-runs $${FUZZ_RUNS:-20000} --match-path test/DeepDynamicSuiteEquivalence.t.sol

.PHONY: foundry-abi-stress-fixed
foundry-abi-stress-fixed: foundry-abi-build-fe-fixed
forge test --root benchmarks/foundry-abi --offline --threads 0 --fuzz-runs $${FUZZ_RUNS:-5000} --match-path test/FixedArraySuiteEquivalence.t.sol

.PHONY: foundry-abi-stress-ceiling
foundry-abi-stress-ceiling: foundry-abi-build-fe-ceiling
forge test --root benchmarks/foundry-abi --offline --threads 0 --fuzz-runs $${FUZZ_RUNS:-2000} --match-path test/FixedArrayCeilingSuiteEquivalence.t.sol

.PHONY: foundry-abi-stress-nested
foundry-abi-stress-nested: foundry-abi-build-fe-nested
forge test --root benchmarks/foundry-abi --offline --threads 0 --fuzz-runs $${FUZZ_RUNS:-5000} --match-path test/NestedTupleSuiteEquivalence.t.sol

README.md: src/main.rs
cargo readme --no-title --no-indent-headings > README.md

Expand Down
21 changes: 21 additions & 0 deletions PR_OPTIMIZATIONS_TABLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ABI Optimization PR Table

| Metric | Before (parity snapshot) | After (this series) | Delta |
| --- | ---: | ---: | ---: |
| Mean gas delta (Fe avg - Solidity avg) | +1588.82 | -579.71 | -2168.53 |
| Median gas delta (Fe avg - Solidity avg) | +1534.00 | -33.00 | -1567.00 |
| Best single-case delta | -1078 (`benchEchoBoolAddressPairArray`) | -6865 (-12.95%) (`benchEchoStringU64PairArray`) | n/a |
| Worst single-case delta | +5203 (`benchEchoStringU64PairArray2`) | +34 (+0.13%) (`benchEchoInt56`) | n/a |

| Commit | Area | Change |
| --- | --- | --- |
| [`9e0167d0f`](https://github.com/argotorg/fe/commit/9e0167d0f2ef086d3faec726cee984e4167f35e5) | ABI dynamic payloads | Bulk-copy dynamic ABI payloads and tighten dynamic-span calculations. |
| [`ee68df1e0`](https://github.com/argotorg/fe/commit/ee68df1e08fc313520b9356642f3be7c0394561f) | Solidity ABI custom integers | Cheaper custom-width canonical checks; `signextend`-based signed checks; tighten runtime lowering. |
| [`804fb842f`](https://github.com/argotorg/fe/commit/804fb842f04b0a10fcb6e62f3dd3d0c657e31e12) | ABI copy lowering | Lower core `mcopy` as an intrinsic across MIR/Yul/Sonatina. |
| [`59ba5430a`](https://github.com/argotorg/fe/commit/59ba5430ac8eece96bd4b4e7da167427b233ff0f) | ABI encode | Fast-path `DIRECT_ENCODE` `encode_to_ptr`. |
| [`96c078014`](https://github.com/argotorg/fe/commit/96c07801457ff83dcfc24f839117bf582530917c) | ABI passthrough validation | Add calldata passthrough validation fast paths across lowering/validation. |
| [`205555dd3`](https://github.com/argotorg/fe/commit/205555dd354677e457162777508c127789df0494) | Tuple/fixed-array validation | Optimize tuple + fixed-array `AbiValidate` and inline hot checks. |
| [`aa158ec69`](https://github.com/argotorg/fe/commit/aa158ec69dcc72d4b7d5d943b642fab15bc6f690) | Runtime selector dispatch | Replace linear selector dispatch with binary search. |
| [`4120cbccf`](https://github.com/argotorg/fe/commit/4120cbccf6e260f4438a49f8bdce0a7773dea03b) | ABI passthrough runtime | Avoid malloc in ABI passthrough arms by constructing calldata views directly. |
| [`9f8000eda`](https://github.com/argotorg/fe/commit/9f8000eda025cacc8d89b6ad44d753343896f374) | Calldata validation arithmetic | Avoid checked arithmetic in calldata view validation where bounds are established. |
| [`4a5777d33`](https://github.com/argotorg/fe/commit/4a5777d33909dc8fab8db298c9c9de6581379263) | Scalar/static ABI decode | Optimize scalar word decode + static ABI decode/validation; final source checkpoint used by the reports. |
6 changes: 6 additions & 0 deletions benchmarks/foundry-abi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cache/
out/
broadcast/
fe-out/
__pycache__/
*.pyc
Loading
Loading