Skip to content
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

Fix check of EIP-3607 transaction for internal calls #1018

Merged
merged 3 commits into from
Mar 15, 2023
Merged

Fix check of EIP-3607 transaction for internal calls #1018

merged 3 commits into from
Mar 15, 2023

Conversation

koushiro
Copy link
Collaborator

Only check the restrictions of EIP-3607 if the source of the EVM operation is from an external transaction.

If the source of this EVM operation is from an internal call, like from eth_call or eth_estimateGas RPC, we will skip the checks for the EIP-3607.

related PR and discuss: #905

cc @tgmichel @nanocryk

@koushiro koushiro requested a review from sorpaas as a code owner March 14, 2023 07:32
Only check the restrictions of EIP-3607 if the source of the EVM operation
is from an external transaction.

If the source of this EVM operation is from an internal call, like from
`eth_call` or `eth_estimateGas` RPC, we  will skip the checks for the EIP-3607.
@koushiro
Copy link
Collaborator Author

@sorpaas PTAL

Comment on lines 133 to 150
// Only check the restrictions of EIP-3607 if the source of the EVM operation is from an external transaction.
// If the source of this EVM operation is from an internal call, like from `eth_call` or `eth_estimateGas` RPC,
// we will skip the checks for the EIP-3607.
if is_transactional {
// EIP-3607: https://eips.ethereum.org/EIPS/eip-3607
// Do not allow transactions for which `tx.sender` has any code deployed.
//
// We extend the principle of this EIP to also prevent `tx.sender` to be the address
// of a precompile. While mainnet Ethereum currently only has stateless precompiles,
// projects using Frontier can have stateful precompiles that can manage funds or
// which calls other contracts that expects this precompile address to be trustworthy.
if !<AccountCodes<T>>::get(source).is_empty() || precompiles.is_precompile(source) {
return Err(RunnerError {
error: Error::<T>::TransactionMustComeFromEOA,
weight,
});
}
}
Copy link
Collaborator Author

@koushiro koushiro Mar 14, 2023

Choose a reason for hiding this comment

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

Suggested change
// Only check the restrictions of EIP-3607 if the source of the EVM operation is from an external transaction.
// If the source of this EVM operation is from an internal call, like from `eth_call` or `eth_estimateGas` RPC,
// we will skip the checks for the EIP-3607.
if is_transactional {
// EIP-3607: https://eips.ethereum.org/EIPS/eip-3607
// Do not allow transactions for which `tx.sender` has any code deployed.
//
// We extend the principle of this EIP to also prevent `tx.sender` to be the address
// of a precompile. While mainnet Ethereum currently only has stateless precompiles,
// projects using Frontier can have stateful precompiles that can manage funds or
// which calls other contracts that expects this precompile address to be trustworthy.
if !<AccountCodes<T>>::get(source).is_empty() || precompiles.is_precompile(source) {
return Err(RunnerError {
error: Error::<T>::TransactionMustComeFromEOA,
weight,
});
}
}
// Only check the restrictions of EIP-3607 if the source of the EVM operation is from an external transaction.
// If the source of this EVM operation is from an internal call, like from `eth_call` or `eth_estimateGas` RPC,
// we will skip the checks for the EIP-3607.
//
// EIP-3607: https://eips.ethereum.org/EIPS/eip-3607
// Do not allow transactions for which `tx.sender` has any code deployed.
//
// We extend the principle of this EIP to also prevent `tx.sender` to be the address
// of a precompile. While mainnet Ethereum currently only has stateless precompiles,
// projects using Frontier can have stateful precompiles that can manage funds or
// which calls other contracts that expects this precompile address to be trustworthy.
if is_transactional && !<AccountCodes<T>>::get(source).is_empty() || precompiles.is_precompile(source) {
return Err(RunnerError {
error: Error::<T>::TransactionMustComeFromEOA,
weight,
});
}

Copy link
Collaborator Author

@koushiro koushiro Mar 14, 2023

Choose a reason for hiding this comment

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

It seems that the moonbeam team have extended the principle of EIP-3607, should I change it to something like this? @tgmichel @nanocryk

If the precompile is stateful, maybe calling eth_call with this stateful precompile will cause some problems? I'm not sure 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question, I'd say in non-transactional context we don't care, @nanocryk to confirm

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good to me

@nanocryk so calling non-transactional call with stateful precompiles as the source will be fine, right?

Copy link
Member

Choose a reason for hiding this comment

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

Please apply the other suggestions and change this to a single if statement.

Copy link
Contributor

@tgmichel tgmichel left a comment

Choose a reason for hiding this comment

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

Indeed this was missing, thank you @koushiro! A test for it would be great.

@koushiro
Copy link
Collaborator Author

Once this PR is merged, @sorpaas can you cherry-pick it to the polkadot-v0.9.36, polkadot-v0.9.37 and polkadot-v0.9.38 branches?
At the same time, downstream developers who have used these branches can upgrade the runtime to apply the changes .

@koushiro koushiro changed the title Improve check of EIP-3607 Fix check of EIP-3607 transaction for internal calls Mar 14, 2023
Copy link
Member

@sorpaas sorpaas left a comment

Choose a reason for hiding this comment

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

LGTM otherwise.

Comment on lines 133 to 150
// Only check the restrictions of EIP-3607 if the source of the EVM operation is from an external transaction.
// If the source of this EVM operation is from an internal call, like from `eth_call` or `eth_estimateGas` RPC,
// we will skip the checks for the EIP-3607.
if is_transactional {
// EIP-3607: https://eips.ethereum.org/EIPS/eip-3607
// Do not allow transactions for which `tx.sender` has any code deployed.
//
// We extend the principle of this EIP to also prevent `tx.sender` to be the address
// of a precompile. While mainnet Ethereum currently only has stateless precompiles,
// projects using Frontier can have stateful precompiles that can manage funds or
// which calls other contracts that expects this precompile address to be trustworthy.
if !<AccountCodes<T>>::get(source).is_empty() || precompiles.is_precompile(source) {
return Err(RunnerError {
error: Error::<T>::TransactionMustComeFromEOA,
weight,
});
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please apply the other suggestions and change this to a single if statement.

@koushiro koushiro requested a review from sorpaas March 14, 2023 15:45
@sorpaas sorpaas merged commit 8a5492f into polkadot-evm:master Mar 15, 2023
@koushiro koushiro deleted the improve-eip3607-check branch March 15, 2023 13:20
Dinonard pushed a commit to AstarNetwork/frontier that referenced this pull request Mar 22, 2023
* Improve check of EIP-3607

Only check the restrictions of EIP-3607 if the source of the EVM operation
is from an external transaction.

If the source of this EVM operation is from an internal call, like from
`eth_call` or `eth_estimateGas` RPC, we  will skip the checks for the EIP-3607.

* fix eip-3607 tests

* apply review suggtions
tgmichel pushed a commit to moonbeam-foundation/frontier that referenced this pull request Apr 12, 2023
* Improve check of EIP-3607

Only check the restrictions of EIP-3607 if the source of the EVM operation
is from an external transaction.

If the source of this EVM operation is from an internal call, like from
`eth_call` or `eth_estimateGas` RPC, we  will skip the checks for the EIP-3607.

* fix eip-3607 tests

* apply review suggtions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants