Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
8012f45
Reflect `block_hash` already being stable in `uapi`
cmichi Aug 9, 2025
db9f6c5
Remove `call_chain_extension` from `uapi`
cmichi Aug 9, 2025
1b69351
Implement getters
cmichi Aug 10, 2025
cc83058
Remove `address` arg
cmichi Aug 18, 2025
085a84e
Migrate calls to delegate_calls
cmichi Aug 18, 2025
8568190
Rename pre-compile weights
cmichi Aug 19, 2025
077bede
Migrate benchmarks
cmichi Aug 19, 2025
54cd40b
Remove unused functionality
cmichi Aug 19, 2025
7e2b99d
Clean up code
cmichi Aug 19, 2025
ec00d2a
Fix `unused_parens`
cmichi Aug 19, 2025
dd607ef
Migrate benchmark for `weight_left`
cmichi Aug 19, 2025
66799e3
Add prdoc file
cmichi Aug 19, 2025
64f680f
Code cleanups
cmichi Aug 19, 2025
c4c34be
Apply `taplo` suggestions
cmichi Aug 19, 2025
ccdaa48
Update function signatures
cmichi Aug 19, 2025
860b65e
Make CI happy
cmichi Aug 19, 2025
19ca21e
Import `vec`
cmichi Aug 19, 2025
61fd201
Adapt semver changes based on CI check
cmichi Aug 19, 2025
7bfd2fc
Update semver
cmichi Aug 19, 2025
dbf6845
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Aug 22, 2025
202b1df
Revert lockfile changes
cmichi Aug 22, 2025
0b41ce0
Revert merge changes
cmichi Aug 22, 2025
72979fd
Fix merge issues
cmichi Aug 22, 2025
eb35a38
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Aug 22, 2025
121eb93
Apply git diff
cmichi Aug 25, 2025
284456c
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Aug 25, 2025
f9e1034
Simplify variable naming
cmichi Aug 26, 2025
0f6e7ed
Fix test
cmichi Aug 26, 2025
4dc44be
Allow pre-compiles access to `convert_native_to_evm`
cmichi Aug 26, 2025
80c58a3
Encode as Solidity types
cmichi Aug 26, 2025
bde818c
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Sep 1, 2025
d4e0b5c
Follow-up to `master` merge
cmichi Sep 1, 2025
8576e7f
Remove dead code
cmichi Sep 1, 2025
bc1b6f6
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Sep 2, 2025
64e145b
Resolve merge test failures
cmichi Sep 2, 2025
0816676
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Sep 2, 2025
8e46866
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Sep 5, 2025
f7ff425
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Sep 9, 2025
6b1263f
Rollback ext removals
cmichi Sep 9, 2025
24f6f08
Rollback removal of `to_account_id`
cmichi Sep 10, 2025
3faa774
Add tests
cmichi Sep 9, 2025
e6a04ed
Use `to_account_id` from `Ext` in pre-compile
cmichi Sep 10, 2025
a71467c
Revert "Add tests"
cmichi Sep 10, 2025
ebf0365
Move `ISystem` to `pallet-revive-uapi`
cmichi Sep 10, 2025
a1a01e0
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Sep 10, 2025
b7d75dc
Rename feature `precompiles` to `precompiles-sol-interfaces`
cmichi Sep 10, 2025
b865371
Improve comment
cmichi Sep 10, 2025
10420b8
Revert introduction of `convert_native_to_evm`
cmichi Sep 10, 2025
6ba7f58
Use `call` over `delegate_call`
cmichi Sep 10, 2025
bf48062
Rename `precompile-sol-interfaces` to `precompiles-sol-interfaces`
cmichi Sep 10, 2025
6fc1398
Use `READ_ONLY` for calling getters on pre-compile
cmichi Sep 10, 2025
ab717db
Fix `call_diverging_out_len`
cmichi Sep 10, 2025
118aea7
Update substrate/frame/revive/src/benchmarking.rs
cmichi Sep 12, 2025
fc94aff
Remove unused dep
cmichi Sep 12, 2025
5e6fc4e
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Sep 12, 2025
41ebb98
Use `delegate_call` for `own_code_hash` + `caller_is_root`
cmichi Sep 12, 2025
ddf9d08
Use `delegate_call` for `caller_is_origin`
cmichi Sep 12, 2025
76361a8
Simplify `System` precompile
cmichi Sep 12, 2025
45f106c
Use Solidity ABI encoding for `own_code_hash` return value
cmichi Sep 12, 2025
869f690
Allow dead code for `ExtInfo::own_code_hash`
cmichi Sep 12, 2025
55a30fe
Remove unused imports
cmichi Sep 12, 2025
5923c69
Drive-by fix: ink! URL
cmichi Sep 12, 2025
2ac798a
Apply `taplo` toml format
cmichi Sep 12, 2025
6d92b70
Revert unrelated `taplo` change
cmichi Sep 12, 2025
cbfd780
Make `own_code_hash` callable via `call`
cmichi Sep 15, 2025
5d39e84
Reflect calling convention in comments
cmichi Sep 15, 2025
78131c8
Use caller of caller for `System::caller_is_origin` + `System::caller…
cmichi Sep 15, 2025
1793c1d
Use `clone()` over `to_owned()`
cmichi Sep 15, 2025
1862e0d
Name unused variable
cmichi Sep 15, 2025
6922bc7
Make CI happy
cmichi Sep 16, 2025
a89bf30
Make CI happy
cmichi Sep 16, 2025
ab766e4
Merge remote-tracking branch 'origin/master' into cmichi-migrate-revi…
cmichi Sep 16, 2025
7778632
Apply CI recommended changes to toml files
cmichi Sep 16, 2025
23124e4
Apply CI recommended changes to toml files
cmichi Sep 16, 2025
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
25 changes: 25 additions & 0 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions prdoc/pr_9517.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: '[pallet-revive] Migrate various getters to `System` pre-compile'
doc:
- audience: Runtime Dev
description: Migrates `own_code_hash`, `caller_is_origin`, `caller_is_root`,
`weight_left`, `minimum_balance`. Contains minor other fixes (removing leftovers
from deprecating chain extensions, stabilizing `block_hash` in overlooked crates, …).
crates:
- name: pallet-revive
bump: patch
- name: pallet-revive-fixtures
bump: major
- name: pallet-revive-uapi
bump: major
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The CI check for correct semver is going a bit haywire here. This is what it came up with:

- name: pallet-revive
  bump: major
- name: pallet-revive-fixtures
  bump: patch
- name: pallet-revive-uapi
  bump: minor

I believe more correct is:

2 changes: 1 addition & 1 deletion substrate/frame/contracts/src/chain_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
//! # Example
//!
//! The ink-examples repository maintains an
//! [end-to-end example](https://github.com/paritytech/ink-examples/tree/main/rand-extension)
//! [end-to-end example](https://github.com/use-ink/ink-examples/tree/v5.x.x/rand-extension)
//! on how to use a chain extension in order to provide new features to ink! contracts.

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-revive-fixtures = { workspace = true, optional = true }
pallet-revive-proc-macro = { workspace = true }
pallet-revive-uapi = { workspace = true, features = ["scale"] }
pallet-revive-uapi = { workspace = true, features = ["precompiles-sol-interfaces", "scale"] }
pallet-transaction-payment = { workspace = true }
ripemd = { workspace = true }
sp-api = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! This fixture calls the `callerIsOrigin` function on the
//! `System` pre-compile.

#![no_std]
#![no_main]
include!("../panic_handler.rs");

use uapi::{HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn deploy() {}

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {
let mut output = [0u8; 32];
let _ = api::call(
uapi::CallFlags::READ_ONLY,
&uapi::SYSTEM_PRECOMPILE_ADDR,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
&uapi::solidity_selector("callerIsOrigin()"),
Some(&mut &mut output[..]),
).unwrap();

api::return_value(uapi::ReturnFlags::empty(), &output);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! This fixture calls the `callerIsRoot` function on the
//! `System` pre-compile.

#![no_std]
#![no_main]
include!("../panic_handler.rs");

use uapi::{HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn deploy() {}

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {
let mut output = [0u8; 32];
let _ = api::call(
uapi::CallFlags::READ_ONLY,
&uapi::SYSTEM_PRECOMPILE_ADDR,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
&uapi::solidity_selector("callerIsRoot()"),
Some(&mut &mut output[..]),
).unwrap();

api::return_value(uapi::ReturnFlags::empty(), &output);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#![no_main]
include!("../panic_handler.rs");

use uapi::{HostFn, HostFnImpl as api};
use uapi::{HostFn, HostFnImpl as api, u256_bytes};

const BUF_SIZE: usize = 8;
static DATA: [u8; BUF_SIZE] = [1, 2, 3, 4, 5, 6, 7, 8];
Expand Down Expand Up @@ -58,8 +58,19 @@ fn assert_call<const N: usize>(callee_address: &[u8; 20], expected_output: [u8;
/// Instantiate this contract with an output buf of size `N`
/// and expect the instantiate output to match `expected_output`.
fn assert_instantiate<const N: usize>(expected_output: [u8; BUF_SIZE]) {
let mut code_hash = [0; 32];
api::own_code_hash(&mut code_hash);
let mut output_buf1 = [0u8; 32];
let output1 = &mut &mut output_buf1[..];
let _ = api::call(
uapi::CallFlags::READ_ONLY,
&uapi::SYSTEM_PRECOMPILE_ADDR,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
&uapi::solidity_selector("ownCodeHash()"),
Some(output1),
).unwrap();
assert_ne!(output_buf1, [0u8; 32]);

let mut output_buf = [0u8; BUF_SIZE];
let output_buf_capped = &mut &mut output_buf[..N];
Expand All @@ -68,8 +79,8 @@ fn assert_instantiate<const N: usize>(expected_output: [u8; BUF_SIZE]) {
u64::MAX,
u64::MAX,
&[u8::MAX; 32],
&[0; 32],
&code_hash,
&u256_bytes(0),
output_buf1.clone().as_slice(),
None,
Some(output_buf_capped),
None,
Expand Down
51 changes: 51 additions & 0 deletions substrate/frame/revive/fixtures/contracts/call_own_code_hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! This fixture calls the `ownCodeHash` function on the
//! `System` pre-compile.

#![allow(unused_imports)]
#![no_std]
#![no_main]
include!("../panic_handler.rs");

use core::num::NonZero;
use uapi::{HostFn, HostFnImpl as api, u256_bytes};
use hex_literal::hex;

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn deploy() { }

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {
let mut output_buf = [0u8; 32];
let output = &mut &mut output_buf[..];
let _ = api::call(
uapi::CallFlags::READ_ONLY,
&uapi::SYSTEM_PRECOMPILE_ADDR,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
&uapi::solidity_selector("ownCodeHash()"),
Some(output),
).unwrap();
assert_ne!(output_buf, [0u8; 32]);
api::return_value(uapi::ReturnFlags::empty(), &output_buf);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ pub extern "C" fn call() {
input!(n: u32, );

for _ in 0..n {
let _ = api::caller_is_origin();
let _ = api::call(
uapi::CallFlags::READ_ONLY,
&uapi::SYSTEM_PRECOMPILE_ADDR,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
&uapi::solidity_selector("callerIsOrigin()"),
None,
).unwrap();
}
}

This file was deleted.

19 changes: 18 additions & 1 deletion substrate/frame/revive/fixtures/contracts/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,24 @@ pub extern "C" fn deploy() {}
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {
let balance = u64_output!(api::balance,);
let minimum_balance = u64_output!(api::minimum_balance,);

let mut output_buf = [0u8; 32];
let output = &mut &mut output_buf[..];
let _ = api::call(
uapi::CallFlags::READ_ONLY,
&uapi::SYSTEM_PRECOMPILE_ADDR,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
&uapi::solidity_selector("minimumBalance()"),
Some(output),
).unwrap();
assert_ne!(output_buf, [0u8; 32]);

let mut u64_buf = [0u8; 8];
u64_buf[..8].copy_from_slice(&output_buf[24..32]);
let minimum_balance = u64::from_be_bytes(u64_buf);

// Make the transferred value exceed the balance by adding the minimum balance.
let balance = balance + minimum_balance;
Expand Down
Loading
Loading