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

DEV-7. Balance pool: optimizations, redundant logic removed. ValidDelta bug fix #39

Merged
merged 6 commits into from
Jun 2, 2024

Conversation

Bromel777
Copy link
Collaborator

@Bromel777 Bromel777 commented Apr 3, 2024

Optimizations

To optimize cpu and memory costs of the swap action validation in the main PBalancePool.hs contract we made the following changes:

  • The value of the constant pDen is reduced from 10 to 5 to decrease number of exponentiations and required number of significant figures in the values ​​of the involved state variables;
  • The length of variable values ​​is now pre-calculated off-chain and checked for correctness inside the pool contract using the checkLength function, main additions here are:
    • An invariantLength field is added into the BalancePoolConfig to explicitly pass the number of significant figures of the invariant value;
    • A lengths field is added the BalancePoolRedeemer to explicitly pass the number of significant figures of the pool's state variables and off-chain calculated values, namely: gXgYLength, newXBalanceLength, newGXLength, newTxPowLength, newTxPowWeightLength, leftSideLengthX, rightSideLengthX, newYBalanceLength, newGYLength, newTyPowLength, newTyPowWeightLength, leftSideLengthY, rightSideLengthY;
    • Implemented a more efficient exponentiation function pow10 for calculating exponents with pre-known power values, i.e. calculated from lengths.

Bug fixes

  • The validDelta predicate inside the verifyTExpEquality function is now calculated taking into account the error from rounding calculations (in consistency with newInvariantIsCorrect, correctTokenError and validGEquality predicates).
  • Verification of the valid invariant value is added into the validDepositRedeemAllTokens function to prevent a possible break of the pool due to an incorrect invariant value saved in the datum after malicious redeem/deposit actions.

Copy link

linear bot commented Apr 3, 2024

@Bromel777 Bromel777 changed the title wip DEV-7. Balance pool: optimizations, redundant logic removed Apr 15, 2024
@Bromel777 Bromel777 force-pushed the dev-7-debug branch 3 times, most recently from f76aea5 to 2fb75ba Compare April 15, 2024 13:26
@Bromel777 Bromel777 changed the title DEV-7. Balance pool: optimizations, redundant logic removed DEV-7. Balance pool: optimizations, redundant logic removed. ValidDelta bug fix Apr 15, 2024
@AOranov AOranov self-requested a review April 15, 2024 13:52
@Bromel777
Copy link
Collaborator Author

waiting audit complete before merge

oskin1 and others added 2 commits April 24, 2024 12:55
…c-flow-in-depositredeem-contracts

Dev 567. Fix incorrect logic flow in deposit, redeem contracts
* New approach for balance pools

* remove invariant

* fix balance contract
@Bromel777 Bromel777 merged commit a90d54c into dev-7-weighted-pools-cleanup Jun 2, 2024
1 check passed
Bromel777 added a commit that referenced this pull request Jun 2, 2024
* Balance Pool. Swap, Deposit, Redeem, DepositSingleAsset operations

* cleanup

* fix treasury validation

* Redeem & Swap for random weights and fees fixes.

* Fixes and looped test example fixed.

* DEV-7. Balance pool. Optimizations (#36)

* DEV-7. Balance pools. Deposit, Redeem balance orders contracts (#30)

* add daoBalanceMintPolicyValidator

* DEV-7. Balance pool: optimizations, redundant logic removed. ValidDelta bug fix (#39)

* Balance pool. Optimizations, redundant logic removed, validDelta bug fix

* update balanceFeeSwitch

* remove redundant variable  in ppow10

* Fix incorrect flow in deposit, redeem contracts

* Balance pool. New approach (#43)

* New approach for balance pools

* remove invariant

* fix balance contract

---------

Co-authored-by: Ilya <[email protected]>

---------

Co-authored-by: AOranov <[email protected]>
Co-authored-by: Alex Oranov <[email protected]>
Co-authored-by: Ilya <[email protected]>
AOranov added a commit that referenced this pull request Oct 2, 2024
* Balance Pool. Swap, Deposit, Redeem, DepositSingleAsset operations

* cleanup

* fix treasury validation

* Redeem & Swap for random weights and fees fixes.

* Fixes and looped test example fixed.

* DEV-7. Balance pool. Optimizations (#36)

* DEV-7. Balance pools. Deposit, Redeem balance orders contracts (#30)

* add daoBalanceMintPolicyValidator

* DEV-7. Balance pool: optimizations, redundant logic removed. ValidDelta bug fix (#39)

* Balance pool. Optimizations, redundant logic removed, validDelta bug fix

* update balanceFeeSwitch

* remove redundant variable  in ppow10

* Fix incorrect flow in deposit, redeem contracts

* Balance pool. New approach (#43)

* New approach for balance pools

* remove invariant

* fix balance contract

---------

Co-authored-by: Ilya <[email protected]>

---------

Co-authored-by: AOranov <[email protected]>
Co-authored-by: Alex Oranov <[email protected]>
Co-authored-by: Ilya <[email protected]>
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