Skip to content
Draft
Show file tree
Hide file tree
Changes from 183 commits
Commits
Show all changes
210 commits
Select commit Hold shift + click to select a range
fcaeef2
first draft by claude, untestet
xermicus Feb 2, 2026
ae2f532
it did something
xermicus Feb 3, 2026
f7ae880
it fixed something
xermicus Feb 3, 2026
d42ba52
it fixed something
xermicus Feb 4, 2026
874aebb
it fixed something
xermicus Feb 4, 2026
da717f1
it struggles hard
xermicus Feb 4, 2026
663baed
its so confused not even /clear helps anymore
xermicus Feb 4, 2026
3bfe43a
it contemplates its miserable existence
xermicus Feb 4, 2026
6ae1d79
it did something again
xermicus Feb 5, 2026
c2f3f39
the plan lol
xermicus Feb 5, 2026
890c243
it finally achieved something
xermicus Feb 5, 2026
2161c76
update
xermicus Feb 5, 2026
1b9db52
it ensured tests pass
xermicus Feb 5, 2026
7fe1fac
it did something
xermicus Feb 5, 2026
b455de5
it fixed something
xermicus Feb 5, 2026
596aa54
it implemented some more opts
xermicus Feb 5, 2026
73b7dcc
it fixed something
xermicus Feb 5, 2026
7655d9e
it fixed something
xermicus Feb 6, 2026
c5bffda
update plan
xermicus Feb 6, 2026
80b2826
it thought 2 hourse for this lol
xermicus Feb 6, 2026
255892f
it did stuff again
xermicus Feb 6, 2026
7433d56
it fixed everything
xermicus Feb 6, 2026
0d25537
type-inference narrowing + inliner fix for large contracts
xermicus Feb 6, 2026
05c9b77
FMP range proof: mload(64) truncate-extend eliminates overflow checks
xermicus Feb 6, 2026
010ce0d
32-bit FMP range proof + region annotation + builtin range proofs
xermicus Feb 7, 2026
4cd89c2
conditional sbrk NoInline + interprocedural param narrowing infrastru…
xermicus Feb 7, 2026
44b2c25
preserve 32-bit FMP range proof in Let-binding narrowing
xermicus Feb 7, 2026
39ae0dc
keccak256 fusion + FMP propagation + interprocedural narrowing
xermicus Feb 7, 2026
4016673
panic revert outlining + shared return blocks
xermicus Feb 7, 2026
04bbbd1
environment read CSE + storage by-value + caller outlining
xermicus Feb 7, 2026
1ad9137
native FMP store/load + interprocedural return narrowing + storage by…
xermicus Feb 8, 2026
13f9732
fuzzy function deduplication (parameterize by differing literals)
xermicus Feb 8, 2026
a10fa71
callvalue nonzero boolean outlining
xermicus Feb 8, 2026
2613d4e
fuzzy dedup: count unique differing values, not positions
xermicus Feb 8, 2026
8ec9a85
outlined revert functions for common exit patterns
xermicus Feb 8, 2026
53f3438
stop → shared return block deduplication
xermicus Feb 8, 2026
6f16b3c
global constant pool for i256 storage keys
xermicus Feb 8, 2026
2d130ff
outlined keccak256 slot wrappers for constant mapping keys
xermicus Feb 8, 2026
dbcfc92
fix: remove FMP i32 store/load shortcuts and harden heap_opt soundness
xermicus Feb 8, 2026
a6889e4
keccak256 single-word fusion and sbrk NoInline fix
xermicus Feb 8, 2026
cadaa63
type inference: FMP MLoad returns I32 for interprocedural narrowing
xermicus Feb 8, 2026
93fa0ac
compile-time constant keccak256 folding
xermicus Feb 8, 2026
811783b
keccak fold: handle Statement::Block + update codesize baselines
xermicus Feb 8, 2026
1c09c2f
fix: scope type inference per object and use body-based param narrowing
xermicus Feb 8, 2026
2c8988d
Restored DCE pass and added safety fix for type narrowing
xermicus Feb 10, 2026
68698cd
fix: use provably safe structural narrowing instead of unsound type i…
xermicus Feb 22, 2026
a19c1eb
fix: backward demand-driven param narrowing for sound type inference
xermicus Feb 22, 2026
bb50682
Merge branch 'main' into cl/newyork
xermicus Feb 22, 2026
2aeba68
fix: BlobHash opcode collision in function deduplication
xermicus Feb 23, 2026
c8e47c9
fix: remove redundant subobject heap analysis and wire mem_opt results
xermicus Feb 23, 2026
fda65c3
perf: add full simplify pass after mem_opt/FMP/keccak fold
xermicus Feb 23, 2026
ba93b68
fix: inliner argument count assertion and MStore8 pending store key
xermicus Feb 23, 2026
66c2650
fix: enable IR validation in release builds
xermicus Feb 23, 2026
e91022e
perf: preserve memory state across control flow in mem_opt
xermicus Feb 23, 2026
7cf0cdd
fix: correct tautological effective_width formula and remove dead code
xermicus Feb 23, 2026
e613c61
fix: use quadratic leave overhead in inliner cost model
xermicus Feb 23, 2026
a5d6eca
docs: document why backward demand narrowing is not wired into codegen
xermicus Feb 23, 2026
2ab23c4
perf: demand-driven narrow codegen and iterative parameter narrowing
xermicus Feb 23, 2026
744d1f8
docs: document optimization opportunities in newyork optimizer
xermicus Feb 23, 2026
f0407cb
docs: document optimization opportunities in newyork optimizer
xermicus Feb 23, 2026
3eb058b
docs: add 20+ optimization opportunities for newyork optimizer
xermicus Feb 23, 2026
b8d442b
fix: keep calldataload offset at i256 to prevent incorrect truncation
xermicus Feb 23, 2026
eb06b3f
docs: add newyork optimizer documentation page to compiler book
xermicus Feb 24, 2026
f3ddb34
Merge branch 'main' into cl/newyork
xermicus Mar 5, 2026
9b6d594
feat: implement per-access native heap mode for free memory pointer
xermicus Mar 6, 2026
060607d
fix: improve heap analysis correctness for per-access native mode
xermicus Mar 6, 2026
fc747c6
docs: update RALPH_TASK.md with heap analysis correctness fixes
xermicus Mar 6, 2026
556fc5b
feat: skip msize watermark update when contract doesn't use msize
xermicus Mar 6, 2026
099f4b6
docs: update RALPH_TASK.md with final optimization results
xermicus Mar 6, 2026
ac452e5
chore: update codesize_newyork.json for heap optimization improvements
xermicus Mar 6, 2026
14d54e9
feat: expand InlineNative heap optimization beyond reserved region
xermicus Mar 6, 2026
7c8a658
feat: add InlineByteSwap mode for constant-offset heap accesses
xermicus Mar 6, 2026
435d62f
feat: use inline bswap in keccak256 helper functions
xermicus Mar 6, 2026
4432776
fix: correct heap analysis for FMP safety, keccak256 taint, and dynam…
xermicus Mar 7, 2026
571421e
fix: track variable-accessed offsets to prevent native/byteswap mode …
xermicus Mar 7, 2026
3931a9f
docs: update RALPH_TASK.md with Iteration 6 results
xermicus Mar 7, 2026
277a490
fix: resolve infinite loop in heap analysis for cross-object ValueId …
xermicus Mar 7, 2026
4314a35
docs: update RALPH_TASK.md with Iteration 7 results
xermicus Mar 7, 2026
0b147e1
fix: track for-loop carried variables as non-literal in heap analysis
xermicus Mar 7, 2026
5b11a36
feat: add compound outlining pass to newyork optimizer
xermicus Mar 7, 2026
0cefe81
feat: add guard narrowing pass and improve type demand transparency
xermicus Mar 7, 2026
3d62f23
docs: update RALPH_TASK.md with Iteration 9 results
xermicus Mar 7, 2026
0618ca7
feat: optimize dynamic-offset memory access by eliminating sbrk overhead
xermicus Mar 7, 2026
a5f14ab
feat: eliminate sbrk from dynamic return/revert/log for non-msize con…
xermicus Mar 7, 2026
1d03bf0
fix: revert unsound dynamic sbrk elimination, add safe constant-offse…
xermicus Mar 7, 2026
2b16a77
feat: bypass sbrk for dynamic-offset memory ops in non-msize contracts
xermicus Mar 8, 2026
97e3aa1
feat: add outlined exit_checked for dynamic return/revert in non-msiz…
xermicus Mar 8, 2026
a53d20d
feat: add value-based storage functions to eliminate alloca+store ove…
xermicus Mar 8, 2026
8628dd3
feat: add compound outlining pass for mapping access patterns
xermicus Mar 8, 2026
df2f14c
update task
xermicus Mar 8, 2026
71ebb49
fix: correct unsigned wrapping in exit_checked bounds check
xermicus Mar 8, 2026
50ee9e8
update task
xermicus Mar 8, 2026
cae80a5
feat: enable calldataload outlining for contracts with >=20 call sites
xermicus Mar 8, 2026
b00d1b9
feat: tune inliner thresholds and add PolkaVM Yul optimizer sequence
xermicus Mar 8, 2026
0881c7b
feat: add LLVM IPSCCP post-pass and second dedup pass for code size r…
xermicus Mar 8, 2026
1b36dcc
feat: add second LLVM optimization pass with polkavm-linker workaround
xermicus Mar 8, 2026
5e66f6d
feat: store/load FMP as i32 in InlineNative mode
xermicus Mar 8, 2026
b0b059d
feat: entry-block alloca hoisting and mapping threshold reduction
xermicus Mar 8, 2026
905ab4e
refactor: deduplicate IR traversals and remove dead code in newyork
xermicus Mar 9, 2026
23d9b23
new riscv backend flags
xermicus Mar 9, 2026
d5fe689
feat: comparison-relaxed parameter narrowing in type inference
xermicus Mar 9, 2026
86a416f
feat: add store-zero and return-word outlined functions for code size
xermicus Mar 10, 2026
30a90ad
feat: re-run full type inference after parameter narrowing
xermicus Mar 10, 2026
f25b2fd
feat: mark multi-call CostBenefit functions as noinline
xermicus Mar 10, 2026
8f94be0
feat: add i128 narrowing tier for reduced register pressure
xermicus Mar 10, 2026
8fefc42
feat: improve provable_narrow_width with Add/Mul and recursive depth
xermicus Mar 10, 2026
99c03cd
feat: add return type narrowing, caller-based param narrowing, and eq…
xermicus Mar 12, 2026
a656a8e
feat: add loop variable demand-based narrowing for smaller code
xermicus Mar 13, 2026
21212bb
Merge branch 'main' into cl/newyork
xermicus Mar 25, 2026
bf84961
update codesize.json
xermicus Mar 25, 2026
935b1bb
update book
xermicus Mar 25, 2026
cbbc6dd
the retester script
xermicus Mar 27, 2026
a53c5ae
feat: add LICM disable, machine outliner, and guard-narrow return fix
xermicus Mar 14, 2026
98049b1
feat: add interprocedural validator narrowing for address types
xermicus Mar 14, 2026
62af31a
feat: tune inliner thresholds for smaller code on rv64e
xermicus Mar 14, 2026
03d3494
feat: add NoUnwind attribute and tune inliner for code size
xermicus Mar 14, 2026
9d1b2a1
feat: lower single-call inline threshold from 30 to 22 for smaller code
xermicus Mar 14, 2026
5629499
update revive-differential-tests submodule
xermicus Mar 31, 2026
a68a03c
update revive-differential-tests submodule
xermicus Apr 2, 2026
1631b9c
fix: push function scope in newyork generate_object to prevent ICE
xermicus Apr 8, 2026
3238884
revert: remove catch_unwind workaround from polkavm linker
xermicus Apr 8, 2026
e24b2f3
init fuzzer
xermicus Apr 20, 2026
a4c5e4c
fuzzer: parallelize, cap memory, accurate calldata
xermicus Apr 20, 2026
ccca38d
newyork: stop demand-narrowing memory offsets, fixes mload(huge) bypass
xermicus Apr 20, 2026
6812f41
fuzzer: add --forever for continuous runs
xermicus Apr 20, 2026
0f1373d
fuzzer: boundary-biased calldata + stateful sequences
xermicus Apr 20, 2026
1fd6063
newyork: FMP native mode unsafe under dynamic mloads
xermicus Apr 20, 2026
c12fb90
fuzzer: filter abstract/interface contracts, try candidates in reverse
xermicus Apr 21, 2026
1e2d485
newyork: FreePointerSlot region must match exactly 0x40, not 0x40..0x60
xermicus Apr 21, 2026
b46129a
newyork: support switch case values > u64::MAX
xermicus Apr 22, 2026
bcbaa35
review: drop orphaned `mod exact_repro` decl from integration/lib.rs
xermicus Apr 28, 2026
9b57fbc
review: remove debug-quality exact_repro.rs test module
xermicus Apr 28, 2026
24e7a1f
review: revert RESOLC_USE_NEWYORK branching in codesize test
xermicus Apr 28, 2026
8e4dd79
review: drop circular `default<O1>` second pass in optimizer pipeline
xermicus Apr 28, 2026
37f3da4
review: document why `set_default_attributes` adds NoFree+NoUnwind
xermicus Apr 28, 2026
f7e7a4c
review: express `memory(none)` via `RuntimeFunction::ATTRIBUTES`
xermicus Apr 28, 2026
5e05451
review: relocate exact_repro tests into tests.rs and remove the file
xermicus Apr 28, 2026
4660e7e
review: revert RESOLC_USE_NEWYORK branching in codesize test
xermicus Apr 28, 2026
da46456
review: keep `default<O1>` second pass, document the real reason
xermicus Apr 29, 2026
6056f29
review: document why `set_default_attributes` adds NoFree+NoUnwind
xermicus Apr 28, 2026
6226524
review: express `memory(none)` via `RuntimeFunction::ATTRIBUTES`
xermicus Apr 28, 2026
c6c898a
newyork: extract IR visitor helpers, replace ~10 walker families
xermicus May 4, 2026
6a16814
newyork: collapse InlineRemapper, tighten simplify_binary, dedup lite…
xermicus May 4, 2026
81bdf3a
newyork: convert heap_opt + rewrite_* + fold_keccak walkers
xermicus May 4, 2026
e7640b3
newyork: factor strength_reduce template + to_llvm cmp helper
xermicus May 4, 2026
686fe91
newyork: convert mem_opt::collect_callees to for_each_stmt
xermicus May 4, 2026
bedf6a4
review: relocate exact_repro tests into tests.rs and remove the file
xermicus Apr 28, 2026
c648c04
review: keep `default<O1>` second pass, document the real reason
xermicus Apr 29, 2026
722ef5e
Merge branch 'cl/newyork' into refac
xermicus May 4, 2026
e0d03e6
newyork: avoid per-statement BTreeSet clone in propagate_demands_block
xermicus May 4, 2026
8c07cf9
rm stale files
xermicus May 5, 2026
9238e1d
rm stale files
xermicus May 5, 2026
34e0407
rm stale files
xermicus May 5, 2026
80b14de
rm stale files
xermicus May 5, 2026
41fb120
rm stale files
xermicus May 5, 2026
7623644
upadte book
xermicus May 6, 2026
d6e42f2
newyork: guard-narrow OR-chains and panic-helper terminators
xermicus May 7, 2026
d6ed33a
newyork: narrow add operands when overflow check is in the OR-chain
xermicus May 7, 2026
2fa9344
newyork: narrow on iszero(lt(val, K)) where K is a power of two
xermicus May 7, 2026
0a3f45d
newyork: specialised low-word store for constant-value MStore
xermicus May 7, 2026
bffdfb4
newyork: specialised high-word store for shl(224, sel) ABI selectors
xermicus May 7, 2026
51daf2e
newyork: gate specialised constant-store helpers by call-site count
xermicus May 7, 2026
549488e
newyork: narrow finalize_allocation params via structural detection
xermicus May 7, 2026
06c39be
newyork: extend allocator-shape detection to single-param size valida…
xermicus May 7, 2026
e7bd65a
newyork: only narrow finalize_allocation p0 to preserve panic semantics
xermicus May 7, 2026
d072e20
newyork: insert early p1 bound check inside finalize_allocation body
xermicus May 7, 2026
5a36c9a
newyork: extend FMP range proof to non-native-safe contracts
xermicus May 7, 2026
8578caa
newyork: tighten FMP range proof to bits(heap_size - 1)
xermicus May 7, 2026
ca4e202
book: document FMP byte-order vs value-bound separation + soundness t…
xermicus May 8, 2026
367f7a2
update book
xermicus May 8, 2026
7e03477
code review
xermicus May 8, 2026
cd557b9
bugfix
xermicus May 8, 2026
b69aec0
review
xermicus May 8, 2026
ae8c0f4
code review
xermicus May 8, 2026
1e5bae1
bugfix
xermicus May 8, 2026
18e39b5
review
xermicus May 10, 2026
82bd1a3
review
xermicus May 11, 2026
1961b70
remove more garbage AI slop
xermicus May 11, 2026
bf8a590
remove more AI slop garbage
xermicus May 11, 2026
d94a84c
fix more AI slop
xermicus May 11, 2026
3cd9810
remove a lot of AI garbage
xermicus May 11, 2026
2d71a4e
add env vars to book
xermicus May 11, 2026
6ea5672
Improve the inliner (#3)
May 15, 2026
72513bd
add failing test cases (#4)
May 20, 2026
f6e64c3
cl/soundness (#5)
May 21, 2026
6627828
Merge main into cl/newyork
xermicus May 21, 2026
ada3f2d
Add reference page for newyork IR (#522)
elle-j May 22, 2026
7e49770
remove deprecated target vm feature flag
xermicus May 22, 2026
9985570
Fix newyork regressions from main merge
xermicus May 22, 2026
4e77b52
Whitelist 6 known `blockhash(max u256)` failures at S-
xermicus May 22, 2026
c7e54b8
clippy
xermicus May 22, 2026
0d0e555
newyork: type fresh-ID counters as ValueId instead of raw u32
xermicus May 26, 2026
330b6cc
newyork: split SsaBuilder::define into declare and assign
xermicus May 26, 2026
2b1533e
newyork: ICE on unbalanced SsaBuilder::exit_scope
xermicus May 26, 2026
0d7b505
newyork: rename SsaBuilder::fresh_value to fresh_id
xermicus May 26, 2026
b0dc5d6
Improve the IR validation
May 26, 2026
9a736bb
newyork: name the few-callsites bonus literals
xermicus May 26, 2026
5e21fe6
newyork: extend EnvRead CSE to all invocation-constant nullary expres…
xermicus May 26, 2026
a0fa332
newyork: name the exact-dedup size threshold
xermicus May 26, 2026
0155cc6
Merge branch 'main' into cl/newyork
xermicus Jun 1, 2026
56277cf
fix printer bug
xermicus Jun 1, 2026
e217dbc
wire up missing mem-opt statistics into debug-logging
xermicus Jun 1, 2026
5f23b96
extract MemoryRegion::is_free_pointer_slot helper
xermicus Jun 1, 2026
0dcf55d
remove some magic numbers
xermicus Jun 1, 2026
433faee
cleanup
xermicus Jun 1, 2026
b96159c
dump all ny debug artifacts into the debug output dir
xermicus Jun 1, 2026
069e835
ir dumps show inferred type widths
xermicus Jun 1, 2026
f2dd3ec
annotate IR dumps with inferred type widths, using per-subobject infe…
xermicus Jun 1, 2026
4340bd9
printer: dont drop post_input_variables
xermicus Jun 1, 2026
ea7d4cd
printer: use write_value for custom_error_revert args
xermicus Jun 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ playwright-report
.cache
emsdk
docs-tmp
workdir
17 changes: 14 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@ make test-yul # Yul parser tests
make format # Check formatting (cargo fmt --all --check)
make clippy # Run clippy with --deny warnings

# Run single test
cargo test --package <crate-name> <test_name>
cargo test --package revive-integration <test_name>
```

**For verifying work, claiming a task done, or pre-commit checks: only ever run
`make test*` targets — never raw `cargo test`.** Integration and resolc tests
invoke the installed `resolc` binary as a subprocess. Each `make test*` target
already declares `install-bin` (or `install`) as a dependency, so it always
rebuilds and installs a fresh binary before running tests. Raw `cargo test`
does not — it builds the test binary but leaves system `resolc` stale, so it
passes against code the test isn't actually exercising. That mismatch is
exactly why raw `cargo test` is an anti-pattern for validation.

The one legitimate exception is **actively debugging a single test** for fast
iteration: run `make install-bin` first to refresh the binary, then iterate with
`cargo test --package <crate> <test_name>`, re-running `make install-bin`
between code changes. Never use this exception for validation.

## Crate Architecture

All crates live in `crates/`. Key crates:
Expand Down
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ revive-differential = { version = "1.0.0", path = "crates/differential" }
revive-integration = { version = "1.0.0", path = "crates/integration" }
revive-linker = { version = "1.0.0", path = "crates/linker" }
revive-llvm-context = { version = "1.0.0", path = "crates/llvm-context" }
revive-newyork = { version = "1.0.0", path = "crates/newyork" }
revive-runner = { version = "1.0.0", path = "crates/runner" }
revive-runtime-api = { version = "1.0.0", path = "crates/runtime-api" }
revive-solc-json-interface = { version = "1.0.0", path = "crates/solc-json-interface", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [Developer Guide](./developer_guide.md)
- [Contributor guide](./developer_guide/contributing.md)
- [Compiler architecture](./developer_guide/architecture.md)
- [The newyork optimizer](./developer_guide/newyork_optimizer.md)
- [PVM and the pallet-revive runtime target](./developer_guide/target.md)
- [Testing strategy](./developer_guide/testing.md)
- [Cross compilation](./developer_guide/cross_compilation.md)
Expand Down
2 changes: 1 addition & 1 deletion book/src/developer_guide/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ We also maintain the [lld-sys crate](https://crates.io/crates/lld-sys) for inter

## Custom optimizations

At the moment, no significant custom optimizations are implemented. Thus, we are missing some optimization opportunities that neither `solc` nor LLVM can realize (due to their lack of domain specific knowledge about the semantics of our target environment). Furthermore, `solc` optimizes for EVM gas and a target machine orthogonal to our target (BE 256-bit stack machine EVM vs. 64-bit LE RISC architecture PVM). We have started working on an additional IR layer between Yul and LLVM to capture missed optimization opportunities, though.
An experimental [`newyork` optimizer](./newyork_optimizer.md) introduces a custom IR layer between Yul and LLVM IR to capture optimization opportunities that neither `solc` nor LLVM can realize on their own. `solc` optimizes for EVM gas on a 256-bit big-endian stack machine, while LLVM lacks the domain knowledge to understand EVM memory semantics or Solidity patterns. The newyork IR bridges this gap with passes for type narrowing, memory optimization, function deduplication, and more.
284 changes: 284 additions & 0 deletions book/src/developer_guide/newyork_optimizer.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) mod extension;
pub(crate) mod keccak256;
pub(crate) mod metadata;
pub(crate) mod object;
pub(crate) mod solidity_selector;
pub(crate) mod utils;

pub use self::base::*;
Expand All @@ -21,5 +22,6 @@ pub use self::extension::*;
pub use self::keccak256::*;
pub use self::metadata::*;
pub use self::object::*;
pub use self::solidity_selector::*;
pub use self::utils::*;
pub use contract_identifier::*;
22 changes: 22 additions & 0 deletions crates/common/src/solidity_selector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! Solidity ABI selector words used when emitting reverts.
//!
//! Each constant is the 32-byte EVM memory word that stores the corresponding
//! Solidity selector at memory offset 0. The 4-byte selector occupies the
//! high-order bytes (memory addresses 0..4) and the remaining 28 bytes are
//! zero. The hex strings are consumed verbatim by 256-bit integer constructors
//! such as `Context::word_const_str_hex`, so the selector ends up in the most
//! significant bits of the resulting `i256`.

/// 32-byte EVM word holding the Solidity `Panic(uint256)` ABI selector.
///
/// `keccak256("Panic(uint256)")[..4] == 0x4e487b71`, placed in the high-order
/// bytes of a 32-byte word followed by 28 zero bytes.
pub const PANIC_UINT256_SELECTOR_WORD_HEX: &str =
"4e487b7100000000000000000000000000000000000000000000000000000000";

/// 32-byte EVM word holding the Solidity `Error(string)` ABI selector.
///
/// `keccak256("Error(string)")[..4] == 0x08c379a0`, placed in the high-order
/// bytes of a 32-byte word followed by 28 zero bytes.
pub const ERROR_STRING_SELECTOR_WORD_HEX: &str =
"08c379a000000000000000000000000000000000000000000000000000000000";
16 changes: 8 additions & 8 deletions crates/integration/codesize.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"Baseline": 870,
"Computation": 2418,
"DivisionArithmetics": 9327,
"ERC20": 17160,
"Events": 1662,
"FibonacciIterative": 1427,
"Flipper": 2240,
"SHA1": 8009
"Baseline": 493,
"Computation": 1376,
"DivisionArithmetics": 7147,
"ERC20": 8933,
"Events": 909,
"FibonacciIterative": 969,
"Flipper": 1099,
"SHA1": 5198
}
10 changes: 10 additions & 0 deletions crates/integration/codesize_newyork.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Baseline": 479,
"Computation": 1376,
"DivisionArithmetics": 7192,
"ERC20": 10138,
"Events": 1279,
"FibonacciIterative": 949,
"Flipper": 1123,
"SHA1": 6286
}
35 changes: 35 additions & 0 deletions crates/integration/contracts/CallerOriginAliasing.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8;

// Differential guard against a latent soundness footgun in the codegen for
// __revive_caller: before the fix the helper wrote its result through the
// shared @__address_spill_buffer LLVM global while declaring
// memory(inaccessiblemem: read). The same global is also written by the
// inlined tx.origin and address(this) patterns, so the function attribute
// was a contract violation from LLVM's point of view (globals are Other
// memory, not inaccessiblemem). Any optimizer pass that exploited the wrong
// attribute to CSE / hoist a load of the spill buffer across a
// __revive_caller() call would have miscompiled the surrounding tx.origin /
// address(this) read.
//
// The fix moves __revive_caller's output to a function-local alloca so the
// attribute matches the body. This contract exercises every shape that
// previously shared the spill buffer.
contract CallerOriginAliasing {
function caller_then_origin() external view returns (address, address) {
return (msg.sender, tx.origin);
}

function origin_then_caller() external view returns (address, address) {
return (tx.origin, msg.sender);
}

function caller_address_origin() external view returns (address, address, address) {
return (msg.sender, address(this), tx.origin);
}

function repeated_caller() external view returns (address, address, address) {
return (msg.sender, msg.sender, msg.sender);
}
}
42 changes: 42 additions & 0 deletions crates/integration/contracts/Factorial.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8;

// Regression test: factorial with uint8 parameter and uint64 result.
// Bug: newyork pipeline doesn't revert for out-of-range uint8 parameter,
// causing the function to return 1 (factorial of truncated 0) instead of
// reverting.

/* runner.json
{
"differential": true,
"actions": [
{
"Instantiate": {
"code": { "Solidity": { "contract": "Factorial", "solc_optimizer": false } }
}
},
{
"Call": {
"dest": { "Instantiated": 0 },
"data": "ebbee3910000000000000000000000000000000000000000000000000000000000000005"
}
},
{
"Call": {
"dest": { "Instantiated": 0 },
"data": "ebbee3910000000000000000000000000000000000000000000000000000000100000000"
}
}
]
}
*/

contract Factorial {
function main(uint8 n) public pure returns (uint64) {
uint64 fact = 1;
for (uint8 i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}
}
57 changes: 57 additions & 0 deletions crates/integration/contracts/InternalFn.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8;

// Regression test: contracts whose Yul IR generates internal helper functions
// (e.g. abi_encode_string, extract_byte_array_length) that survive the newyork
// inliner require a function scope in the LLVM context during code generation.
// Without it, declaring frontend functions in generate_object triggers an ICE:
// "function scope must be pushed before declaring frontend functions".

/* runner.json
{
"differential": false,
"actions": [
{
"Instantiate": {}
},
{
"Call": {
"dest": { "Instantiated": 0 },
"data": "e942b51600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000568656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005776f726c64000000000000000000000000000000000000000000000000000000"
}
},
{
"VerifyCall": {
"success": true
}
},
{
"Call": {
"dest": { "Instantiated": 0 },
"data": "6d4ce63c"
}
},
{
"VerifyCall": {
"success": true,
"output": "00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000568656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005776f726c64000000000000000000000000000000000000000000000000000000"
}
}
]
}
*/

contract InternalFn {
string public a;
string public b;

function set(string calldata _a, string calldata _b) external {
a = _a;
b = _b;
}

function get() external view returns (string memory, string memory) {
return (a, b);
}
}
12 changes: 11 additions & 1 deletion crates/integration/contracts/MSize.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8;

/* runner.json
{
"differential": true,
"differential": false,
"actions": [
{
"Instantiate": {
Expand All @@ -24,13 +24,23 @@ pragma solidity ^0.8;
"data": "f016832c"
}
},
{
"VerifyCall": {
"success": true
}
},
{
"Call": {
"dest": {
"Instantiated": 0
},
"data": "f4a63aa5"
}
},
{
"VerifyCall": {
"success": true
}
}
]
}
Expand Down
22 changes: 22 additions & 0 deletions crates/integration/contracts/SDivNarrowBug.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8;

contract SDivNarrowBug {
/// Forces LLVM IR of the form
/// sdiv i256 (and i256 %a, 0xff..ff_u64), (and i256 %b, 0xff..ff_u64)
///
/// `provable_bit_width` accepts the AND-mask proof and lets revive's
/// `narrow_divrem_instructions` rewrite this to `sdiv i64 (trunc..), (trunc..)`
/// followed by `sext` back to i256. The truncated low-64 view of an i256
/// whose bit 63 is set looks negative under i64, but the i256 value is
/// non-negative (high 192 bits are zero by the AND), so the narrowed
/// signed division returns the wrong sign.
function sdiv_masked(uint256 a, uint256 b) external pure returns (int256 q) {
assembly {
let am := and(a, 0xffffffffffffffff)
let bm := and(b, 0xffffffffffffffff)
q := sdiv(am, bm)
}
}
}
Loading