Skip to content

Wrong weiValue calculation in DropERC20_Claim method - multiplies by wei amount instead of token amount #235

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

Closed
DebabratDas1 opened this issue Apr 28, 2025 · 3 comments
Assignees
Labels
bug Something isn't working .NET SDK

Comments

@DebabratDas1
Copy link

In the method DropERC20_Claim, the weiValue is incorrectly calculated when the claim currency is native (e.g., ETH).
Currently, it multiplies the amount in wei by pricePerToken, instead of multiplying the amount of tokens (as a count) by the pricePerToken.

Thus, the gas transaction sends an extremely large amount of native currency, much higher than intended.

📋 Current Behavior (Bug)
Inside DropERC20_Claim:

BigInteger bigInteger = BigInteger.Parse(amount.ToWei()).AdjustDecimals(18, toDecimals);
BigInteger weiValue = ((activeClaimCondition.Currency == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") ? (bigInteger * activeClaimCondition.PricePerToken) : BigInteger.Zero);

The bigInteger represents amount in wei, not token count.
Multiplying bigInteger (already in wei) by pricePerToken causes wei overflows.

Example:

Price per token: 1 ETH (1e18 wei)
User claims 2 tokens
amount = "2"
amount.ToWei() = 2 × 10¹⁸ wei
Calculation done: 2 × 10¹⁸ × 1 × 10¹⁸ = 2 × 10³⁶ wei (Wrong!)
Instead, should send 2 × 1 ETH = 2 ETH (2 × 10¹⁸ wei).

✅ Expected Behavior

Multiply the token amount (count), not the wei value, by the pricePerToken.
The calculation should be:

BigInteger tokenAmount = BigInteger.Parse(amount);BigInteger weiValue = (activeClaimCondition.Currency == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") ? (tokenAmount * activeClaimCondition.PricePerToken) : BigInteger.Zero;

🧪 Steps to Reproduce

Set up a DropERC20 contract with a claim price of 1 ETH per token.
Call DropERC20_Claim requesting 2 tokens.
Observe that the transaction tries to send 2e36 wei instead of 2e18 wei.

💻 Environment
Thirdweb SDK Version: [v5.19.2]
Platform: [Unity / WebGL / Android / iOS]
Blockchain: [Ethereum / Polygon / Soneium / etc.]

Copy link

linear bot commented Apr 28, 2025

@0xFirekeeper 0xFirekeeper self-assigned this Apr 28, 2025
@0xFirekeeper 0xFirekeeper added the .NET SDK label Apr 28, 2025 — with Linear
Copy link
Member

Thank you for the detailed report! This indeed looks like a bug, will do a pass on all functions with related behavior and make a release by tomorrow. Much appreciated 🙂

@0xFirekeeper 0xFirekeeper added the bug Something isn't working label Apr 28, 2025 — with Linear
@0xFirekeeper
Copy link
Member

Fixed here, thank you!
https://github.com/thirdweb-dev/unity/releases/tag/v5.20.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET SDK
Projects
None yet
Development

No branches or pull requests

2 participants