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

Allow COA.withdraw call to run when there is a possible rounding error #6877

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Jan 13, 2025

Closes #6856

In this case, we perform the withdrawal, by simply truncating the remainder that cannot fit in a Flow token vault.
When the attoFlow balance is too small to fit in a Flow vault, we panic with a dedicated error message.

@m-Peter
Copy link
Collaborator Author

m-Peter commented Jan 13, 2025

cc @sisyphusSmiling Can you take a lot at this approach, and the added test cases?

@codecov-commenter
Copy link

codecov-commenter commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 41.13%. Comparing base (b740fc0) to head (f0e23ff).

Files with missing lines Patch % Lines
fvm/evm/types/balance.go 0.00% 2 Missing ⚠️
utils/unittest/execution_state.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6877      +/-   ##
==========================================
+ Coverage   41.11%   41.13%   +0.01%     
==========================================
  Files        2116     2116              
  Lines      185749   185759      +10     
==========================================
+ Hits        76378    76413      +35     
+ Misses     102954   102935      -19     
+ Partials     6417     6411       -6     
Flag Coverage Δ
unittests 41.13% <80.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@m-Peter m-Peter force-pushed the mpeter/withdraw-balance-with-rounding branch 2 times, most recently from 9d80c61 to 1f5fbae Compare January 13, 2025 17:53
panic(types.ErrInvalidBalance)
}

if types.BalanceInAttFlowValidForFlowVault(amountValue.BigInt) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the name, I would expect true here to be valid. But it seems the check results in a panic so I'm probably misunderstanding the meaning of BalanceInAttFlowValidForFlowVault. What is being checked here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sisyphusSmiling My bad 😅 The name and the logic didn't match the intention.

I have updated it in f0e23ff.

This method basically checks if the requested withdrawal amount in attoFlow, can be represented in a FlowToken vault. The smallest allowed withdrawal amount is 1e^10 attoFlow, which is 1e^-8 Flow (or 0.00000001).

I have chosen to panic on such a case, as there's no reason to silently allow such cases.

@sisyphusSmiling
Copy link
Contributor

Thanks for the changes @m-Peter! The test cases and behavior look good to me, just left one question.

@m-Peter m-Peter force-pushed the mpeter/withdraw-balance-with-rounding branch from 1f5fbae to f0e23ff Compare January 14, 2025 11:32
@m-Peter m-Peter marked this pull request as ready for review January 14, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic on FLOW remainder in UInt to UFix64 conversion
3 participants