Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pallet_revive: Switch to 64bit RISC-V #6565

Merged
merged 20 commits into from
Nov 29, 2024
Merged

pallet_revive: Switch to 64bit RISC-V #6565

merged 20 commits into from
Nov 29, 2024

Conversation

athei
Copy link
Member

@athei athei commented Nov 20, 2024

This PR updates pallet_revive to the newest PolkaVM version and adapts the test fixtures and syscall interface to work under 64bit.

Please note that after this PR no 32bit contracts can be deployed (they will be rejected at deploy time). Pre-deployed 32bit contracts are now considered defunct since we changes how parameters are passed for functions with more than 6 arguments.

Fixtures

The fixtures are now built for the 64bit target. I also removed the temporary directory mechanism that triggered a full rebuild every time. It also makes it easier to find the compiled fixtures since they are now always in target/pallet-revive-fixtures.

Syscall interface

Passing pointer

Registers and pointers are now 64bit wide. This allows us to pass u64 arguments in a single register. Before we needed two registers to pass them. This means that just as before we need one register per pointer we pass. We keep pointers as u32 argument by truncating the register. This is done since the memory space of PolkaVM is 32bit.

Functions with more than 6 arguments

We only have 6 registers to pass arguments. This is why we pass a pointer to a struct when we need more than 6. Before this PR we expected a packed struct and interpreted it as SCALE encoded tuple. However, this was buggy because the MaxEncodedLen returned something that was larger than the packed size of the structure. This wasn't a problem before. But now the memory space changed in a way that things were placed at the edges of the memory space and those extra bytes lead to an out of bound access.

This is why this PR drops SCALE and expects the arguments to be passed as a pointer to a C aligned struct. This avoids unaligned accesses. However, revive needs to adapt its codegen to properly align the structure fields.

TODO

  • Add multi block migration that wipes all existing contracts as we made breaking changes to the syscall interface

@athei athei requested review from a team as code owners November 20, 2024 20:03
@athei
Copy link
Member Author

athei commented Nov 20, 2024

/cmd prdoc --audience runtime_dev

@athei athei added the T2-pallets This PR/Issue is related to a particular pallet. label Nov 20, 2024
@athei
Copy link
Member Author

athei commented Nov 20, 2024

/cmd fmt

Copy link

Command "fmt" has started 🚀 See logs here

Copy link

Command "fmt" has finished ✅ See logs here

@@ -97,7 +97,6 @@ jobs:
--exclude
"substrate/frame/contracts/fixtures/build"
"substrate/frame/contracts/fixtures/contracts/common"
"substrate/frame/revive/fixtures/build"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed because I renamed the file to _Cargo.toml.

Copy link
Member

@xermicus xermicus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The revive integration tests pass with this branch 🎉

Though this effectively narrows the pointer size to 32bit. I think we should tell people to reflect this by setting the pointer size to 32bit.

@athei
Copy link
Member Author

athei commented Nov 25, 2024

Okay great. I will finish up this PR by adding a migration to reset the contracts and disabling the failing tests ASAP then.

@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/12082221407
Failed job name: test-linux-stable-runtime-benchmarks

@athei athei enabled auto-merge November 29, 2024 12:23
@athei athei added this pull request to the merge queue Nov 29, 2024
Merged via the queue into master with commit 447902e Nov 29, 2024
194 of 198 checks passed
@athei athei deleted the at/revive_64 branch November 29, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants