aurora-is-near / aurora-engine

⚙️ Aurora Engine implements an Ethereum Virtual Machine (EVM) on the NEAR Protocol.
https://doc.aurora.dev/develop/compat/evm
330 stars 82 forks source link

fix: return error if `amount` is greater than `2^128` #681

Closed 0x3bfc closed 1 year ago

0x3bfc commented 1 year ago

Description

The exitToNear and exitToEthereum precompiles may panic if the input amount is greater than 2^128 when cast from a U256 to u128 .

aleksuss commented 1 year ago

@0x3bfc for writing tests for this I'd suggest to create helper function like this:

fn validate_amount(amount: U256) -> Result<(), ExitError> {
    if amount > U256::from(u128::MAX) {
        return Err(ExitError::Other(Cow::from("ERR_INVALID_AMOUNT")));
    }

    Ok(())
}

And then you'll be able to cover the function with tests.

joshuajbouw commented 1 year ago

Before I merge it, you need to sign all the commits with your @aurora.dev e-mail. Really important.

Aurora-ClickUp commented 1 year ago

Task linked: CU-863g0gc9w AUR-01 Reachable Panic Converting Balances to u128