Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
538 commits
Select commit Hold shift + click to select a range
d1d5199
cleanup
Aug 26, 2025
dec0849
PR review
pgherveou Aug 26, 2025
cc45f5b
Code cleanup and calls refactoring
smiasojed Aug 26, 2025
ea5011b
Update substrate/frame/revive/src/exec.rs
smiasojed Aug 26, 2025
dbfc430
make pristine unbounded and check PVM & EVM code size
pgherveou Aug 26, 2025
b4e868f
create: set caller frame
xermicus Aug 26, 2025
87b7b4e
nit
pgherveou Aug 26, 2025
b4dad01
added comments
Aug 26, 2025
fbdd9fc
commented code so that estending memory will not cost any gas
Aug 26, 2025
cb8b8ce
added TODO in host.rs instruction for extcodecopy gas macro
Aug 26, 2025
ee7c237
unused vars in macros.rs
Aug 26, 2025
b769010
refcount = 1 for evm
pgherveou Aug 26, 2025
5a6c9f2
the exec error to halt reason mapping function
xermicus Aug 26, 2025
0abfc74
fix
pgherveou Aug 26, 2025
6060eb4
fix
pgherveou Aug 26, 2025
2007fb5
add one more assert
pgherveou Aug 26, 2025
f219e06
nit
pgherveou Aug 26, 2025
5a965c7
the callcode instruction is unsupported
xermicus Aug 26, 2025
6f25eed
typos
xermicus Aug 26, 2025
99718d6
typos
xermicus Aug 26, 2025
2a88092
format the fixtures
xermicus Aug 26, 2025
33e9216
Remove refcount and owner for EVM CodeInfo
pgherveou Aug 26, 2025
f75403a
rm unused
pgherveou Aug 26, 2025
d26d8ac
origin should be held not caller
pgherveou Aug 26, 2025
cc8cef4
Merge branch 'master' into pg/revm
pgherveou Aug 27, 2025
b61416a
Rm copy cost from call
smiasojed Aug 27, 2025
d647759
fix ci
Aug 27, 2025
63290b9
dummy chang
Aug 27, 2025
d22ac45
nit
Aug 27, 2025
8bd37b6
fix ci
Aug 27, 2025
9d40097
changed prdoc to major
Aug 27, 2025
e405e18
rollback refcount removals
pgherveou Aug 27, 2025
8b1669f
Update Cargo.toml
pgherveou Aug 27, 2025
4f86e9b
Update prdoc/pr_9285.prdoc
pgherveou Aug 27, 2025
315ae52
Update substrate/frame/revive/src/call_builder.rs
pgherveou Aug 27, 2025
3598d6f
Update substrate/frame/revive/src/benchmarking.rs
pgherveou Aug 27, 2025
3272e99
rm charge_evm_init_cost
pgherveou Aug 27, 2025
e2242a2
fix
pgherveou Aug 27, 2025
7fa6421
rm - 1
pgherveou Aug 27, 2025
ae647b6
restore legacy behaviour
pgherveou Aug 27, 2025
e374a38
fix selfdestruct in exec.rs and host.rs
Aug 27, 2025
3197e68
Add revert test and fix errors mapping
smiasojed Aug 27, 2025
9c56173
Add call tests
smiasojed Aug 27, 2025
38602a5
format fixtures
xermicus Aug 28, 2025
4971e97
the unified error mapping approach
xermicus Aug 28, 2025
90656f2
Enable invalid opcode test for EVM
smiasojed Aug 28, 2025
1a073b6
update
pgherveou Aug 28, 2025
2765b13
Merge remote-tracking branch 'origin/pg/revm' into rve/revm-instructi…
Aug 28, 2025
ce5254d
the instruction result to exec error mapping function
xermicus Aug 28, 2025
11fbe30
using U256Converter trait
Aug 28, 2025
d4d8c1a
deadcode unused for now
pgherveou Aug 28, 2025
511fe2b
the INVALID EVM opcode test
xermicus Aug 28, 2025
115c860
Reject bytecode starting with 0xef (EOF)
smiasojed Aug 28, 2025
17b713a
Merge branch 'pg/revm' into sm/vm-instr
xermicus Aug 28, 2025
f0b629d
fixed gas charge in host sstore and tstore
Aug 28, 2025
eac460a
the create tester needs value to instantiate contracts
xermicus Aug 28, 2025
e286c49
deposit fixes
pgherveou Aug 28, 2025
f9aebdc
add missing assert
pgherveou Aug 28, 2025
7232f99
tweak tests
pgherveou Aug 28, 2025
6d0181e
fixed copy paste mistake
Aug 28, 2025
04001a2
fixed review comment
Aug 28, 2025
f68a53d
remove allow deadcode in utility.rs
Aug 28, 2025
f175c1b
ensure pallet_account exits
pgherveou Aug 28, 2025
76a2078
Use U256 converter
smiasojed Aug 28, 2025
bf19cf0
fixes
pgherveou Aug 29, 2025
7211711
nit
pgherveou Aug 29, 2025
c1ba77d
update comment
pgherveou Aug 29, 2025
46f6dfb
Add back remove_code
pgherveou Aug 29, 2025
d137f91
fix ci
Aug 29, 2025
135a9e0
Merge remote-tracking branch 'origin/pg/revm' into sm/vm-instr
smiasojed Aug 29, 2025
a7c3083
Add missing license
smiasojed Aug 29, 2025
546d65d
nit
pgherveou Aug 29, 2025
51ba0f7
trigger ci
Aug 29, 2025
4edc46e
format
Aug 29, 2025
7afade1
fix compilation issue
Aug 29, 2025
972a51f
Address comment
smiasojed Aug 29, 2025
9a34932
Update substrate/frame/revive/src/vm/evm.rs
smiasojed Aug 29, 2025
d820477
Update substrate/frame/revive/src/lib.rs
pgherveou Aug 29, 2025
c16e6ce
mint balance in migration
pgherveou Aug 29, 2025
1541263
rm check
pgherveou Aug 29, 2025
0a8935c
fmt
pgherveou Aug 29, 2025
692abb2
fixes
pgherveou Aug 29, 2025
d1808d6
added test for invalid jumpdest
Aug 29, 2025
a504987
reject hash == 0
pgherveou Aug 29, 2025
a064b21
review comments
Aug 29, 2025
4283724
removed formatting diff
Aug 29, 2025
3a9f3d7
warm up pallet_account
pgherveou Aug 29, 2025
c245621
Update substrate/frame/revive/src/migrations/v2.rs
pgherveou Aug 29, 2025
f04044f
Apply comments
smiasojed Aug 29, 2025
29765fc
fix unused variable
Aug 29, 2025
88c6b23
Update ExtBuilder
pgherveou Aug 29, 2025
60b168d
Fmt
smiasojed Aug 29, 2025
5dc7d0b
Add assert for gas checking
smiasojed Aug 29, 2025
3201fb2
Merge branch 'master' into pg/revm
pgherveou Aug 29, 2025
a4be918
fix selfdestruct
Aug 29, 2025
400c912
Update .github/workflows/tests-misc.yml
pgherveou Aug 29, 2025
a1178f3
Update from github-actions[bot] running command 'bench --runtime dev …
github-actions[bot] Aug 29, 2025
0362daf
added contracts_created check to selfdestruct in Stack
Aug 31, 2025
f79c8dd
Merge remote-tracking branch 'origin/pg/revm' into rve/revm-instructi…
Aug 31, 2025
d502f36
fix tests-misc
pgherveou Sep 1, 2025
28a1b65
fix
pgherveou Sep 1, 2025
739300d
test for selfdestruct needs create
Sep 1, 2025
3f5bc89
Merge remote-tracking branch 'origin/pg/revm' into rve/revm-instructi…
Sep 1, 2025
80b2d56
Merge branch 'pg/revm' into sm/vm-instr
pgherveou Sep 1, 2025
d85b361
Merge branch 'master' into sm/vm-instr
pgherveou Sep 1, 2025
44ea81c
fix log level
pgherveou Sep 1, 2025
4e58574
fix
pgherveou Sep 1, 2025
da38232
Merge remote-tracking branch 'origin/sm/vm-instr' into rve/revm-instr…
Sep 1, 2025
7d1da2a
disabled test call_invalid_opcode
Sep 1, 2025
80ffaa4
fix CI
Sep 1, 2025
73aaaee
selfdestruct_delete_works not working
Sep 1, 2025
4b491f9
make it compile
Sep 2, 2025
b57e6d3
Merge remote-tracking branch 'origin/master' into rve/revm-instructio…
Sep 2, 2025
167e660
format
Sep 2, 2025
0c18dda
Update prdoc/pr_9385.prdoc
0xRVE Sep 2, 2025
3a32468
clippy
Sep 2, 2025
4fc05d1
disable selfdestruct
Sep 2, 2025
dbcea0c
implemented defered contract destruction, tests failing
Sep 4, 2025
46d494b
added sekf_destruct_factory fixture
Sep 5, 2025
e14f014
typo
Sep 5, 2025
f9f8f75
seems to work now
Sep 8, 2025
a459b40
removed selfdestruct from exec.rs
Sep 8, 2025
195872b
added terminate function to builtin system precompile but not working
Sep 9, 2025
3da6cb5
added logging, still it does not work
Sep 10, 2025
12c1c76
Merge remote-tracking branch 'origin/master' into rve/revm-selfdestruct2
Sep 10, 2025
743e1d8
typo
Sep 10, 2025
667fd4c
Merge remote-tracking branch 'origin/master' into rve/revm-selfdestruct2
Sep 19, 2025
c647719
created separate fixture self_destruct2
Sep 19, 2025
d7792c5
self_destruct2 ficture seems to work?
Sep 20, 2025
259c837
clean up
Sep 21, 2025
c69596d
Merge remote-tracking branch 'origin/master' into rve/revm-selfdestruct2
Sep 21, 2025
cd66780
fixed two original tests
Sep 21, 2025
0efc997
small fixes but terminate call still not working through uapi
Sep 21, 2025
c66572f
fixed selector and calldata
Sep 21, 2025
851eca8
cleanup
Sep 21, 2025
9641755
fixed allow_from_outside_tx behavior
Sep 21, 2025
660c2b5
added comment in env.rs describing allow_from_outside_tx
Sep 21, 2025
aaefa0c
self_destruct_work still had incorrect balance
Sep 22, 2025
ea4622a
undo change
Sep 22, 2025
b58aa98
fixed balance problem in self_destruct_works
Sep 22, 2025
6bb3ad8
fixed self_destruct_works
Sep 22, 2025
855ac8e
removed dead code
Sep 22, 2025
b467f87
self_destruct2_works test runs but the balance is not credited to DJA…
Sep 22, 2025
52dbcd2
removed print
Sep 22, 2025
d8c9009
comment
Sep 22, 2025
bfd0374
django still didnt get 100_000 balance
Sep 22, 2025
fa1f55b
refunding storage deposit to the origin of the tx
Sep 23, 2025
2f9f2b3
ALL TESTDS WORK EXCEPT FOR SELF_DESTRUCT2_WORKS
Sep 23, 2025
de0e187
added storage meter charge coalescing
Sep 23, 2025
a34252f
logging
Sep 23, 2025
cf686d7
small fix
Sep 23, 2025
916d1b8
self_destruct2_works finally passed
Sep 23, 2025
a484091
fixed some error handling
Sep 23, 2025
5c1109c
added TODO for handling error coming out of destroy_contract()
Sep 23, 2025
966a215
Update substrate/frame/revive/uapi/src/precompiles/system.rs
0xRVE Sep 24, 2025
65e5d06
Update substrate/frame/revive/Cargo.toml
0xRVE Sep 24, 2025
8a562c1
Update substrate/frame/revive/src/storage/meter.rs
0xRVE Sep 24, 2025
744d1f1
Update substrate/frame/revive/src/storage/meter.rs
0xRVE Sep 24, 2025
63672dc
small fix in meter.rs
Sep 24, 2025
a62790a
fixes from review comments
Sep 24, 2025
5bc59ad
cleanup
Sep 25, 2025
2810cf2
coalesce_and_refund_destroyed_contracts
Sep 25, 2025
01f48ca
found bug in mater.rs charge method
Sep 29, 2025
d6e894d
fixing coalescing of charges on in meter.rs
Sep 29, 2025
554da0d
fixed deposit charge and refund coalesce
Sep 29, 2025
8ab22ed
format
Sep 30, 2025
84e4b6e
moved all destruction logic to meter.rs charge()
Sep 30, 2025
95c8c6d
fixed tests
Sep 30, 2025
d1d6f79
cargo check
Sep 30, 2025
42f4c5d
removed itertools dependency as it was causing linking error because …
Sep 30, 2025
e453559
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Sep 30, 2025
02e7024
fix ci
Oct 1, 2025
e8cdd47
format
Oct 1, 2025
7977e9e
clean up
Oct 1, 2025
2ae7876
cargo check
Oct 1, 2025
e155c57
fix ci
Oct 1, 2025
66ce550
added new benchmark for terminate
Oct 2, 2025
9e125e6
update comment in self_destruct2.rs fixture
Oct 2, 2025
8959f06
added method for benchmarking terminate
Oct 2, 2025
7f8c965
renamed banchmark seal_Terminate
Oct 2, 2025
b10eb4e
format
Oct 2, 2025
c9adb5f
removed assert from seal_terminate
Oct 2, 2025
ec72b5e
fix ci
Oct 2, 2025
08b75ad
fix ci
Oct 2, 2025
f1abebf
Merge remote-tracking branch 'origin/master' into rve/revm-selfdestruct2
Oct 3, 2025
a800d8d
Update from github-actions[bot] running command 'bench --runtime dev …
github-actions[bot] Oct 3, 2025
e830473
added seal_terminate_logic to runtime_costs
Oct 3, 2025
2636072
typo
Oct 3, 2025
cb4b776
changed debug message
Oct 3, 2025
2d915f2
fixed returm value of cargo test
Oct 3, 2025
7eed6be
fixed gas charging and adjsuting
Oct 3, 2025
50eb46e
fixed code deletion not propagated to meter
Oct 3, 2025
5f82f1b
added test self_destruct2_does_not_delete_code
Oct 3, 2025
980ff03
fixed bug in meter.rs but alice still gets her deposit refunded
Oct 3, 2025
bf40cfa
fixed refund if selfdestruct not in same tx as create
Oct 3, 2025
b4020c4
Merge remote-tracking branch 'origin/master' into rve/revm-selfdestruct2
Oct 3, 2025
5e0d505
format
Oct 6, 2025
8597d39
Merge remote-tracking branch 'origin/master' into rve/revm-selfdestruct2
Oct 6, 2025
0e45287
format
Oct 6, 2025
381a460
update workflow
Oct 6, 2025
1c89e49
remove brew command again
Oct 6, 2025
3686985
fixed benchmark
Oct 6, 2025
df94e09
fix ci
Oct 6, 2025
37ea157
fix ci
Oct 6, 2025
46c1d4c
Update substrate/frame/revive/src/storage/meter.rs
0xRVE Oct 6, 2025
71deb86
fixed comment in meter
Oct 6, 2025
4a4ac33
removed bare_instantiate_with_signer
Oct 6, 2025
d182c9d
remove prdoc
Oct 6, 2025
a043d53
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Oct 7, 2025
6e2694e
undo rename of cached_contract_info and moved phantondata to bottom
Oct 9, 2025
45835d0
Update substrate/frame/revive/uapi/src/precompiles/system.rs
0xRVE Oct 9, 2025
a9c126f
fixed most review comments
Oct 9, 2025
9a43ad7
cargo check
Oct 9, 2025
36203ad
added assert to benchmark
Oct 9, 2025
dcd9f64
selfdestruct precompile always deleted code. selfdestruct syscall beh…
Oct 9, 2025
bf1c5f6
Merge remote-tracking branch 'origin/master' into rve/revm-selfdestruct2
Oct 9, 2025
ba2206a
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Oct 10, 2025
f2f53d1
review comment fix
Oct 10, 2025
0e958be
fix ci
Oct 10, 2025
c20f17c
fixed bench mark
Oct 14, 2025
5f06f43
cargo check
Oct 14, 2025
a4ad61d
format
Oct 14, 2025
08f5f19
cargo check
Oct 14, 2025
de96680
clean up and trigger ci
Oct 14, 2025
98eccc4
Merge remote-tracking branch 'origin/master' into rve/revm-selfdestruct2
Oct 15, 2025
96c4649
format
Oct 17, 2025
4232a9d
removed prdoc
Oct 18, 2025
7f1cad5
review comments
Oct 18, 2025
d83e343
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Oct 18, 2025
f7814ef
update prdoc
Oct 19, 2025
74e9fe8
format
Oct 19, 2025
973f120
review comments
0xRVE Oct 21, 2025
be54781
format
0xRVE Oct 21, 2025
b569794
Merge remote-tracking branch 'origin/master' into rve/revm-selfdestruct2
0xRVE Oct 21, 2025
472ad26
trigger ci
0xRVE Oct 21, 2025
534a61f
added check in selfdestruct for StateChangeDenied
0xRVE Oct 21, 2025
146ab40
fixed comment
0xRVE Oct 21, 2025
54a8f2c
Update substrate/frame/revive/src/tests/pvm.rs
0xRVE Oct 21, 2025
8668892
Update substrate/frame/revive/src/benchmarking.rs
0xRVE Oct 21, 2025
a441b96
test fixtures
0xRVE Oct 21, 2025
6074765
added static context check in system precompile
0xRVE Oct 22, 2025
8386a75
review comments and half assed test for static context selfdestruct
0xRVE Oct 22, 2025
4eb2906
added test for staticcontext selfdestruct
0xRVE Oct 22, 2025
06a120c
nit
0xRVE Oct 22, 2025
6307093
fixed match arm
0xRVE Oct 22, 2025
3fe5750
Update substrate/frame/revive/src/precompiles/builtin/system.rs
0xRVE Oct 23, 2025
25a937a
nit
0xRVE Oct 23, 2025
8fc51bf
Update substrate/frame/revive/src/vm/evm/instructions/host.rs
0xRVE Oct 23, 2025
d84d7c0
remove static-context tests to be done later
0xRVE Oct 24, 2025
8bd6870
Merge remote-tracking branch 'origin/master' into rve/revm-selfdestruct2
0xRVE Oct 24, 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
16 changes: 16 additions & 0 deletions prdoc/pr_9699.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
title: Rve/revm selfdestruct2
doc:
- audience: Runtime Dev
description: |-
fixes https://github.com/paritytech/polkadot-sdk/issues/9621

