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

Audit Fix: Fix coins.add usage during deposit #342

Merged
merged 3 commits into from
Nov 13, 2023

Conversation

jcompagni10
Copy link
Contributor

@jcompagni10 jcompagni10 commented Nov 1, 2023

Every sdk.Coin.Add happening in DepositCore results in multiple traversals over all coins
in sharesIssued , and also involves allocation of additional data structures, thus resulting in quadratic
scaling of the DepositCore runtime (because it invokes sdk.Coins Add() for each issued share).
As a fix, we instead aggregate the coins as a slice and then perform aggregation and validation only once.
We also move coin sending logic to the end of the deposit function for further efficiency.

Julian Compagni Portis added 2 commits November 1, 2023 15:34
every sdk.Coin.Add happening in DepositCore results in multiple traversals over all coins
in sharesIssued , and also involves allocation of additional data structures, thus resulting in quadratic
scaling of the DepositCore runtime (because it invokes sdk.Coins Add() for each issued share).
Much better gas efficiency since we don't need to perform duplicate lookups for
each share issuance

Also add additional check for duplicate deposits. This should exist regardless
but also required for share math to work if we aren't issuing shares within the
deposit loop
Copy link
Collaborator

@pr0n00gler pr0n00gler left a comment

Choose a reason for hiding this comment

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

LGTM, but please attach a testrun

@jcompagni10
Copy link
Contributor Author

jcompagni10 commented Nov 9, 2023

@pr0n00gler pr0n00gler merged commit d182738 into merge_duality_neutron Nov 13, 2023
5 of 6 checks passed
@pr0n00gler pr0n00gler deleted the fix_coin_add branch May 9, 2024 18:15
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.

3 participants