-
Notifications
You must be signed in to change notification settings - Fork 1.2k
EIP-3607 added check to make sure a contract account cannot transfer funds as an EOA account #9717
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
Changes from 23 commits
14ee22e
641883c
1818eb6
b0f25f2
519626e
26a8c87
7dfae21
89a50ed
e68d273
96256ce
c7000cd
868f6f6
7c69faf
92114f8
45c767d
70838e7
1ca5129
b1f52b7
ceebe36
60d1fd8
f19903d
10a5df0
d0901f2
61d710d
00f8b75
d8cc88e
2b722b7
7edb09e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| title: EIP-3607 added check to make sure a contract account cannot transfer funds | ||
| as an EOA account | ||
| doc: | ||
| - audience: Runtime Dev | ||
| description: fixes https://github.com/paritytech/polkadot-sdk/issues/9570 | ||
| crates: | ||
| - name: pallet-revive | ||
| bump: patch | ||
| - name: pallet-assets | ||
| bump: patch |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1193,6 +1193,9 @@ where | |||||
| storage_deposit_limit: DepositLimit<BalanceOf<T>>, | ||||||
| data: Vec<u8>, | ||||||
| ) -> ContractResult<ExecReturnValue, BalanceOf<T>> { | ||||||
| if let Err(contract_result) = Self::ensure_non_contract_if_signed(&origin) { | ||||||
| return contract_result; | ||||||
| } | ||||||
| let mut gas_meter = GasMeter::new(gas_limit); | ||||||
| let mut storage_deposit = Default::default(); | ||||||
|
|
||||||
|
|
@@ -1250,6 +1253,10 @@ where | |||||
| salt: Option<[u8; 32]>, | ||||||
| bump_nonce: BumpNonce, | ||||||
| ) -> ContractResult<InstantiateReturnValue, BalanceOf<T>> { | ||||||
| // Enforce EIP-3607 for top-level signed origins: deny signed contract addresses. | ||||||
| if let Err(contract_result) = Self::ensure_non_contract_if_signed(&origin) { | ||||||
| return contract_result; | ||||||
| } | ||||||
| let mut gas_meter = GasMeter::new(gas_limit); | ||||||
| let mut storage_deposit = Default::default(); | ||||||
| let unchecked_deposit_limit = storage_deposit_limit.is_unchecked(); | ||||||
|
|
@@ -1715,6 +1722,50 @@ where | |||||
| .saturating_mul(T::NativeToEthRatio::get().into()) | ||||||
| .saturating_add(dust.into()) | ||||||
| } | ||||||
|
|
||||||
| /// Ensure the origin has no code deplyoyed if it is a signed origin. | ||||||
| fn ensure_non_contract_if_signed<ReturnValue>( | ||||||
| origin: &OriginFor<T>, | ||||||
| ) -> Result<(), ContractResult<ReturnValue, BalanceOf<T>>> { | ||||||
| use crate::exec::{code_hash, is_precompile, EMPTY_CODE_HASH}; | ||||||
| if let Ok(who) = ensure_signed(origin.clone()) { | ||||||
0xRVE marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| let address = <T::AddressMapper as AddressMapper<T>>::to_address(&who); | ||||||
|
|
||||||
| // EIP_1052: precompile can never be used as EOA. | ||||||
| if is_precompile::<T>(&address) { | ||||||
| log::debug!( | ||||||
| target: crate::LOG_TARGET, | ||||||
| "EIP-3607: reject externally-signed tx from precompile account {:?}", | ||||||
| address | ||||||
| ); | ||||||
| return Err(ContractResult { | ||||||
| result: Err(DispatchError::BadOrigin), | ||||||
| gas_consumed: Weight::default(), | ||||||
| gas_required: Weight::default(), | ||||||
| storage_deposit: Default::default(), | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| let code_hash = code_hash::<T>(&address); | ||||||
|
||||||
| let code_hash = code_hash::<T>(&address); | |
| let is_contract = <AccountInfo<T>>::is_contract(&address); |
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.
this does not tell you if it's a precompile though if you just check AccountInfo
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.
There is a separate check to catch precompiles
Uh oh!
There was an error while loading. Please reload this page.