Behavior of `terminate` is changed in accordance with EIP-6780 (and EVM in general):
- `terminate` only deletes the code from storage if it is called in the same transaction the contract was created.
- `terminate` does not destroy the contract instantly. The contract is registered for destruction, which happens at the end of the transaction.
crates:
- name: pallet-revive
bump: minor
- name: pallet-revive-fixtures
bump: minor
- name: pallet-revive-uapi
bump: minor
5 changes: 5 additions & 0 deletions substrate/frame/revive/fixtures/contracts/HostEvmOnly.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ contract HostEvmOnly {
selfdestruct(recipient)
}
}
function fallback(address payable recipient) public {
Copy link
Copy Markdown
Member

@xermicus xermicus Oct 23, 2025

Choose a reason for hiding this comment

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

Don't do this. Either make it the fallback function and use for example msg.sender as recipient or choose a function name which doesn't shadow the fallback function (then ensure the tests pass the selector accordingly to not revert inside the function dispatch).

assembly {
selfdestruct(recipient)
}
}

function extcodecopyOp(address account, uint64 offset, uint64 size) public view returns (bytes memory code) {
code = new bytes(size);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ pub extern "C" fn call() {
.unwrap();
} else {
// Try to terminate and give balance to django.
api::terminate(&DJANGO_FALLBACK);

// Build the calldata: selector + ABI-encoded address
let selector = uapi::solidity_selector("terminate(address)");
let mut calldata = [0u8; 4 + 32];
calldata[0..4].copy_from_slice(&selector);
// ABI encode address: right-align into 32 bytes (pad with 12 leading zeros)
calldata[4 + 12..4 + 32].copy_from_slice(&DJANGO_FALLBACK);

let _ = api::call(
uapi::CallFlags::ALLOW_REENTRY,
&uapi::SYSTEM_PRECOMPILE_ADDR,
u64::MAX,
u64::MAX,
&[u8::MAX; 32],
&[0u8; 32],
&calldata,
None,
).unwrap();
}
}
Comment thread
0xRVE marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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");

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() {
const DJANGO_FALLBACK: [u8; 20] = [4u8; 20];
api::terminate(&DJANGO_FALLBACK);
}
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

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

