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

Perform fee padding in a larger bit width of integers #70

Merged
merged 12 commits into from
Feb 21, 2024
Merged

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Feb 20, 2024

What

Modify fee calculation to use 64-bit integers + tests for overflow.

Why

In situations where the resource fee padding causes the transaction fee to exceed its maximum value, it will overflow and create an invalid transaction, instead (i.e. one where the transaction fee is lower than the resource fee).

This code ensures that the padding is done in a higher bit width (i.e. with a u64) and then cast down to a u32.

Known limitations

@Shaptic Shaptic added the bug Something isn't working label Feb 20, 2024
@leighmcculloch
Copy link
Member

Would be great to add a test to catch the overflow too.

cmd/crates/soroban-rpc/src/txn.rs Outdated Show resolved Hide resolved
cmd/crates/soroban-rpc/src/txn.rs Outdated Show resolved Hide resolved
@Shaptic
Copy link
Contributor Author

Shaptic commented Feb 21, 2024

@dmkozh @leighmcculloch please have another look! The logic is still the same but it should be easier to read:

  • first, pick the larger of tx fee and base inclusion fee + min resource fee, ensuring this fits in a u32
  • then, bump that by 15% via the same int math
  • finally, cap that at u32_max

And the tests should reflect checks to these three steps.

@Shaptic Shaptic merged commit a3047e5 into main Feb 21, 2024
20 checks passed
@Shaptic Shaptic deleted the overflow-fixup branch February 21, 2024 02:19
@mn13
Copy link

mn13 commented Mar 12, 2024

Hey guys, could you please explain some details why fee should fit 32 bits?

Why: with soroban 20.3.1 I tried to call soroban contract install with a 61 kb wasm in testnet and got error: Fee was too large 4946582915. After some investigation I found that error occurs in https://github.com/stellar/soroban-rpc/blob/main/cmd/crates/soroban-rpc/src/txn.rs#L321 because classic_tx_fee + simulation.min_resource_fee = 4946582915 or 494.6582915 XLM.
Why values that exceed U32_MAX is not allowed for fee? Does it mean that there is no way to install wasm in mainnet with soroban-cli?

@2opremio
Copy link
Contributor

Hi @mn13 ! Thanks for reporting your problem. However, could you please create a separate ticket for it? Thanks!

@leighmcculloch
Copy link
Member

leighmcculloch commented Mar 12, 2024

The 32-bit size is limited by the protocol, so any change to the size is a protocol change for the Stellar network itself, and not just a change to the rpc, or another tool.

@mn13 The best place to discuss possible protocol changes is currently over on the stellar-protocol repo's discussion form, if you'd like to open an issue there: https://github.com/stellar/stellar-protocol/discussions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants