Skip to content

WIP: pallet-revive: Raise contract size limit to one megabyte and raise call depth to 25 #9267

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
54 changes: 44 additions & 10 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions substrate/frame/revive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ num-bigint = { workspace = true }
num-integer = { workspace = true }
num-traits = { workspace = true }
paste = { workspace = true }
polkavm = { version = "0.26.0", default-features = false }
polkavm-common = { version = "0.26.0", default-features = false, optional = true }
polkavm = { git = "https://github.com/aman4150/polkavm.git", branch = "polkavm_memory", default-features = false }
polkavm-common = { git = "https://github.com/aman4150/polkavm.git", branch = "polkavm_memory", default-features = false, optional = true }
rand = { workspace = true, optional = true }
rand_pcg = { workspace = true, optional = true }
rlp = { workspace = true }
Expand Down Expand Up @@ -62,7 +62,7 @@ subxt-signer = { workspace = true, optional = true, features = ["unstable-eth"]
[dev-dependencies]
array-bytes = { workspace = true, default-features = true }
assert_matches = { workspace = true }
polkavm-common = { version = "0.26.0" }
polkavm-common = { git = "https://github.com/aman4150/polkavm.git", branch = "polkavm_memory" }
pretty_assertions = { workspace = true }
secp256k1 = { workspace = true, features = ["recovery"] }
serde_json = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#![no_main]
include!("../panic_handler.rs");

polkavm_derive::min_stack_size!(256 * 1024);

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

#[no_mangle]
Expand All @@ -38,7 +40,7 @@ pub extern "C" fn call() {
);

// the first 4 bytes are reserved for the return code
let mut output = [0u8; 512];
let mut output = [0u8; 128 * 1024];
let output_ptr = &mut &mut output[4..];

let code = match api::call(
Expand Down
51 changes: 51 additions & 0 deletions substrate/frame/revive/fixtures/contracts/call_with_input_size.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.

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

polkavm_derive::min_stack_size!(512 * 1024);

use uapi::{input, 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() {
input!(
input_size: u32,
);

let input_buf = [0u8; 256 * 1024];
let address = [1u8; 20];

// Call the callee
api::call(
uapi::CallFlags::empty(),
&address,
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.
&[0; 32], // Value transferred to the contract.
&input_buf[..input_size as usize],
None,
).unwrap();
}
2 changes: 1 addition & 1 deletion substrate/frame/revive/fixtures/contracts/oom_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ include!("../panic_handler.rs");

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

static BUFFER: [u8; 1025 * 1024] = [0; 1025 * 1024];
static BUFFER: [u8; 1024 * 1024] = [0; 1024 * 1024];

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/oom_rw_included.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ include!("../panic_handler.rs");

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

static mut BUFFER: [u8; 513 * 1024] = [42; 513 * 1024];
static mut BUFFER: [u8; 1024 * 1024] = [42; 1024 * 1024];

unsafe fn buffer() -> &'static [u8; 513 * 1024] {
unsafe fn buffer() -> &'static [u8; 1024 * 1024] {
let ptr = core::ptr::addr_of!(BUFFER);
&*ptr
}
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/oom_rw_trailing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ include!("../panic_handler.rs");

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

static mut BUFFER: [u8; 2 * 1025 * 1024] = [0; 2 * 1025 * 1024];
static mut BUFFER: [u8; 2 * 1024 * 1024] = [0; 2 * 1024 * 1024];

unsafe fn buffer() -> &'static [u8; 2 * 1025 * 1024] {
unsafe fn buffer() -> &'static [u8; 2 * 1024 * 1024] {
let ptr = core::ptr::addr_of!(BUFFER);
&*ptr
}
Expand Down
29 changes: 15 additions & 14 deletions substrate/frame/revive/fixtures/contracts/recurse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#![no_main]
include!("../panic_handler.rs");

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

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -36,19 +36,20 @@ pub extern "C" fn call() {
let mut addr = [0u8; 20];
api::address(&mut addr);

if calls_left == 0 {
return
let mut return_buffer = calls_left.to_le_bytes();

if calls_left > 0 {
let _ = api::call(
uapi::CallFlags::ALLOW_REENTRY,
&addr,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all resources.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all resources.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
&(calls_left - 1).to_le_bytes(),
Some(&mut &mut return_buffer[..]),
);
}

api::call(
uapi::CallFlags::ALLOW_REENTRY,
&addr,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all resources.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all resources.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
&(calls_left - 1).to_le_bytes(),
None,
)
.unwrap();
api::return_value(ReturnFlags::empty(), &return_buffer);
}
40 changes: 40 additions & 0 deletions substrate/frame/revive/fixtures/contracts/return_sized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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.

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

polkavm_derive::min_stack_size!(512 * 1024);

use uapi::{ReturnFlags, input, 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() {
input!(
return_size: u32,
);

let return_buf = [42u8; 256 * 1024];
api::return_value(ReturnFlags::empty(), &return_buf[..return_size as usize])

}
Loading
Loading