Commit Graph

58 Commits

Author SHA1 Message Date
xermicus 878ca91689 RISCV relaxations (#408)
This PR enables RISC-V relaxations and changes to internal linkage for internal function and global symbols.

See also:
https://github.com/llvm/llvm-project/issues/167381#issuecomment-3513830043

Signed-off-by: xermicus <cyrill@parity.io>
2025-11-11 17:27:53 +01:00
xermicus c0cdde5a5a llvm-context: fix off-by-one in SDIV overflow semantics (#398)
- Fix the wrong predicate (the negative side in 2s complement has one
more bit)
- Increase test coverage

Signed-off-by: xermicus <cyrill@parity.io>
2025-10-31 14:07:01 +01:00
xermicus 84018c18ae switch to the new storage API (#396)
This PR switches to the new `get_storage_or_zero` and
`set_storage_or_clear` syscalls which are more tailored towards
Solidity.

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-10-30 14:13:37 +01:00
xermicus 42cac55be8 update cargo dependencies (#395)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-10-29 10:01:05 +01:00
xermicus f46bea6a96 llvm-context: do not trap zero length OOB heap access (#389)
Fixes https://github.com/paritytech/contract-issues/issues/120

---------

Signed-off-by: xermicus <cyrill@parity.io>
2025-10-15 22:39:42 +02:00
xermicus 8240163be0 release resolc 0.4.0 (#384)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-10-06 09:12:34 +02:00
xermicus b560d72139 Prevent frontend function confusion (#383)
Function symbols can clash as we compile multiple YUL `object`
definition into the same `LLVM` module.
- Disambiguate via unique function symbols based its location (runtime
or deploy code).
- Use `LinkOnceODR` linkage for compiler builtin helpers.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-09-29 23:05:57 +02:00
xermicus 6858cb9a61 mark internal functions linker private (#381)
Prevents unused functions in the emitted ELF object. Drive-by add a
missing test case (which misses a relocation under `-Oz` when all
internal functions are marked as private).

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-09-29 17:55:29 +02:00
xermicus c285a6ec3d add columns to debug information (#362)
- Add column numbers to debug information.
- Do not build allocas at entry for now.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-07-17 09:53:54 +02:00
xermicus 20e77cb0b5 configurable stack and heap memory size (#288)
- Allow configuration of the maximum heap and stack size via CLI flags
and JSON input settings.
- Increase the default value for the stack size to 32kb.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-04-24 10:47:38 +02:00
xermicus 357bf58868 allow dynamic configuration of the heap memory (#287)
This PR changes the implementation of the emulated EVM heap memory:
Instead of linking in a C implementation the code is emitted directly
into the contract module. Which allows making it configurable via a
compiler parameter (a follow up PR to this).

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-04-23 20:25:55 +02:00
xermicus 5003f3e9ac llvm-context: alloca at the function entry if possible (#283)
Closes  #48

Change the code size test to no longer emit debug info as to get a more
accurate picture.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-04-15 15:22:24 +02:00
xermicus 431b5a2ce5 llvm-context: lazy handling of function arguments and immutable data (#282)
- Lazily load function arguments so that they can be passed as pointers.
- Lazily call the immutable store function to avoid storing zero sized
immutable data.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-04-14 15:54:59 +02:00
xermicus 7d8fa75a0f storage keys and values should be big endian (#277)
Storage keys and values are big endian. Keeping them LE was a pre-mature
optimization because for the contract itself it this is a no-op and thus
not observable. However we should consider the storage layout as part of
the contract ABI. The endianness of transient storage values are still
kept as-is.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-04-07 10:34:44 +02:00
xermicus 4a9b651235 Support solc v0.8.29 (#261)
No observable changes w.r.t. YUL compilation.
- Mark solc v0.8.29 as the latest supported version
- Add integration test for solc v0.8.29 specific feature
- Use the latest version on CI
- Drive-by fix linter complaints and a two types in the CI yaml files

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
2025-03-18 13:01:15 +01:00
xermicus a07968205b llvm-context: modularize compiler builtin functions (#234)
- Add the revive runtime function interface to minimize boiler plate
code.
- Outline heavily repeated code into dedicated functions to bring down
code size.
- The code size tests builds optimized for size.
- Function attributes are passed as slices.

This significantly brings down the code size for all OpenZeppelin wizard
contracts (using all possible features) compiled against OpenZeppelin
`v5.0.0` with size optimizations.

|contract|| `-Oz` main | `-Oz` PR || `-O3` main | `-O3` PR |
|-|-|-|-|-|-|-|
|erc1155.sol||100K|67K||114K|147K|
|erc20.sol||120K|90K||160K|191K|
|erc721.sol||128K|101K||178K|214K|
|governor.sol||226K|165K||293K|349K|
|rwa.sol||116K|85K||154K|185K|
|stable.sol||116K|86K||155K|192K|

On the flip side this introduces a heavy penalty for cycle optimized
builds. Setting the no-inline attributes for cycle optimized builds
helps a lot but heavily penalizes runtime speed (LLVM does not yet
inline everything properly - to be investigated later on).

Next steps:
- Modularize more functions
- Refactor the YUL function arguments to use pointers instead of values
- Afterwards check if LLVM still has trouble inline-ing properly on O3
or set the no-inline attribute if it does not penalize runtime
performance too bad.
2025-02-25 16:47:01 +01:00
Pavlo Khrystenko 89ec25da65 Add per file output selection for --standard-json mode and some other small foundry support bits. (#228) 2025-02-24 12:44:22 +01:00
Cyrill Leutwiler 3f9771f838 update and fix the linker (#140) 2024-12-18 23:11:06 +01:00
Cyrill Leutwiler d299dd1a19 change getters to register version (#138) 2024-12-18 17:56:37 +01:00
Cyrill Leutwiler 14a598e840 implement the gas opcode (#136) 2024-12-18 17:19:32 +01:00
Cyrill Leutwiler 909de515c4 Allow arbitrary call data size (#135)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2024-12-18 14:04:46 +01:00
Cyrill Leutwiler 423a494621 Switch target to 64bit and enable the zbb feature (#120) 2024-11-29 15:56:10 +01:00
Cyrill Leutwiler 6a120463c2 implement the blockhash opcode (#114) 2024-11-15 13:11:04 +01:00
Cyrill Leutwiler a4043ecde7 update LLVM target features (#102)
Signed-off-by: xermicus <cyrill@parity.io>
2024-10-29 18:17:29 +01:00
Ermal Kaleci aae25107a2 support full storage key space (#100)
- The storage pointer values will no longer be truncated to the register size, allowing for the use of arbitrary storage keys
- Failed storage value reads will now guarantee to return the zero value
2024-10-28 10:18:11 +01:00
Cyrill Leutwiler 995b115c5f bump polkadot-sdk and polkavm (#94)
Signed-off-by: xermicus <cyrill@parity.io>
2024-10-22 19:50:58 +02:00
Cyrill Leutwiler 82ae22c163 tidy up the runtime API crate (#85)
- remove unused runtime API imports and constants
- move runtime api symbols into the revive-runtime-api crate

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2024-10-17 10:55:27 +02:00
Cyrill Leutwiler f0f344a139 disable sbrk and emulate EVM linear memory internally (#76)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
2024-10-14 15:20:00 +02:00
Cyrill Leutwiler d5d419cefc implement immutable variables codegen (#70) 2024-10-10 13:33:00 +02:00
xermicus b344e0cff5 Revert "implement immutable variables codegen"
This reverts commit 0e6a6d12c3.
2024-10-09 03:43:05 +02:00
xermicus 0e6a6d12c3 implement immutable variables codegen
Signed-off-by: xermicus <cyrill@parity.io>
2024-10-09 03:37:56 +02:00
Cyrill Leutwiler 6585973e99 Updated call semantics (#56)
- Update pallet-revive dependency
- Implement calls according to pallet-revive call semantics
- Switch to the new return data API in pallet revive and get rid of return data buffer
- Remove a bunch of resulting dead code
2024-09-28 20:03:03 +02:00
Cyrill Leutwiler d2f76b645f switch to pallet_revive runtime (#40)
Signed-off-by: xermicus <cyrill@parity.io>
2024-09-03 17:18:22 +02:00
xermicus 6834751522 support riscv64 target
Signed-off-by: xermicus <cyrill@parity.io>
2024-07-09 17:57:58 +02:00
xermicus 39d78179d4 implement transient storage
Signed-off-by: xermicus <cyrill@parity.io>
2024-06-05 17:34:17 +02:00
Cyrill Leutwiler 9e9227d740 Remove vyper and dead code (#23) 2024-06-05 13:29:07 +02:00
Cyrill Leutwiler caa1228720 Run all tests on CI (#21)
Run all tests on CI

Signed-off-by: xermicus <cyrill@parity.io>
2024-06-05 00:50:03 +02:00
xermicus 354b1c8d79 do not byte swap storage values
Signed-off-by: xermicus <cyrill@parity.io>
2024-06-03 17:16:49 +02:00
Cyrill Leutwiler 532721f3be Implement MCOPY (#18)
Signed-off-by: xermicus <cyrill@parity.io>
2024-05-29 21:43:22 +02:00
Cyrill Leutwiler 06aa289d9b Constructors and contract creation (#11)
Implement constructor logic and support create/create2 in the mock runtime

Signed-off-by: xermicus <cyrill@parity.io>
2024-05-22 21:35:32 +02:00
Cyrill Leutwiler d8be21f156 update PolkaVM
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2024-05-15 10:12:52 +02:00
xermicus 83bf9d6041 events
Signed-off-by: xermicus <cyrill@parity.io>
2024-05-14 09:46:18 +02:00
xermicus 02055c73bb extend mock runtime to allow executing constructors and cross contract calls
Signed-off-by: xermicus <cyrill@parity.io>
2024-05-13 13:50:35 +02:00
xermicus 0e90317488 add contract name to integration to integration test cases
Signed-off-by: xermicus <cyrill@parity.io>
2024-05-10 13:47:47 +02:00
xermicus 03a1918993 parallelize tests
Signed-off-by: xermicus <cyrill@parity.io>
2024-05-10 10:54:01 +02:00
Cyrill Leutwiler ea63991617 implement address and msg.sender
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2024-05-08 16:09:23 +02:00
xermicus b55669f5c5 remove the zkasm format
Signed-off-by: xermicus <cyrill@parity.io>
2024-05-08 10:48:01 +02:00
xermicus 95ff85c6d1 implement block.number and block.timestamp
Signed-off-by: xermicus <cyrill@parity.io>
2024-05-07 18:03:17 +02:00
xermicus c0dd845b39 s/field/word
Signed-off-by: xermicus <cyrill@parity.io>
2024-05-07 13:37:17 +02:00
xermicus 518c03d045 internalize runtime API function symbols
Signed-off-by: xermicus <cyrill@parity.io>
2024-05-06 13:45:58 +02:00