Skip to content

Commit

Permalink
Add feature flag to compile contracts for pallet-revive (#2319)
Browse files Browse the repository at this point in the history
* hack together RiscV support for ink! -- works!

* fix: various fixes for xcm and pallet-revive-uapi integration (#1)

* fix(revive): apply xcm fix from pallet_contracts

* build(deps): align pallet-revive-uapi dependency

* fix: update pallet-revive-uapi integration

* chore: remove workspace.xml

* fix: improve output type length handling

* fix: various fixes and improvements

* fix(caller): use to_account_id host fn

* chore: update cargo.lock

* Introduce feature flag `revive`

* Cleanup prior commits

* Update changelog

* Debugging faulty `std` import

* Make sure `panic_impl` of `sp-io` is not enabled

* Clean up changes

* Update `Cargo.lock`

* Make `[build.rustflags]` an array

* Replace `panic`'s with `todo`'s

* Revert changes to `Cargo.toml`'s

* Convert spaces to tabs

* Add `caller_is_root`

* Introduce `#[ink::polkadot_derive]` re-export

* Forward `std`

* Configure `sp-io`

* Configure `sp-io`

* Forward `std`

* Remove unused attribute

* Use correct `ErrorCode` enum

* Update test fixtures

* Fix clippy errors

---------

Co-authored-by: Peter White <petras9789@gmail.com>
Co-authored-by: Frank Bell <60948618+evilrobot-01@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent 8ac9899 commit b195f58
Show file tree
Hide file tree
Showing 37 changed files with 1,497 additions and 56 deletions.
5 changes: 4 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[env]
# We need to enable `RUSTC_BOOTSTRAP` so that the nightly ink!
# features still work on stable.
RUSTC_BOOTSTRAP = "1"
RUSTC_BOOTSTRAP = "1"

[build]
rustflags = ["--cfg", "substrate_runtime"]
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Restrict which `cfg` attributes can be used ‒ [#2313](https://github.com/use-ink/ink/pull/2313)

## Added
- Add feature flag to compile contracts for `pallet-revive`[#2318](https://github.com/use-ink/ink/pull/2318)
- Support for `caller_is_root` - [#2332] (https://github.com/use-ink/ink/pull/2332)

## Fixed
Expand Down
121 changes: 107 additions & 14 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ pallet-contracts = { version = "38.0.0", default-features = false }
pallet-balances = { version = "39.0.0", default-features = false }
pallet-timestamp = { version = "37.0.0", default-features = false }
pallet-contracts-uapi = { version = "12.0.0", default-features = false }
pallet-revive-uapi = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2412-rc2", default-features = false }
# TODO include mock-network for revive
pallet-contracts-mock-network = { version = "14.0.0", default-features = false }
sp-externalities = { version = "0.29.0", default-features = false }
sp-io = { version = "38.0.0", default-features = false }
Expand All @@ -101,6 +103,9 @@ sp-runtime = { version = "39.0.2", default-features = false }
sp-weights = { version = "31.0.0", default-features = false }
xcm = { package = "staging-xcm", version = "14.2.0", default-features = false }

# PolkaVM dependencies
polkavm-derive = { version = "0.17.1", default-features = false }

# Local dependencies
ink = { version = "=5.1.0", path = "crates/ink", default-features = false }
ink_allocator = { version = "=5.1.0", path = "crates/allocator", default-features = false }
Expand Down
16 changes: 9 additions & 7 deletions crates/allocator/src/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const PAGE_SIZE: usize = 64 * 1024;

static mut INNER: Option<InnerAlloc> = None;

#[cfg(target_arch = "riscv32")]
static mut RISCV_HEAP: [u8; 1024 * 1024] = [0; 1024 * 1024];

/// A bump allocator suitable for use in a Wasm environment.
pub struct BumpAllocator;

Expand Down Expand Up @@ -146,15 +149,14 @@ impl InnerAlloc {
Some(prev_page * PAGE_SIZE)
}
} else if #[cfg(target_arch = "riscv32")] {
const fn heap_start() -> usize {
// Placeholder value until we specified our riscv VM
0x7000_0000
fn heap_start() -> usize {
unsafe {
RISCV_HEAP.as_mut_ptr() as usize
}
}

const fn heap_end() -> usize {
// Placeholder value until we specified our riscv VM
// Let's just assume a cool megabyte of mem for now
0x7000_0400
fn heap_end() -> usize {
Self::heap_start() + unsafe { RISCV_HEAP.len() }
}

fn request_pages(&mut self, _pages: usize) -> Option<usize> {
Expand Down
4 changes: 4 additions & 0 deletions crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ sandbox = [
"pallet-contracts-mock-network",
"ink_e2e_macro/sandbox",
]
revive = [
"ink/revive",
"ink_env/revive"
]
4 changes: 3 additions & 1 deletion crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
ink_primitives = { workspace = true }
scale = { workspace = true }
pallet-contracts-uapi = { workspace = true }
pallet-revive-uapi = { workspace = true }
derive_more = { workspace = true, features = ["from", "display"] }

sha2 = { workspace = true }
Expand All @@ -32,6 +33,7 @@ default = [ "std" ]
std = [
"ink_primitives/std",
"scale/std",
"secp256k1",
"secp256k1",
"derive_more/std"
]
revive = []
4 changes: 4 additions & 0 deletions crates/engine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ use crate::{
BlockTimestamp,
},
};
#[cfg(not(feature = "revive"))]
pub use pallet_contracts_uapi::ReturnErrorCode as Error;
#[cfg(feature = "revive")]
pub use pallet_revive_uapi::ReturnErrorCode as Error;
use scale::Encode;
use std::panic::panic_any;

Expand Down Expand Up @@ -320,6 +323,7 @@ impl Engine {
set_output(output, &block_timestamp[..])
}

#[cfg(not(feature = "revive"))]
pub fn gas_left(&self, _output: &mut &mut [u8]) {
unimplemented!("off-chain environment does not yet support `gas_left`");
}
Expand Down
Loading

0 comments on commit b195f58

Please sign in to comment.