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

Prevent addition overflow #1983

Merged
merged 3 commits into from
Sep 17, 2023
Merged

Prevent addition overflow #1983

merged 3 commits into from
Sep 17, 2023

Conversation

vicsn
Copy link
Collaborator

@vicsn vicsn commented Sep 13, 2023

Motivation

We should avoid panics, this PR adds checking if additions are allowed in snarkVM. I could not find problematic subtraction cases.

For this, we should agree on the attack surface. I can imagine the following attack vectors:

  • an attacker lets different nodes misinterpret a serialized object, which can happen if our flags are serialized last. Fortunately I haven't seen this anywhere.
  • an attacker's frontend lets an honest user serialize a giant object so their local node panics, I don't think this is a huge issue
  • an attacker lets an honest node deserialize a giant object so it panics. This might kill the network so we should prevent this. Nodes already seem to have a maximum message size, but as defense in depth I use saturating_add in serialized_size. Using checked_add there is tricky as it will change the serialized_size trait function signature all over the codebase, including in macros and for types which we know have a fixed size.

Test Plan

The existing tests should cover it.

Related PRs

Succeeding: https://github.com/AleoHQ/snarkVM/pull/1584
Compared to that PR, here we only care about fixing addition overflow and we are rebased on testnet3

@vicsn vicsn requested a review from howardwu September 13, 2023 14:49
@vicsn vicsn force-pushed the prevent_addition_overflow branch from 7b1d737 to bae18e6 Compare September 13, 2023 14:51
Copy link
Member

@howardwu howardwu left a comment

Choose a reason for hiding this comment

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

I think we can remove all usage of checked_add in these cases. It is unlikely we would wrap around a usize assuming a 32-bit or 64-bit architecture, because our SRS is only up to 2^27.

@howardwu
Copy link
Member

I am open to changing our usage of usize to a u64 to truly mitigate this issue as well.

@vicsn vicsn force-pushed the prevent_addition_overflow branch from bae18e6 to bf5619b Compare September 13, 2023 16:30
@vicsn
Copy link
Collaborator Author

vicsn commented Sep 13, 2023

Pushed and squashed the changes.

I am open to changing our usage of usize to a u64 to truly mitigate this issue as well.

For that topic, I will review and rebase this PR later: https://github.com/AleoHQ/snarkVM/pull/1499

@howardwu howardwu merged commit 9cd1042 into testnet3 Sep 17, 2023
@howardwu howardwu deleted the prevent_addition_overflow branch September 17, 2023 12:06
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.

2 participants