Delayed Swap because of Numeric Underflow Bug by utilizing Tron’s triggerSmartContract Technique

[ad_1]

Yesterday, @steemit-market despatched 20 STEEM to @steem2usdt as a result of he/she needs to swap to USDT on Tron Blockchain (TRC-20), the standing was displaying “Pending Despatched” within the Steem to USDT Swap Software.

This isn’t regular – I took a glance and investigated, and discovered the invoke of API triggerSmartContract fails and says “Numeric Underflow” (Exception) see under

1
2
3
4
5
6
7
8
9
10
11
const tx = await tronWeb.transactionBuilder.triggerSmartContract(
    CONTRACT, 'switch(deal with,uint256)', choices,
    [{
        type: 'address',
        value: toAddress
    }, {
        type: 'uint256',
        value: parseFloat(amount * 1000000)
    }],
    tronWeb.deal with.toHex(fromAddress)
);

const tx = await tronWeb.transactionBuilder.triggerSmartContract(
    CONTRACT, 'switch(deal with,uint256)', choices,
    [{
        type: 'address',
        value: toAddress
    }, {
        type: 'uint256',
        value: parseFloat(amount * 1000000)
    }],
    tronWeb.deal with.toHex(fromAddress)
);

The triggerSmartContract technique is used to set off a sensible contract on Tron Blockchain e.g. TRC-20. The TRC-20 USDT is a brilliant contract aka token, and we have to set off the contract’s technique switch with a purpose to ship USDT tokens from one deal with to a different.

The USDT transaction was not displaying on the tronscan (which is a Tron Blockchain Explorer) so it means the transaction fails domestically and never but pushed to the chain.

The issue is that the quantity because of floating precision can’t be safely represented within the present sort. The “parseFloat” operate is inflicting the issue (Numeric Underflow Exception) right here. After altering it to parseInt, the fund was safely despatched out to the vacation spot pockets deal with (Tron).

parseFloat technique returns a float and parseInt returns a complete of integer. That is completely effective right here as a result of for instance: 4.184999999 instances 1000000 to transform to the SUN unit is 4184999.9999 which causes the underflow subject – but when we use parseInt, will probably be 4184999 – or we are able to use the Math.spherical which rounds as much as 41185000 and that’s acceptable as effectively.

Robustness of the Swap Software

This incident exhibits the correctness of the device – solely mark the standing to “Despatched” when the fund has been despatched. The transactions on the steem blockchain are immutable database information which we are able to simply scan or lookup, so are those on the Tron Blockchain.

Steem to the Moon!

  • You possibly can swap the STEEM/SBD to USDT (TRC-20) through Steem2USDT!
  • Register a free STEEM account at SteemYY!

–EOF (The Final Computing & Expertise Weblog) —

GD Star Ranking
loading…


559 phrases
Final Submit: Instructing Children Programming – Minimal Quantity of Time to Fill Cups (Grasping Simulation Algorithm and Math)



[ad_2]

Leave a Comment

Your email address will not be published. Required fields are marked *