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: return error if signature len does not eq 65 #717

Merged
merged 11 commits into from
Mar 21, 2023

Conversation

0x3bfc
Copy link
Contributor

@0x3bfc 0x3bfc commented Mar 6, 2023

Description

the ecrecover precompile panics if provided signature length is not exactly 65.

Copy link
Member

@birchmd birchmd left a comment

Choose a reason for hiding this comment

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

While we're looking at ecrecover. It might be good to expand our integration tests for it to cover this case as well. I took a look at geth and extra bytes after a valid signature are simply ignored:

Valid signature:

go-ethereum$ ./build/bin/evm \
    --input 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c000000000000000000000000000000000000000000000000000000000000001c73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75feeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549 \
    --receiver 0x0000000000000000000000000000000000000001 \
    run
0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b

Extra bytes:

go-ethereum$ ./build/bin/evm \
    --input 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c000000000000000000000000000000000000000000000000000000000000001c73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75feeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549aabbccddeeff \
    --receiver 0x0000000000000000000000000000000000000001 \
    run
0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b

I think our implementation does this properly too, but's good to include a test for it just in case.

engine-precompiles/src/secp256k1.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@joshuajbouw joshuajbouw left a comment

Choose a reason for hiding this comment

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

As @birchmd noted above, this shouldn't be added until there is test. Unit test is fine enough.

@0x3bfc
Copy link
Contributor Author

0x3bfc commented Mar 9, 2023

As @birchmd noted above, this shouldn't be added until there is test. Unit test is fine enough.

Unit test won't work as it will lead to a compile time error.

@joshuajbouw
Copy link
Contributor

As @birchmd noted above, this shouldn't be added until there is test. Unit test is fine enough.

Unit test won't work as it will lead to a compile time error.

Why so?

@0x3bfc 0x3bfc requested a review from vimpunk as a code owner March 13, 2023 08:15
@Aurora-ClickUp
Copy link

@Aurora-ClickUp
Copy link

@0x3bfc 0x3bfc requested a review from hskang9 as a code owner March 16, 2023 11:36
@0x3bfc 0x3bfc requested a review from joshuajbouw March 16, 2023 11:36
Co-authored-by: Oleksandr Anyshchenko <[email protected]>
@joshuajbouw joshuajbouw added this pull request to the merge queue Mar 21, 2023
@joshuajbouw joshuajbouw merged commit 30868f9 into develop Mar 21, 2023
@joshuajbouw joshuajbouw deleted the fix/0x3bfc/audit-aur-23 branch March 21, 2023 11:58
lempire123 pushed a commit that referenced this pull request Apr 5, 2023
* fix: return error if signature len does not eq `65`

* fix: avoid magic numbers

* fix: tests

* fix: return error on size check in compile time

* chore: remove outdated code

* chore: update tests

* fix: update test outputs

* Update engine-precompiles/src/secp256k1.rs

Co-authored-by: Oleksandr Anyshchenko <[email protected]>

---------

Co-authored-by: Oleksandr Anyshchenko <[email protected]>
@joshuajbouw joshuajbouw mentioned this pull request Apr 5, 2023
birchmd pushed a commit that referenced this pull request Apr 5, 2023
* fix: return error if signature len does not eq `65`

* fix: avoid magic numbers

* fix: tests

* fix: return error on size check in compile time

* chore: remove outdated code

* chore: update tests

* fix: update test outputs

* Update engine-precompiles/src/secp256k1.rs

Co-authored-by: Oleksandr Anyshchenko <[email protected]>

---------

Co-authored-by: Oleksandr Anyshchenko <[email protected]>
joshuajbouw added a commit that referenced this pull request Apr 5, 2023
## [2.9.0] 2023-04-05

### Added

- Enabled XCC for mainnet release by [@birchmd]. ([#694])
- Added `set_owner` contract method which sets the owner of the contract
by [@hskang9]. ([#690])
- New variant of submit function `submit_with_args` which accepts
additional arguments along with the transaction such as the max gas
price a user is ready to pay by [@aleksuss]. ([#696])
- Added the ability to create and fund XCC sub-accounts from external
NEAR accounts by [@birchmd]. ([#735])

### Changes

- Replaced `rjson` with `serde_json` by [@aleksuss]. ([#677])
- Changed owner intended contract methods to now require owner or the
contract itself by [@hskang9]. ([#676])

### Fixes

- Fixed nonce incorrectly being incremented on an out of fund failure by
[@joshuajbouw]. ([#671])
- Fixed a check in promise results before executing cross contract calls
(XCC) callbacks by [@birchmd]. ([#693])
- Fixed a reachable panic in `receive_erc20_tokens` by [@0x3bfc].
([#709])
- Fixed a lack of minimum size checks when instantiating a new `EthGas`
object by [@lempire123]. ([#722])
- Fixed a lack of division by 0 checks in `EthGas::Div()` by
[@lempire123]. ([#718])
- Fixed the validation of the return of `exports:storage_remove` by
[@0x3bfc]. ([#712])
- Fixed missing account validations of NEAR account IDs by [@0x3bfc].
([#703])
- Fixed a reachable panic in the `exitToNear` and `exitToEthereum`
precompiles if the input amount is greater than 1^128 when cast from a
`U256` to `u128` by [@0x3bfc]. ([#681])
- Fixed a reachable panic in `modExp` due to arithmetic overflow by
[@0x3bfc]. ([#688])
- Fixed the ability attaching values to Aurora specific precompiles,
this no longer is possible, by [@0x3bfc]. ([#714])
- Fixed a return error if an ecrecover signature length is not exactly
65 by [@0x3bfc]. ([#717])
- Fixed size checks on input array passed to `exitToNear` and
`exitToEthereum` precompiles by [@0x3bfc]. ([#684])
- Fixed missing gas costs in `exitToNear` and `exitToEthereum`
precompiles by [@lempire123]. ([#687])
- Fixed a reachable panic due to out of memory in the `modExp`
precompile by [@0x3bfc]. ([#689])
- Fixed an assurance that the `sender_id` has a balance greater than the
amount in `ft_transfer_call` by [@0x3bfc]. ([#708])
- Fixed returning `0x` when a length cannot be cast as `usize` instead
of returning an error in the `modExp` precompile by [@birchmd]. ([#737])
- Miscellaneous minor fixes by [@0x3bfc]. ([#738])

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Leandro Casuso Montero <[email protected]>
Co-authored-by: Michael Birch <[email protected]>
Co-authored-by: Alexey Lapitsky <[email protected]>
Co-authored-by: Oleksandr Anyshchenko <[email protected]>
Co-authored-by: Alexey Lapitsky <[email protected]>
Co-authored-by: Hyungsuk Kang <[email protected]>
Co-authored-by: Ahmed Ali <[email protected]>
Co-authored-by: lempire123 <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

6 participants