-
Notifications
You must be signed in to change notification settings - Fork 91
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
Precompile for balances ERC-20 #1731
Conversation
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.
Minor comments
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.
Looks good. Still got questions around the precompiles callable logic.
And we are missing the account code migration for the Erc20
precompile.
pub fn to_evm_address(account: &AccountId) -> H160 { | ||
// EVM AccountId20 addresses are right-padded to 32 bytes | ||
let mut bytes20 = [0; 20]; | ||
let account_32: [u8; 32] = account.clone().into(); | ||
bytes20.copy_from_slice(&account_32); | ||
H160::from(bytes20) | ||
} | ||
|
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.
Why the new method? Doesn't our current converter already provide means to go back to H160
. I am not the biggest fan of having this here if this is a duplicate and creates a second source of truth for conversions.
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.
Not sure exactly why, but PrecompileSetBuilder::user_addresses()
returns an AccountId
instead of H160
(internally, it transforms H160
into AccountId
).
So, we need this method to go back from AccountId
to H160
in chain_spec.rs
.
I really think it is taking more responsibility than it should, but I have no choice right now with the API they offer. Maybe I can open an issue regarding this in Moonbeam.
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.
Doesn't our current converter already provide means to go back to H160
Not for this direction, only for H160
-> AccountId
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.
In the router we are doing this conversion:
/// NOTE - the sender account ID provided here will be converted to an EVM
/// address via truncating. When the call is processed by the underlying EVM
/// pallet, this EVM address will be converted back into a substrate account
/// which will be charged for the transaction. This converted substrate
/// account is not the same as the original account.
pub fn do_send(&self, sender: T::AccountId, msg: Vec<u8>) -> DispatchResultWithPostInfo {
let sender_evm_address = H160::from_slice(&sender.as_ref()[0..20]);
and here we are doing it also. I would like to have the runtime_common::account_conversion::AccountConverter
to implement a trait Convert<AccountId32, H160>
and then use this converter as an associated type in theses pallets. Otherwise, we have multiple locations that do conversion.
No blocker. Just do not wanna create a foot-gun...
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.
Ok, I guess H160::from_slice(&sender.as_ref()[0..20])
should be extracted to a converter.
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.
I've been juggling traits in this commit: 0fb227c, and I've got to remove the conversion, so there is no issue (at least by now).
I think I've solved all comments @mustermeiszer |
# Recomended command: | ||
# cargo install taplo-cli --locked | ||
cargo install --git=https://github.com/tamasfe/taplo.git taplo-cli | ||
cargo install taplo-cli --locked |
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.
Required to fix taplo
CI
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.
If try-runtime
does show the migration of the ERC20 precompile then I am happy. Would love to see the logs thought, that we can be sure that T::PrecompilesType::h160_addresses()
works correctly.
I could also log the address in the utility method, but the method is infallible and very simple to work as expected in all cases. |
@mustermeiszer, merged but still open to add a log if after what I say you still consider we need it |
Fine for me if you are confident it works! |
Description
Fixes #1726
Changes and Descriptions
precompile-utils
, which is more type safety.balances-erc20
forbid-evm-reentrancy
featureDelegateCall
security issue