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 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
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
athei marked this conversation as resolved.
Show resolved Hide resolved
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
8 changes: 4 additions & 4 deletions substrate/frame/contracts/src/benchmarking/mod.rs
Copy link
Member

Choose a reason for hiding this comment

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

Still some left over changes in the wrong pallet to roll back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out.

Original file line number Diff line number Diff line change
Expand Up @@ -1650,8 +1650,8 @@ mod benchmarks {
&mut memory,
CallFlags::CLONE_INPUT.bits(), // flags
0, // callee_ptr
0, // ref_time_limit
0, // proof_size_limit
u64::MAX, // ref_time_limit
u64::MAX, // proof_size_limit
callee_len, // deposit_ptr
callee_len + deposit_len, // value_ptr
0, // input_data_ptr
Expand Down Expand Up @@ -1744,8 +1744,8 @@ mod benchmarks {
&mut runtime,
&mut memory,
0, // code_hash_ptr
0, // ref_time_limit
0, // proof_size_limit
u64::MAX, // ref_time_limit
u64::MAX, // proof_size_limit
offset(hash_len), // deposit_ptr
offset(deposit_len), // value_ptr
offset(value_len), // input_data_ptr
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ 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.
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.
None, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
callee_input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ fn assert_call<const N: usize>(callee_address: &[u8; 20], expected_output: [u8;
api::call(
uapi::CallFlags::ALLOW_REENTRY,
callee_address,
0u64,
0u64,
u64::MAX,
u64::MAX,
None,
&[0u8; 32],
&[],
Expand All @@ -67,8 +67,8 @@ fn assert_instantiate<const N: usize>(expected_output: [u8; BUF_SIZE]) {

api::instantiate(
&code_hash,
0u64,
0u64,
u64::MAX,
u64::MAX,
None,
&[0; 32],
&[0; 32],
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/call_return_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ 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.
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.
None, // No deposit limit.
value, // Value transferred to the contract.
input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ 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.
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.
None, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
callee_input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ 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.
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.
None, // No deposit limit.
&u256_bytes(value), // Value transferred to the contract.
forwarded_input,
Expand Down
24 changes: 12 additions & 12 deletions substrate/frame/revive/fixtures/contracts/caller_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ 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.
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.
None, // No deposit limit.
&value,
&reverted_input,
Expand All @@ -57,7 +57,7 @@ pub extern "C" fn call() {
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.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
None, // No deposit limit.
&value,
&input,
Expand All @@ -70,7 +70,7 @@ 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.
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
1u64, // Too little proof_size weight
None, // No deposit limit.
&value,
Expand All @@ -86,8 +86,8 @@ 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.
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.
None, // No deposit limit.
&value,
&input,
Expand All @@ -101,8 +101,8 @@ 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.
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.
None, // No deposit limit.
&value,
&reverted_input,
Expand All @@ -115,7 +115,7 @@ pub extern "C" fn call() {
uapi::CallFlags::empty(),
&callee,
1u64, // Too little ref_time weight.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
u64::MAX, // How much proof_size weight to devote for the execution. u64::MAX = use all.
None, // No deposit limit.
&value,
&input,
Expand All @@ -127,7 +127,7 @@ 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.
u64::MAX, // How much ref_time weight to devote for the execution. u64::MAX = use all.
1u64, // too little proof_size weight
None, // No deposit limit.
&value,
Expand All @@ -141,8 +141,8 @@ 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.
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.
None, // No deposit limit.
&value,
&input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ 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.
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.
None, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, None, &value, &[], None, None, None);
assert!(ret.is_ok());
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ 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.
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.
Some(deposit_limit),
&[0u8; 32], // Value transferred to the contract.
input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ 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.
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.
Some(deposit_limit),
&value,
input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ 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.
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.
None,
&[0u8; 32], // Value transferred to the contract.
input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub extern "C" fn call() {
);

let input = [0u8; 0];
let ret = api::delegate_call(uapi::CallFlags::empty(), address, 0, 0, Some(&u256_bytes(deposit_limit)), &input, None);
let ret = api::delegate_call(uapi::CallFlags::empty(), address, u64::MAX, u64::MAX, Some(&u256_bytes(deposit_limit)), &input, None);

if let Err(code) = ret {
api::return_value(uapi::ReturnFlags::REVERT, &(code as u32).to_le_bytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ pub extern "C" fn call() {

// Delegate call into passed address.
let input = [0u8; 0];
api::delegate_call(uapi::CallFlags::empty(), address, 0, 0, None, &input, None).unwrap();
api::delegate_call(uapi::CallFlags::empty(), address, u64::MAX, u64::MAX, None, &input, None).unwrap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub extern "C" fn deploy() {

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.
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.
None, // No deposit limit.
&VALUE,
&input,
Expand All @@ -62,8 +62,8 @@ pub extern "C" fn call() {
let res = api::call(
uapi::CallFlags::empty(),
&callee_addr,
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.
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.
None, // No deposit limit.
&VALUE,
&[0u8; 1],
Expand All @@ -75,8 +75,8 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::empty(),
&callee_addr,
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.
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.
None, // No deposit limit.
&VALUE,
&[0u8; 0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ pub extern "C" fn call() {

let err_code = match 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. */
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.
None, // No deposit limit.
&u256_bytes(10_000u64), // Value to transfer.
input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn load_input(delegate_call: bool) {
}

if delegate_call {
api::delegate_call(uapi::CallFlags::empty(), address, 0, 0, None, &[], None).unwrap();
api::delegate_call(uapi::CallFlags::empty(), address, u64::MAX, u64::MAX, None, &[], None).unwrap();
}
}

Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::ALLOW_REENTRY,
&addr,
0u64,
0u64,
u64::MAX,
u64::MAX,
None,
&[0; 32],
&[],
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/read_only_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::READ_ONLY,
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.
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = all.
None, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
callee_input,
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/recurse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ 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 deposit_limit to devote for the execution. 0 = all.
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all resources.
u64::MAX, // How much deposit_limit to devote for the execution. u64::MAX = use all resources.
None, // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
&(calls_left - 1).to_le_bytes(),
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/revive/fixtures/contracts/return_data_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn assert_return_data_size_of(expected: u64) {

/// Assert the return data to be reset after a balance transfer.
fn assert_balance_transfer_does_reset() {
api::call(uapi::CallFlags::empty(), &[0u8; 20], 0, 0, None, &u256_bytes(128), &[], None)
api::call(uapi::CallFlags::empty(), &[0u8; 20], u64::MAX, u64::MAX, None, &u256_bytes(128), &[], None)
.unwrap();
assert_return_data_size_of(0);
}
Expand Down Expand Up @@ -113,8 +113,8 @@ pub extern "C" fn call() {
let mut instantiate = |exit_flag| {
api::instantiate(
code_hash,
0u64,
0u64,
u64::MAX,
u64::MAX,
None,
&[0; 32],
&construct_input(exit_flag),
Expand All @@ -127,8 +127,8 @@ pub extern "C" fn call() {
api::call(
uapi::CallFlags::empty(),
address_buf,
0u64,
0u64,
u64::MAX,
u64::MAX,
None,
&[0; 32],
&construct_input(exit_flag),
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/self_destruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ 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.
u64::MAX, // How much ref_time to devote for the execution. u64 = all.
u64::MAX, // How much proof_size to devote for the execution. u64 = all.
None, // No deposit limit.
&[0u8; 32], // Value to transfer.
&[0u8; 0],
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern crate alloc;
// generated file that tells us where to find the fixtures
include!(concat!(env!("OUT_DIR"), "/fixture_location.rs"));

/// Load a given wasm module and returns a wasm binary contents along with it's hash.
/// Load a given wasm module and returns a wasm binary contents along with its hash.
#[cfg(feature = "std")]
pub fn compile_module(fixture_name: &str) -> anyhow::Result<(Vec<u8>, sp_core::H256)> {
let out_dir: std::path::PathBuf = FIXTURE_DIR.into();
Expand Down
Loading
Loading