Skip to content

Base precompile code between connectors#73

Merged
mfornet merged 3 commits intodevelopfrom
connectors
May 12, 2021
Merged

Base precompile code between connectors#73
mfornet merged 3 commits intodevelopfrom
connectors

Conversation

@mfornet
Copy link
Copy Markdown
Contributor

@mfornet mfornet commented May 11, 2021

Add precompiles, so eth-connector and erc20-connector can work from it.

@mfornet mfornet requested review from mrLSD and sept-en May 11, 2021 23:19
Copy link
Copy Markdown
Contributor

@sept-en sept-en left a comment

Choose a reason for hiding this comment

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

Added some comments (we already discussed some of them on the call with you), but I'm fine if we don't address them in the current PR to speed up the process. Noted here just for a future reference if this won't be fixed right now.

Looks good to me, great job!

Comment thread src/precompiles/mod.rs Outdated
Comment thread src/precompiles/native.rs Outdated
String::from_utf8(sdk::current_account_id()).unwrap(),
crate::prelude::format!(
r#"{{"receiver_id": "{}", "amount": "{}", "memo": null}}"#,
String::from_utf8(input.to_vec()).unwrap(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please, add a check to validate the recipient_account_id and fail if any other data is provided (as we've discussed).

Comment thread src/precompiles/native.rs Outdated
let mut input_mut = input;
let amount = U256::from_big_endian(&input_mut[..32]).as_u128();
input_mut = &input_mut[32..];
let receiver_account_id: AccountId = String::from_utf8(input_mut.to_vec()).unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same thing about the receiver_account_id validation

Comment thread src/precompiles/native.rs
// Input slice format:
// eth_recipient (20 bytes) - the address of recipient which will receive ETH on Ethereum

let eth_recipient: String = hex::encode(input);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please, check the input is exactly 20 bytes long.

Comment thread src/sdk.rs Outdated
Comment on lines +281 to +299
#[allow(dead_code)]
pub fn signer_account_id() -> Vec<u8> {
unsafe {
exports::signer_account_id(1);
let bytes: Vec<u8> = vec![0u8; exports::register_len(1) as usize];
exports::read_register(1, bytes.as_ptr() as *const u64 as u64);
bytes
}
}

#[allow(dead_code)]
pub fn signer_account_pk() -> Vec<u8> {
unsafe {
exports::signer_account_pk(1);
let bytes: Vec<u8> = vec![0u8; exports::register_len(1) as usize];
exports::read_register(1, bytes.as_ptr() as *const u64 as u64);
bytes
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need these in the current PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We dont!

Comment thread src/types.rs
pub type RawH256 = [u8; 32]; // Unformatted binary data of fixed length.
pub type Gas = u64;
pub type Balance = u128;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just notice that we have the same type et eth-connector

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let's have it here since they are common to both

@mfornet mfornet requested review from mrLSD and sept-en May 12, 2021 14:32
@mfornet mfornet marked this pull request as ready for review May 12, 2021 14:32
@mfornet mfornet requested a review from artob as a code owner May 12, 2021 14:32
Comment thread src/precompiles/native.rs Outdated
Comment on lines +106 to +108
// TODO: Which is the expected result in case of failure
// Stopped vs Returned vs Suicided
return Ok((ExitSucceed::Stopped, Vec::new(), 0));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What is the expected PrecompileResult if it should fail?

Should we return a flag instead 1 on success, and 0 on failure?

return Ok((ExitSucceed::Returned, [flag].to_vec(), 0));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From what I remember using sha precompile, when you called it, the result is stored in the range from [0, 32]
However, it also returns a boolean value, whether it succeeded or not. How can I return this boolean value from here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should use ExitError for that purpose

Comment thread src/precompiles/native.rs Outdated
/// Get the current nep141 token associated with the current erc20 token.
/// This will fail is none is associated.
fn get_nep141_from_erc20(_erc20_token: &[u8]) -> AccountId {
// TODO:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where it will TODO? If not planned now we should create an issue.

Copy link
Copy Markdown
Contributor Author

@mfornet mfornet May 12, 2021

Choose a reason for hiding this comment

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

it is done in pr #51 , didnt remove for it to compile

Comment thread src/precompiles/native.rs Outdated
),
)
} else {
// TODO: Which is the expected result in case of failure
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe for that cases, we can add log message?

@artob
Copy link
Copy Markdown
Contributor

artob commented May 12, 2021

@mfornet Is this ready to end up on chain on MainNet tomorrow? If not, please retarget it at the develop branch instead of master.

@artob artob added the C-enhancement Category: New feature or request label May 12, 2021
@mfornet mfornet changed the base branch from master to develop May 12, 2021 22:22
@mfornet mfornet merged commit 37c8334 into develop May 12, 2021
@mfornet mfornet deleted the connectors branch May 12, 2021 22:22
joshuajbouw pushed a commit that referenced this pull request May 18, 2021
* Base precompile code between connectors

* Handle errors and validate input

* Use proper result
mfornet added a commit that referenced this pull request Jun 4, 2021
* Base precompile code between connectors (#73)

* Base precompile code between connectors

* Handle errors and validate input

* Use proper result

* Document `aurora encode-address` usage.

* Cache cargo artifacts between CI runs. (#92)

* Address comments from audit. (#86)

* Validate register length in `read_input_arr20()`
* Only read register length in `Engine::get_code_size`
* Add `read_input_borsh()`
* Ensure `method.args.len() == args_decoded.len()`
* Ensure register size is 8 in `read_u64`
* Use constant to specify the register ID used in `read_input()`

* Reduce size of `cargo cache` in CI. (#95)

* Define a `Wei` newtype for balances. (#96)

* Fix evm-bully builds after recent refactoring. (#100)

* Refactor `Engine::get_state` to return a `Result`. (#99)

* Ensure that `Cargo.lock` in the repo is valid. (#101)

* Remove unneeded nightly feature. (#102)

* Implement BC generational storage.

* fix address input

* remove note

* put key on the end of the storage key

* remove pub from methods

* Dispatch precompiles on the full address. (#107)

* Support state migration on upgrade. (#103)

* Implement the ETH connector. (#59)

* Move when to call `set_generation`

* Fix arg

Co-authored-by: Marcelo Fornet <mfornet94@gmail.com>
Co-authored-by: Arto Bendiken <arto@aurora.dev>
Co-authored-by: Michael Birch <michael@near.org>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Evgeny Ukhanov <mrlsd@ya.ru>
mfornet added a commit that referenced this pull request Jun 10, 2021
* Add tests for state check after selfdestruct

* Aurora runner tracks storage usage to avoid underflow when storage is released in future transactions (#85)

* Implement generational storage (#87)

* Base precompile code between connectors (#73)

* Base precompile code between connectors

* Handle errors and validate input

* Use proper result

* Document `aurora encode-address` usage.

* Cache cargo artifacts between CI runs. (#92)

* Address comments from audit. (#86)

* Validate register length in `read_input_arr20()`
* Only read register length in `Engine::get_code_size`
* Add `read_input_borsh()`
* Ensure `method.args.len() == args_decoded.len()`
* Ensure register size is 8 in `read_u64`
* Use constant to specify the register ID used in `read_input()`

* Reduce size of `cargo cache` in CI. (#95)

* Define a `Wei` newtype for balances. (#96)

* Fix evm-bully builds after recent refactoring. (#100)

* Refactor `Engine::get_state` to return a `Result`. (#99)

* Ensure that `Cargo.lock` in the repo is valid. (#101)

* Remove unneeded nightly feature. (#102)

* Implement BC generational storage.

* fix address input

* remove note

* put key on the end of the storage key

* remove pub from methods

* Dispatch precompiles on the full address. (#107)

* Support state migration on upgrade. (#103)

* Implement the ETH connector. (#59)

* Move when to call `set_generation`

* Fix arg

Co-authored-by: Marcelo Fornet <mfornet94@gmail.com>
Co-authored-by: Arto Bendiken <arto@aurora.dev>
Co-authored-by: Michael Birch <michael@near.org>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Evgeny Ukhanov <mrlsd@ya.ru>

* Fix layout of the key

* Fix all tests (don't wipe the storage all the time)

* Use correct generation in writing storage

* Remove unnecessary references

Co-authored-by: Michael Birch <michael@near.org>
Co-authored-by: Joshua J. Bouw <dev@joshuajbouw.com>
Co-authored-by: Arto Bendiken <arto@aurora.dev>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Evgeny Ukhanov <mrlsd@ya.ru>
Co-authored-by: Michael Birch <michael.birch@aurora.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement Category: New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants