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

ApplicationLogs and Neo3 GAS transfer notification results #1252

Closed
hal0x2328 opened this issue Sep 17, 2019 · 10 comments
Closed

ApplicationLogs and Neo3 GAS transfer notification results #1252

hal0x2328 opened this issue Sep 17, 2019 · 10 comments

Comments

@hal0x2328
Copy link
Contributor

The application log for a GAS transfer shows only the from/to/amount transfer notification for GAS transfers - but GAS is a special case, since the system and network fee is subtracted from that amount, so any trackers using transfer notifications to tally balances or confirm transfer amounts for a dApp will end up with incorrect results.

There is the gas_consumed property of the application log, but it doesn't reflect the system fee, network fee (or the sum of both) either so it can't be used to arrive at the correct result.

The only way currently to correctly calculate the amount of the GAS transfer from address A to address B is to also request the raw transaction and subtract the fees shown there.

Example on Neo3 TestNet, a transfer of 1.9770058 GAS:

neo> send gas AHpP2cbWfUDBuH2UVKbmLsc6AHEYYG92Vn 1.9770058
password: *****************
TXID: 0xbbc320ceb17c704987deb0db157a10248f983b06969467e51a6b960c9bc02efc

The resulting log:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "txid": "0xbbc320ceb17c704987deb0db157a10248f983b06969467e51a6b960c9bc02efc",
        "trigger": "Application",
        "vmstate": "HALT",
        "gas_consumed": "9007660",
        "stack": [],
        "notifications": [
            {
                "contract": "0xa1760976db5fcdfab2a9930e8f6ce875b2d18225",
                "state": {
                    "type": "Array",
                    "value": [
                        {
                            "type": "ByteArray",
                            "value": "5472616e73666572"
                        },
                        {
                            "type": "ByteArray",
                            "value": "78e2f3100f2c76823345835c96b8f3b1897a7256"
                        },
                        {
                            "type": "ByteArray",
                            "value": "16699c1a5374ec7b5ce880449e14e7c99ef3fd24"
                        },
                        {
                            "type": "Integer",
                            "value": "197700580"
                        }
                    ]
                }
            }
        ]
    }
}

From the application log, it looks like 16699c1a5374ec7b5ce880449e14e7c99ef3fd24 received 1.97700580 GAS but there was actually a combined fee of 1.0340366 GAS subtracted so actually in the end 16699c1a5374ec7b5ce880449e14e7c99ef3fd24's balance only increased by 0.9429692 GAS.

@hal0x2328
Copy link
Contributor Author

hal0x2328 commented Sep 17, 2019

I just noticed that this only occurred when sending all of the remaining GAS from the wallet - on an earlier transfer of 1 GAS, the fee paid was not subtracted from the amount the recipient received and the transfer notification was correct.

@shargon shargon transferred this issue from neo-project/neo-modules Nov 19, 2019
@shargon
Copy link
Member

shargon commented Nov 19, 2019

Maybe this will be fixed with #1248

@shargon
Copy link
Member

shargon commented Nov 20, 2019

@Tommo-L could you check if your patch #1248 fix this issue too?

@Tommo-L
Copy link
Contributor

Tommo-L commented Nov 21, 2019

I think this is another problem, I'll check it.

@Tommo-L
Copy link
Contributor

Tommo-L commented Nov 28, 2019

@hal0x2328
Is it wrong?

image

neo> send gas AHpP2cbWfUDBuH2UVKbmLsc6AHEYYG92Vn 1.9770058
password: *****************
TXID: 0xbbc320ceb17c704987deb0db157a10248f983b06969467e51a6b960c9bc02efc

@Tommo-L
Copy link
Contributor

Tommo-L commented Nov 28, 2019

I got the point, there is no bug. I think the two addresses: AHpP2cbWfUDBuH2UVKbmLsc6AHEYYG92Vn and ASo4cF4GPWSMAT7JYvoYe9G5BWMyrsKtcn are in the one wallet.

neo> send gas AHpP2cbWfUDBuH2UVKbmLsc6AHEYYG92Vn 1.9770058
password: *****************
TXID: 0xbbc320ceb17c704987deb0db157a10248f983b06969467e51a6b960c9bc02efc

https://neo3-preview.com/transaction/0xbbc320ceb17c704987deb0db157a10248f983b06969467e51a6b960c9bc02efc

As you can see, the tx's sender is AHpP2cbWfUDBuH2UVKbmLsc6AHEYYG92Vn, so the tx's fee = 1.0340366 was paied from AHpP2cbWfUDBuH2UVKbmLsc6AHEYYG92Vn.
Then the 1.97700580 was sent from ASo4cF4GPWSMAT7JYvoYe9G5BWMyrsKtcn actually.
At least, AHpP2cbWfUDBuH2UVKbmLsc6AHEYYG92Vn cost 1.0340366 and recevied 1.97700580, the income is:

-1.0340366 +  1.97700580 =  0.9429692

@hal0x2328
Copy link
Contributor Author

This transaction only sent part of AHpP2cbWfUDBuH2UVKbmLsc6AHEYYG92Vn's balance. The bug is exhibited only when you send the whole balance of an address.

So if AHpP2cbWfUDBuH2UVKbmLsc6AHEYYG92Vn now sends the entire current balance of 49995.919995 GAS to another address, the fee must be subtracted from the 49995.919995 - the receiving address will get the remainder which will be some amount less than 49995.919995. This behavior is expected and correct even if it makes it a bit unpredictable to the sender as to the final amount the recipient will receive.

The issue I saw is that the Transfer notification event will show that the full 49995.919995 was sent to the recipient address instead of the correct amount. So an explorer that is tracking the transfer via the notification will have the wrong information.

@Tommo-L
Copy link
Contributor

Tommo-L commented Nov 29, 2019

So if AHpP2cbWfUDBuH2UVKbmLsc6AHEYYG92Vn now sends the entire current balance of 49995.919995 GAS to another address, the fee must be subtracted from the 49995.919995 - the receiving address will get the remainder which will be some amount less than 49995.919995.

I will have a try, but I think the tx will fail as Insufficient GAS. Even though it can be packaged in the blockchain, but it will execute fail.

@hal0x2328
Copy link
Contributor Author

I see it will be possible with Neo3 to have "dust" GAS in an account that can't be transferred out because the transaction fee is more than the amount it would cost to send it. They could transfer in more GAS and send the properly calculated amount + fee to leave the amount at exactly zero but it's going to lead to confusion either way - wallets will need to be smart about handling it.

@Tommo-L
Copy link
Contributor

Tommo-L commented Dec 2, 2019

it will be possible with Neo3 to have "dust" GAS in an account that can't be transferred out because the transaction fee is more than the amount it would cost to send it.

This was fixed in #1248. It works fine my latest version
image

What surprised me was that the transaction with insufficient balance will execute successfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants