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