use uapi::{input, u256_bytes, 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!(36, code_hash: [u8],);

let mut addr = [0u8; 20];
let salt = [1u8; 32];
api::instantiate(
u64::MAX,
u64::MAX,
&[u8::MAX; 32],
&u256_bytes(100_000_000_000u64),
code_hash,
Some(&mut addr),
None,
Some(&salt),
).unwrap();

api::call(
uapi::CallFlags::empty(),
&addr,
u64::MAX,
u64::MAX,
&[0u8; 32],
&[0u8; 32],
&[],
None,
).unwrap();

// Return the address of the created (and destroyed) contract
api::return_value(uapi::ReturnFlags::empty(), &addr);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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");

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

const DJANGO_FALLBACK: [u8; 20] = [4u8; 20];

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn deploy() {
// Build the calldata: selector + ABI-encoded address
let selector = uapi::solidity_selector("terminate(address)");
let mut calldata = [0u8; 4 + 32];
calldata[0..4].copy_from_slice(&selector);
// ABI encode address: right-align into 32 bytes (pad with 12 leading zeros)
calldata[4 + 12..4 + 32].copy_from_slice(&DJANGO_FALLBACK);

let _ = api::call(
uapi::CallFlags::ALLOW_REENTRY,
&uapi::SYSTEM_PRECOMPILE_ADDR,
u64::MAX,
u64::MAX,
&[u8::MAX; 32],
&[0u8; 32],
&calldata,
None,
).unwrap();
}

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,21 @@ pub extern "C" fn deploy() {}
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {
input!(beneficiary: &[u8; 20],);
api::terminate(&beneficiary);
// Build the calldata: selector + ABI-encoded address
let selector = uapi::solidity_selector("terminate(address)");
let mut calldata = [0u8; 4 + 32];
calldata[0..4].copy_from_slice(&selector);
// ABI encode address: right-align into 32 bytes (pad with 12 leading zeros)
calldata[4 + 12..4 + 32].copy_from_slice(beneficiary);

let _ = api::call(
uapi::CallFlags::ALLOW_REENTRY,
&uapi::SYSTEM_PRECOMPILE_ADDR,
u64::MAX,
u64::MAX,
&[u8::MAX; 32],
&[0u8; 32],
&calldata,
None,
).unwrap();
}
49 changes: 47 additions & 2 deletions substrate/frame/revive/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ use frame_support::{
self, assert_ok,
migrations::SteppedMigration,
storage::child,
traits::{fungible::InspectHold, Hooks},
traits::{
fungible::{InspectHold, UnbalancedHold},
Hooks,
},
weights::{Weight, WeightMeter},
};
use frame_system::RawOrigin;
Expand Down Expand Up @@ -1221,7 +1224,49 @@ mod benchmarks {
}

assert!(matches!(result, Err(crate::vm::pvm::TrapReason::Termination)));
assert_eq!(PristineCode::<T>::get(code_hash).is_none(), delete_code);

Ok(())
}

#[benchmark(pov_mode = Measured)]
Comment thread
0xRVE marked this conversation as resolved.
fn seal_terminate_logic() -> Result<(), BenchmarkError> {
let beneficiary = account::<T::AccountId>("beneficiary", 0, 0);

build_runtime!(_runtime, instance, _memory: [vec![0u8; 0], ]);
let code_hash = instance.info()?.code_hash;

assert!(PristineCode::<T>::get(code_hash).is_some());

// Set storage deposit to zero so terminate_logic can proceed.
T::Currency::set_balance_on_hold(
&HoldReason::StorageDepositReserve.into(),
&instance.account_id,
0u32.into(),
)
.unwrap();

T::Currency::set_balance(&instance.account_id, Pallet::<T>::min_balance() * 2u32.into());

let result;
#[block]
{
result = crate::storage::meter::terminate_logic_for_benchmark::<T>(
&instance.account_id,
&beneficiary,
);
}
result.unwrap();

// Check that the contract is removed
assert!(PristineCode::<T>::get(code_hash).is_none());

// Check that the balance has been transferred away
let balance = <T as Config>::Currency::total_balance(&instance.account_id);
assert_eq!(balance, 0u32.into());

// Check that the beneficiary received the balance
let balance = <T as Config>::Currency::balance(&beneficiary);
assert_eq!(balance, Pallet::<T>::min_balance() * 2u32.into());

Ok(())
Comment thread
0xRVE marked this conversation as resolved.
}
Expand Down
Loading
Loading