Skip to content

Commit

Permalink
Remove 0 as a special case in gas/storage meters (paritytech#6890)
Browse files Browse the repository at this point in the history
Closes paritytech#6846 .

---------

Signed-off-by: xermicus <[email protected]>
Co-authored-by: command-bot <>
Co-authored-by: Alexander Theißen <[email protected]>
Co-authored-by: xermicus <[email protected]>
  • Loading branch information
3 people authored and Nathy-bajo committed Jan 21, 2025
1 parent 7405421 commit 385ac04
Show file tree
Hide file tree
Showing 39 changed files with 355 additions and 264 deletions.
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
19 changes: 19 additions & 0 deletions prdoc/pr_6890.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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: Alter semantic meaning of 0 in metering limits of EVM contract calls

doc:
- audience: [ Runtime Dev, Runtime User ]
description: |
A limit of 0, for gas meters and storage meters, no longer has the meaning of unlimited metering.

crates:
- name: pallet-revive
bump: patch
- name: pallet-revive-fixtures
bump: patch
- name: pallet-revive-uapi
bump: patch
- name: pallet-revive-eth-rpc
bump: patch
8 changes: 4 additions & 4 deletions substrate/frame/revive/fixtures/contracts/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
&[u8::MAX; 32], // 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 @@ -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,
&[u8::MAX; 32],
&[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,
&[u8::MAX; 32],
&[0; 32],
&[0; 32],
None,
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/revive/fixtures/contracts/call_return_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
&[u8::MAX; 32], // 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 @@ -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.
&[u8::MAX; 32], // 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 @@ -40,10 +40,10 @@ 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.
&u256_bytes(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.
&[u8::MAX; 32], // No deposit limit.
&u256_bytes(value), // Value transferred to the contract.
forwarded_input,
None,
)
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/call_with_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // value transferred to the contract.
forwarded_input,
None,
)
Expand Down
48 changes: 24 additions & 24 deletions substrate/frame/revive/fixtures/contracts/caller_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
&[u8::MAX; 32], // 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.
&[u8::MAX; 32], // 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
&[u8::MAX; 32], // 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.
&[u8::MAX; 32], // 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.
&[u8::MAX; 32], // 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.
&[u8::MAX; 32], // 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
&[u8::MAX; 32], // 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.
&[u8::MAX; 32], // No deposit limit.
&value,
&input,
Some(&mut &mut output[..]),
Expand Down
Original file line number Diff line number Diff line change
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.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
input,
None,
)
Expand Down
12 changes: 11 additions & 1 deletion substrate/frame/revive/fixtures/contracts/create1_with_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ 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,
&[u8::MAX; 32],
&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 @@ -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.
&[u8::MAX; 32], // No deposit limit.
&[0u8; 32], // Value transferred to the contract.
input,
None,
)
Expand Down
10 changes: 9 additions & 1 deletion substrate/frame/revive/fixtures/contracts/delegate_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ pub extern "C" fn call() {
assert!(value[0] == 2u8);

let input = [0u8; 0];
api::delegate_call(uapi::CallFlags::empty(), address, ref_time, proof_size, None, &input, None).unwrap();
api::delegate_call(
uapi::CallFlags::empty(),
address,
ref_time,
proof_size,
&[u8::MAX; 32],
&input,
None
).unwrap();

api::get_storage(StorageFlags::empty(), &key, value).unwrap();
assert!(value[0] == 1u8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ 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,
&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,13 @@ 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,
&[u8::MAX; 32],
&input,
None
).unwrap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ 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.
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.
&[u8::MAX; 32], // No deposit limit.
&VALUE,
&input,
Some(&mut address),
Expand All @@ -62,9 +62,9 @@ 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.
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.
&[u8::MAX; 32], // No deposit limit.
&VALUE,
&[0u8; 1],
None,
Expand All @@ -75,9 +75,9 @@ 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.
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.
&[u8::MAX; 32], // No deposit limit.
&VALUE,
&[0u8; 0],
None,
Expand Down
Loading

0 comments on commit 385ac04

Please sign in to comment.