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

Reduce gas/storage limits in nested calls #6890

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fadb396
Fix typo in integration test
rockbmb Dec 12, 2024
db02307
Add unit tests to current behavior of `GasMeter.nested`
rockbmb Dec 12, 2024
2c2a7f7
Add unit tests to simplest behavior of `RawMeter`
rockbmb Dec 13, 2024
11dd382
Add PRDoc
rockbmb Dec 13, 2024
5a8312a
Limit gas for nested calls per EIP-150
rockbmb Dec 13, 2024
a7781c4
Reflect EIP-150 change in some unit tests
rockbmb Dec 13, 2024
b6e7290
Address missing EIP-150 fix in one gas meter unit test
rockbmb Dec 13, 2024
8d7be23
Apply EIP-150 to storage metering
rockbmb Dec 13, 2024
ee2a183
Fix storage meter unit test for `fn nested`
rockbmb Dec 14, 2024
b89495f
Remove usage of 0 as unlimited storage meter in test
rockbmb Dec 17, 2024
8e66f50
Fix tests in `exec::tests`
rockbmb Dec 17, 2024
8938008
Rework 0 as unlimited metering in test contracts
rockbmb Dec 17, 2024
f5e6b2b
Rollback changes in `frame/contracts`
rockbmb Dec 19, 2024
33758aa
Add EIP-150 note to doc comment
rockbmb Dec 19, 2024
d1b40ed
Run `fmt`
rockbmb Dec 19, 2024
36690cd
Address latest PR comments (`enum Nested`)
rockbmb Dec 20, 2024
2c8f492
Refactor `RawMeter/Nested`
rockbmb Dec 20, 2024
12473b4
Run `fmt`
rockbmb Dec 20, 2024
d21a941
Merge branch 'master' into evm-contracts-limit-nested-calls-gas
rockbmb Jan 2, 2025
2f8ab21
Address latest review
rockbmb Jan 3, 2025
acfcf66
Fix tests `delegate_call` and `deposit_limit_in_nested_calls`
rockbmb Jan 3, 2025
e0c0845
Fix `tests::deposit_limit_in_nested_instantiate`
rockbmb Jan 3, 2025
b090e5f
Address review comments
rockbmb Jan 6, 2025
0be4019
Change default deposit limit in WASM runtime checks
rockbmb Jan 6, 2025
c3b9510
Update from rockbmb running command 'fmt'
Jan 6, 2025
7531f72
Update deposit limit in benchmark
rockbmb Jan 6, 2025
11c8858
Modify how deposit limits are stored in `revive/uapi`
rockbmb Jan 7, 2025
222e6df
Rename `const` with confusing name
rockbmb Jan 8, 2025
93ac5ba
Update usage of `Weight::zero()` in test
rockbmb Jan 8, 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
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ fn relay_commands_add_remove_username_authority() {
);
});

// Now, remove the username authority with another priviledged XCM call.
// Now, remove the username authority with another privileged XCM call.
Westend::execute_with(|| {
type Runtime = <Westend as Chain>::Runtime;
type RuntimeCall = <Westend as Chain>::RuntimeCall;
Expand Down
13 changes: 13 additions & 0 deletions prdoc/pr_6890.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Bound resources for nested EVM contract calls

doc:
- audience: [ Runtime Dev, Runtime User ]
description: |
Implementation of EIP-150 for `pallet-revive`-based EVM contracts.

crates:
- name: pallet-revive
bump: minor
10 changes: 5 additions & 5 deletions substrate/frame/revive/fixtures/contracts/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#![no_main]

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{HostFn, HostFnImpl as api, U256_MAX};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -38,10 +38,10 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::empty(),
callee_addr,
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
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.
&U256_MAX, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
callee_input,
None,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

extern crate common;

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

const BUF_SIZE: usize = 8;
static DATA: [u8; BUF_SIZE] = [1, 2, 3, 4, 5, 6, 7, 8];
Expand All @@ -42,9 +42,9 @@ fn assert_call<const N: usize>(callee_address: &[u8; 20], expected_output: [u8;
api::call(
uapi::CallFlags::ALLOW_REENTRY,
callee_address,
0u64,
0u64,
None,
u64::MAX,
u64::MAX,
&U256_MAX,
&[0u8; 32],
&[],
Some(output_buf_capped),
Expand All @@ -67,9 +67,9 @@ fn assert_instantiate<const N: usize>(expected_output: [u8; BUF_SIZE]) {

api::instantiate(
&code_hash,
0u64,
0u64,
None,
u64::MAX,
u64::MAX,
&U256_MAX,
&[0; 32],
&[0; 32],
None,
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/revive/fixtures/contracts/call_return_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#![no_main]

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{HostFn, HostFnImpl as api, U256_MAX};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -42,10 +42,10 @@ pub extern "C" fn call() {
let err_code = match api::call(
uapi::CallFlags::empty(),
callee_addr,
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
value, // Value transferred to the contract.
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.
&U256_MAX, // No deposit limit.
value, // Value transferred to the contract.
input,
None,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![no_main]

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{HostFn, HostFnImpl as api, U256_MAX};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -42,10 +42,10 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::empty(),
callee_addr,
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
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.
&U256_MAX, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
callee_input,
None,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#![no_main]

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

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -40,9 +40,9 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::from_bits(flags).unwrap(),
callee_addr,
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
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.
&U256_MAX, // No deposit limit.
&u256_bytes(value), // Value transferred to the contract.
forwarded_input,
None,
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/revive/fixtures/contracts/call_with_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#![no_main]

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{HostFn, HostFnImpl as api, U256_MAX};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -43,8 +43,8 @@ pub extern "C" fn call() {
callee_addr,
ref_time,
proof_size,
None, // No deposit limit.
&[0u8; 32], // value transferred to the contract.
&U256_MAX, // No deposit limit.
&[0u8; 32], // value transferred to the contract.
forwarded_input,
None,
)
Expand Down
50 changes: 25 additions & 25 deletions substrate/frame/revive/fixtures/contracts/caller_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![no_main]

use common::{input, u256_bytes};
use uapi::{HostFn, HostFnImpl as api, ReturnErrorCode};
use uapi::{HostFn, HostFnImpl as api, ReturnErrorCode, U256_MAX};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -42,9 +42,9 @@ pub extern "C" fn call() {
// Fail to deploy the contract since it returns a non-zero exit status.
let res = api::instantiate(
code_hash,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
None, // No deposit limit.
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
&U256_MAX, // No deposit limit.
&value,
&reverted_input,
None,
Expand All @@ -56,9 +56,9 @@ pub extern "C" fn call() {
// Fail to deploy the contract due to insufficient ref_time weight.
let res = api::instantiate(
code_hash,
1u64, // too little ref_time weight
0u64, // How much proof_size weight to devote for the execution. 0 = all.
None, // No deposit limit.
1u64, // too little ref_time weight
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
&U256_MAX, // No deposit limit.
&value,
&input,
None,
Expand All @@ -70,9 +70,9 @@ pub extern "C" fn call() {
// Fail to deploy the contract due to insufficient proof_size weight.
let res = api::instantiate(
code_hash,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
1u64, // Too little proof_size weight
None, // No deposit limit.
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
1u64, // Too little proof_size weight
&U256_MAX, // No deposit limit.
&value,
&input,
None,
Expand All @@ -86,9 +86,9 @@ pub extern "C" fn call() {

api::instantiate(
code_hash,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
None, // No deposit limit.
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
&U256_MAX, // No deposit limit.
&value,
&input,
Some(&mut callee),
Expand All @@ -101,9 +101,9 @@ pub extern "C" fn call() {
let res = api::call(
uapi::CallFlags::empty(),
&callee,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
None, // No deposit limit.
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
&U256_MAX, // No deposit limit.
&value,
&reverted_input,
None,
Expand All @@ -114,9 +114,9 @@ pub extern "C" fn call() {
let res = api::call(
uapi::CallFlags::empty(),
&callee,
1u64, // Too little ref_time weight.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
None, // No deposit limit.
1u64, // Too little ref_time weight.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
&U256_MAX, // No deposit limit.
&value,
&input,
None,
Expand All @@ -127,9 +127,9 @@ pub extern "C" fn call() {
let res = api::call(
uapi::CallFlags::empty(),
&callee,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
1u64, // too little proof_size weight
None, // No deposit limit.
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
1u64, // too little proof_size weight
&U256_MAX, // No deposit limit.
&value,
&input,
None,
Expand All @@ -141,9 +141,9 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::empty(),
&callee,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
None, // No deposit limit.
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
&U256_MAX, // No deposit limit.
&value,
&input,
Some(&mut &mut output[..]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#![no_main]

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{HostFn, HostFnImpl as api, U256_MAX};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down Expand Up @@ -54,10 +54,10 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::ALLOW_REENTRY,
&addr,
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
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.
&U256_MAX, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
input,
None,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![no_main]

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{HostFn, HostFnImpl as api, U256_MAX};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -34,6 +34,6 @@ pub extern "C" fn call() {
api::value_transferred(&mut value);

// Deploy the contract with no salt (equivalent to create1).
let ret = api::instantiate(code_hash, 0u64, 0u64, None, &value, &[], None, None, None);
let ret = api::instantiate(code_hash, u64::MAX, u64::MAX, &U256_MAX, &value, &[], None, None, None);
assert!(ret.is_ok());
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ pub extern "C" fn call() {
let ret = api::call(
uapi::CallFlags::empty(),
callee,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
Some(deposit_limit),
&[0u8; 32], // Value transferred to the contract.
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all resources.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all resources.
deposit_limit,
&[0u8; 32], // Value transferred to the contract.
input,
None,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pub extern "C" fn call() {

let ret = api::instantiate(
code_hash,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
Some(deposit_limit),
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
deposit_limit,
&value,
input,
Some(&mut address),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#![no_main]

use common::input;
use uapi::{HostFn, HostFnImpl as api, StorageFlags};
use uapi::{HostFn, HostFnImpl as api, StorageFlags, U256_MAX};

static BUFFER: [u8; 448] = [0u8; 448];

Expand Down Expand Up @@ -49,10 +49,10 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::empty(),
callee,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
None,
&[0u8; 32], // Value transferred to the contract.
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = all.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = all.
&U256_MAX, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
input,
None,
)
Expand Down
Loading
Loading