nspcc-dev / neo-go

Go Node and SDK for the NEO blockchain
MIT License
120 stars 78 forks source link

Mainnet state difference @3672783 #3045

Closed roman-khimov closed 1 year ago

roman-khimov commented 1 year ago
state differs at 3672783, block b68b24d98006ee165f9b6f2719e9bb21af8559bb775e72b7aeeab77f5405ac53
transaction cd1249d5b1d13550534f0fbab48bea7df87ba103f487645084d44b69b38adc7b:
--- https://rpc10.n3.nspcc.ru:10331
+++ http://seed2.neo.org:10332
@@ -1,2 +1,2 @@
-(*result.ApplicationLog)(0xc0004ca4c0)({
+(*result.ApplicationLog)(0xc00038a440)({
  Container: (util.Uint256) (len=32 cap=32) 7bdc8ab3694bd484506487f403a17bf87dea8bb4ba0f4f535035d1b1d54912cd,
@@ -15,3 +15,3 @@
      Name: (string) (len=8) "Transfer",
-     Item: (*stackitem.Array)(0xc00014ca20)(Array)
+     Item: (*stackitem.Array)(0xc00014d7d0)(Array)
     },
@@ -20,3 +20,3 @@
      Name: (string) (len=8) "Transfer",
-     Item: (*stackitem.Array)(0xc00014cc30)(Array)
+     Item: (*stackitem.Array)(0xc00014d9e0)(Array)
     },
@@ -25,3 +25,3 @@
      Name: (string) (len=8) "Transfer",
-     Item: (*stackitem.Array)(0xc00014ce40)(Array)
+     Item: (*stackitem.Array)(0xc00014dbf0)(Array)
     },
@@ -30,3 +30,3 @@
      Name: (string) (len=6) "Synced",
-     Item: (*stackitem.Array)(0xc00014cfc0)(Array)
+     Item: (*stackitem.Array)(0xc00014dd70)(Array)
     },
@@ -35,3 +35,3 @@
      Name: (string) (len=7) "Swapped",
-     Item: (*stackitem.Array)(0xc00014d2c0)(Array)
+     Item: (*stackitem.Array)(0xc000024300)(Array)
     }

transaction d0a94e4048fd2563637be21bb646459854eb17253800412ac8a96d9b434bd68c:
--- https://rpc10.n3.nspcc.ru:10331
+++ http://seed2.neo.org:10332
@@ -1,2 +1,2 @@
-(*result.ApplicationLog)(0xc00038a700)({
+(*result.ApplicationLog)(0xc000210440)({
  Container: (util.Uint256) (len=32 cap=32) 8cd64b439b6da9c82a4100382517eb54984546b61be27b636325fd48404ea9d0,
@@ -7,3 +7,3 @@
    VMState: (vmstate.State) HALT,
-   GasConsumed: (int64) 41639596,
+   GasConsumed: (int64) 43233295,
    Stack: ([]stackitem.Item) (len=1 cap=1) {
@@ -11,3 +11,3 @@
    },
-   Events: ([]state.NotificationEvent) (len=11 cap=13) {
+   Events: ([]state.NotificationEvent) (len=7 cap=9) {
     (state.NotificationEvent) {
@@ -15,3 +15,3 @@
      Name: (string) (len=5) "event",
-     Item: (*stackitem.Array)(0xc000204240)(Array)
+     Item: (*stackitem.Array)(0xc000205bc0)(Array)
     },
@@ -20,3 +20,3 @@
      Name: (string) (len=5) "event",
-     Item: (*stackitem.Array)(0xc0002043c0)(Array)
+     Item: (*stackitem.Array)(0xc000205ce0)(Array)
     },
@@ -25,3 +25,3 @@
      Name: (string) (len=8) "Transfer",
-     Item: (*stackitem.Array)(0xc000204630)(Array)
+     Item: (*stackitem.Array)(0xc000205ef0)(Array)
     },
@@ -30,23 +30,3 @@
      Name: (string) (len=8) "Transfer",
-     Item: (*stackitem.Array)(0xc000204870)(Array)
-    },
-    (state.NotificationEvent) {
-     ScriptHash: (util.Uint160) (len=20 cap=20) ccdba6514039dec29588221856b756520fbbdea2,
-     Name: (string) (len=10) "PTokenSwap",
-     Item: (*stackitem.Array)(0xc000204a80)(Array)
-    },
-    (state.NotificationEvent) {
-     ScriptHash: (util.Uint160) (len=20 cap=20) d5ff61d0518ad47d725c34c59433d03f63a71447,
-     Name: (string) (len=8) "Transfer",
-     Item: (*stackitem.Array)(0xc000204c90)(Array)
-    },
-    (state.NotificationEvent) {
-     ScriptHash: (util.Uint160) (len=20 cap=20) 20f0bea450ada7b903b89749d7c9bbc160b148cd,
-     Name: (string) (len=8) "Transfer",
-     Item: (*stackitem.Array)(0xc000204ea0)(Array)
-    },
-    (state.NotificationEvent) {
-     ScriptHash: (util.Uint160) (len=20 cap=20) 9c8467c6d2599f99fe4d7fbe9866b5597d178f47,
-     Name: (string) (len=9) "TokenSwap",
-     Item: (*stackitem.Array)(0xc000205230)(Array)
+     Item: (*stackitem.Array)(0xc000276120)(Array)
     },
@@ -55,3 +35,3 @@
      Name: (string) (len=11) "UnlockEvent",
-     Item: (*stackitem.Array)(0xc0002054d0)(Array)
+     Item: (*stackitem.Array)(0xc000276330)(Array)
     },
@@ -60,3 +40,3 @@
      Name: (string) (len=5) "event",
-     Item: (*stackitem.Array)(0xc0002055f0)(Array)
+     Item: (*stackitem.Array)(0xc000276450)(Array)
     },
@@ -65,3 +45,3 @@
      Name: (string) (len=21) "CrossChainUnlockEvent",
-     Item: (*stackitem.Array)(0xc000205800)(Array)
+     Item: (*stackitem.Array)(0xc000276720)(Array)
     }
roman-khimov commented 1 year ago

The entry script calls CCMS here (0x5ba6c543c5a86a85e9ab3f028a4ad849b924fab9) which unwraps its data, checks signatures and then calls the O3 bridge contract (0xcd2f899412624ffa90fba6c277d05de3f9e0ac0c) this way (bridgeIn):

[
    {
        "type": "Array",
        "value": [
            {     
                "type": "Buffer",
                "value": "FNX/YdBRitR9clw0xZQz0D9jpxRHFNYkvPrvlvofgiHEWcODRYwtyV5cPTiMjwvNIjoBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD9CwEDARTM26ZRQDnewpWIIhhWt1ZSD7veohSchGfG0lmfmf5Nf76YZrVZfRePRyS6VgEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABRTV/2HQUYrUfXJcNMWUM9A/Y6cURxQg8L6kUK2nuQO4l0nXybvBYLFIzRQoqxh02keq2Cycs1GIVSeBUh8V8BQqTJpNQCJniwPvG74INPlmRg3ESBTPduKL0AYsSkeO41VhARMZ88+k0kQVXjMAAA\
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFNYkvPrvlvofgiHEWcODRYwtyV5ceJij+IgBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
            },
            { 
                "type": "Buffer",
                "value": "X4UX1gZYDTDDvyEPoBa4kWxoW+g="
            },
            { 
                "type": "Buffer",
                "value": "EQAAAAAAAAA="
            }
        ]
    },   
    { 
        "type": "Integer",
        "value": "15"
    },
    { 
        "type": "ByteString",
        "value": "YnJpZGdlSW4="
    },
    { 
        "type": "ByteString",
        "value": "DKzg+eNd0HfCpvuQ+k9iEpSJL80="
    }
]
roman-khimov commented 1 year ago

Bridge mints some O3-pegged fUSDT:

[
    {
        "type": "ByteString",
        "value": "bWludCBwdG9rZW4gdG8gdXNlciBmYWlsZWQ="
    },
    {
        "type": "Array",
        "value": [
            {
                "type": "ByteString",
                "value": "DKzg+eNd0HfCpvuQ+k9iEpSJL80="
            },
            {
                "type": "ByteString",
                "value": "D6LTRyrv/ARa0268Z0AS26eSmzo="
            },
            {
                "type": "Integer",
                "value": "22635880126654199869"
            }
        ]
    },
    {
        "type": "Integer",
        "value": "15"
    },
    {
        "type": "ByteString",
        "value": "bWludA=="
    },
    {
        "type": "ByteString",
        "value": "1f9h0FGK1H1yXDTFlDPQP2OnFEc="
    }
]

It goes to D6LTRyrv/ARa0268Z0AS26eSmzo=/3a9b92a7db124067bc6ed35a04fcef2a47d3a20f/NMLeNw7vzSLqR5Bbegsgj9wZ8qgV588XqH:

        {
                "contract": "0x4714a7633fd03394c5345c727dd48a51d061ffd5",
                "eventname": "Transfer",
                "state": {
                        "type": "Array",
                        "value": [
                                {
                                        "type": "Any"
                                },
                                {
                                        "type": "ByteString",
                                        "value": "D6LTRyrv/ARa0268Z0AS26eSmzo="
                                },
                                {
                                        "type": "Integer",
                                        "value": "22635880126654199869"
                                }
                        ]
                }
        }
roman-khimov commented 1 year ago

And executes the proxy contract (0x3a9b92a7db124067bc6ed35a04fcef2a47d3a20f/proxyCall):

[
    {
        "type": "ByteString",
        "value": "ZXhlY3V0ZSBjYWxsRGF0YSB2aWEgY2FsbFByb3h5IGZhaWxlZA=="
    },
    {
        "type": "Array",
        "value": [
            {
                "type": "ByteString",
                "value": "1f9h0FGK1H1yXDTFlDPQP2OnFEc="
            },
            {
                "type": "ByteString",
                "value": "1iS8+u+W+h+CIcRZw4NFjC3JXlw="
            },
            {
                "type": "Integer",
                "value": "22635880126654199869"
            },
            {
                "type": "Buffer",
                "value": "AwEUzNumUUA53sKViCIYVrdWUg+73qIUnIRnxtJZn5n+TX++mGa1WX0Xj0ckulYBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUU1f9h0FGK1H1yXDTFlDPQP2OnFEcUIPC+pFCtp7kDuJdJ18m7wWCxSM0UKKsYdNpHqtgsnLNRiFUngVIfFfAUKkyaTUAiZ4sD7xu+CDT5ZkYNxEgUz3bii9AGLEpHjuNVYQETGfPPpNJEFV4zAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABTWJLz675b6H4IhxFnDg0WMLcleXHiYo/iIAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
AA"
            }
        ]
    },
    {
        "type": "Integer",
        "value": "15"
    },
    {
        "type": "ByteString",
        "value": "cHJveHlDYWxs"
    },
    { 
        "type": "ByteString",
        "value": "D6LTRyrv/ARa0268Z0AS26eSmzo="
    }
]
               {
                  "returntype" : "Boolean",
                  "safe" : false,
                  "parameters" : [
                     {
                        "type" : "Hash160",
                        "name" : "ptoken"
                     },
                     {
                        "type" : "Hash160",
                        "name" : "receiver"
                     },
                     {
                        "name" : "amount",
                        "type" : "Integer"
                     },
                     {
                        "name" : "callData",
                        "type" : "ByteArray"
                     }
                  ],
                  "name" : "proxyCall",
                  "offset" : 1821
               },
rickcain commented 1 year ago

Interesting... You've been invited to the relevant repo, hope it helps to find out the answer.

roman-khimov commented 1 year ago

swapPToken call of O3FlamingoAggregator (0xa2debb0f5256b75618228895c2de394051a6dbcc):

    {
        "type": "Array",
        "value": [
            {
                "type": "Integer",
                "value": "22635880126654199869"
            },
            {
                "type": "ByteString",
                "value": "nIRnxtJZn5n+TX++mGa1WX0Xj0c="
            },
            {
                "type": "Integer",
                "value": "22460964"
            },
            {
                "type": "Array",
                "value": [
                    {
                        "type": "ByteString",
                        "value": "1f9h0FGK1H1yXDTFlDPQP2OnFEc="
                    },
                    {
                        "type": "ByteString",
                        "value": "IPC+pFCtp7kDuJdJ18m7wWCxSM0="
                    },
                    {
                        "type": "ByteString",
                        "value": "KKsYdNpHqtgsnLNRiFUngVIfFfA="
                    },
                    {
                        "type": "ByteString",
                        "value": "KkyaTUAiZ4sD7xu+CDT5ZkYNxEg="
                    },
                    {
                        "type": "ByteString",
                        "value": "z3bii9AGLEpHjuNVYQETGfPPpNI="
                    }
                ]
            },
            {
                "type": "Integer",
                "value": "861803844"
            },
            {
                "type": "ByteString",
                "value": "1iS8+u+W+h+CIcRZw4NFjC3JXlw="
            },
            {
                "type": "Integer",
                "value": "1687798651000"
            }
        ]
    },
    {
        "type": "Integer",
        "value": "15"
    },
    {
        "type": "ByteString",
        "value": "c3dhcFBUb2tlbg=="
    },
    {
        "type": "ByteString",
        "value": "zNumUUA53sKViCIYVrdWUg+73qI="
    }
roman-khimov commented 1 year ago

OK, there is an "Insufficient AmountOut" happening here, but it happens pretty late in the execution flow.

39799485 234fd7258cc35d7721b83237b665d7ecccf470f9 247 THROW
[
    {
        "type": "ByteString",
        "value": "SW5zdWZmaWNpZW50IEFtb3VudE91dA=="
    }
]
[
    {
        "Script": "5534853448628c89acfdba573cbd68abd7a38843",
        "IP": 1222,
        "NextIP": 1227,
        "Caller": "0000000000000000000000000000000000000000"
    },
    {
        "Script": "5ba6c543c5a86a85e9ab3f028a4ad849b924fab9",
        "IP": 3810,
        "NextIP": 3815,
        "Caller": "5534853448628c89acfdba573cbd68abd7a38843"
    },
    {
        "Script": "5ba6c543c5a86a85e9ab3f028a4ad849b924fab9",
        "IP": 4623,
        "NextIP": 4628,
        "Caller": "5534853448628c89acfdba573cbd68abd7a38843"
    },
    {
        "Script": "cd2f899412624ffa90fba6c277d05de3f9e0ac0c",
        "IP": 4160,
        "NextIP": 4165,
        "Caller": "5ba6c543c5a86a85e9ab3f028a4ad849b924fab9"
    },
    {
        "Script": "cd2f899412624ffa90fba6c277d05de3f9e0ac0c",
        "IP": 4997,
        "NextIP": 5002,
        "Caller": "5ba6c543c5a86a85e9ab3f028a4ad849b924fab9"
    },
    {
        "Script": "3a9b92a7db124067bc6ed35a04fcef2a47d3a20f",
        "IP": 2257,
        "NextIP": 2262,
        "Caller": "cd2f899412624ffa90fba6c277d05de3f9e0ac0c"
    },
    {
        "Script": "3a9b92a7db124067bc6ed35a04fcef2a47d3a20f",
        "IP": 2929,
        "NextIP": 2934,
        "Caller": "cd2f899412624ffa90fba6c277d05de3f9e0ac0c"
    },
    {
        "Script": "a2debb0f5256b75618228895c2de394051a6dbcc",
        "IP": 1366,
        "NextIP": 1371,
        "Caller": "3a9b92a7db124067bc6ed35a04fcef2a47d3a20f"
    },
    {
        "Script": "a2debb0f5256b75618228895c2de394051a6dbcc",
        "IP": 1931,
        "NextIP": 1936,
        "Caller": "3a9b92a7db124067bc6ed35a04fcef2a47d3a20f"
    },
    {
        "Script": "a2debb0f5256b75618228895c2de394051a6dbcc",
        "IP": 118,
        "NextIP": 123,
        "Caller": "3a9b92a7db124067bc6ed35a04fcef2a47d3a20f"
    },
    {
        "Script": "f970f4ccecd765b63732b821775dc38c25d74f23",
        "IP": 3823,
        "NextIP": 3828,
        "Caller": "a2debb0f5256b75618228895c2de394051a6dbcc"
    },
    {
        "Script": "f970f4ccecd765b63732b821775dc38c25d74f23",
        "IP": 247,
        "NextIP": 248,
        "Caller": "a2debb0f5256b75618228895c2de394051a6dbcc"
    }
]
roman-khimov commented 1 year ago

It's an incorrect NeoGo behavior related to exception handling, confirmed now.

Regarding the application logic, as you can see we have some transfers still happening and the overall transaction result is HALT (even though the swap failed in the end), can't say if this is a correct behavior here. But maybe it is, since bridge has to save its data and it mints/transfers things correctly.

rickcain commented 1 year ago

It's an incorrect NeoGo behavior related to exception handling, confirmed now.

Regarding the application logic, as you can see we have some transfers still happening and the overall transaction result is HALT (even though the swap failed in the end), can't say if this is a correct behavior here. But maybe it is, since bridge has to save its data and it mints/transfers things correctly.

Yes this is expected behavior: ptoken minted on the destination chain, then sent to dex to do swap via aggregator, no matter if the swap reverted or not, it should not affect the cross-chain process, so it was wrapped in try cache logic, if failed, users got ptoken, if succeed, users got the swapped token.