Delayed Swap due to Numeric Underflow Bug by using Tron's triggerSmartContract Method
Yesterday, @steemit-market sent 20 STEEM to @steem2usdt because he/she wants to swap to USDT on Tron Blockchain (TRC-20), the status was showing "Pending Sent" in the Steem to USDT Swap Tool.
This isn't normal - I took a look and investigated, and found out the invoke of API triggerSmartContract fails and says "Numeric Underflow" (Exception) see below
const tx = await tronWeb.transactionBuilder.triggerSmartContract(
CONTRACT, 'transfer(address,uint256)', options,
[{
type: 'address',
value: toAddress
}, {
type: 'uint256',
value: parseFloat(amount * 1000000)
}],
tronWeb.address.toHex(fromAddress)
);
The triggerSmartContract method is used to trigger a smart contract on Tron Blockchain e.g. TRC-20. The TRC-20 USDT is a smart contract aka token, and we need to trigger the contract's method transfer in order to send USDT tokens from one address to another.
The USDT transaction was not showing on the tronscan (which is a Tron Blockchain Explorer) so it means the transaction fails locally and not yet pushed to the chain.
The problem is that the amount due to floating precision cannot be safely represented in the current type. The "parseFloat" function is causing the problem (Numeric Underflow Exception) here. After changing it to parseInt, the fund was safely sent out to the destination wallet address (Tron).
parseFloat method returns a float and parseInt returns a whole of integer. This is absolutely fine here because for example: 4.184999999 times 1000000 to convert to the SUN unit is 4184999.9999 which causes the underflow issue - but if we use parseInt, it will be 4184999 - or we can use the Math.round which rounds up to 41185000 and that is acceptable as well.
Robustness of the Swap Tool
This incident shows the correctness of the tool - only mark the status to "Sent" when the fund has been sent. The transactions on the steem blockchain are immutable database records which we can easily scan or lookup, so are the ones on the Tron Blockchain.
--EOF (The Ultimate Computing & Technology Blog) --
Blog: Delayed Swap due to Numeric Underflow Bug by using Tron's triggerSmartContract Method
Steem to the Moon!
- You can swap the STEEM/SBD to USDT (TRC-20) via Steem2USDT!
- Register a free STEEM account at SteemYY!
!ask is there any steem to usdt (TRC-20) swap tool out there?
At this time, there are no swap tools available for exchanging Steem to TRC-20-based USDT. However, there are several platforms that allow users to buy and sell Steem using a variety of other major cryptocurrencies.
command: !ask is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!. !ask is currently based on ChatGPT-3.5
!price
1 STEEM Power: 1768.146 VESTS
steem_to_sbd: 0.2521021236773376
sbd_to_steem: 3.9666464741085945
sbd_median_price: 0.2521021236773376
steem_per_mvests: 565.5656614053125
vests_to_sp: 0.000565564201227796
sp_to_vests: 1768.1412932942374
ticker.latest: 0.07894736842105263
ticker.lowest_ask: 0.08172222802800710
ticker.higest_bid: 0.08163931749530574
ticker.steem_volume: 896.903 STEEM
ticker.sbd_volume: 73.412 SBD
Time: 2023-04-29T12:59:38.770Z
command: !price is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!
!info
Blockchain Version: 0.23.0
Last Irreversible Block: 74183701
Head Block Number: 74183716
Total Steem Accounts: 3537854
Feed Price: 0.252 USD
Market Price: 0.082 USD
Hardfork Version: 0.23.0
1 STEEM Power: 1768.146 VESTS
Time: 2023-04-29T13:02:13
command: !info is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!
!ask Who is the richest man on the earth?
As of March 2021, the world's richest man is Jeff Bezos, the founder and former CEO of Amazon. He has an estimated net worth of $182 billion.
command: !ask is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!. !ask is currently based on ChatGPT-3.5
Thank you friend! Thanks for the explanations and great service!