leather-io / extension

Leather browser extension
https://leather.io
MIT License
294 stars 142 forks source link

Show details about post-condition failures #3920

Open VelarBTC opened 1 year ago

VelarBTC commented 1 year ago

Post conditions for failing tx https://explorer.hiro.so/txid/0xda51face6996587a596fab34bb4101cc329d53951e36c8c749897deb6e1c620c?chain=testnet Working Post Condition https://explorer.hiro.so/txid/0xe3ef2967152e851dee6047fca09373c34e9f9eb2be6e21b3474cfad1f69873e8?chain=testnet

Tx dump for both below

swap-exact-tokens-for-tokens

{
    "txId": "da51face6996587a596fab34bb4101cc329d53951e36c8c749897deb6e1c620c",
    "txRaw": "0x80800000000400f45f1ee12586456a15f1b77a4a2d88da021de408000000000000018000000000001e84800001a73f3d6276d764367782633bad0cf035d5fd55b87ccfe3774cb0873ab29721a377f73b2f8aaa9d81aa3d6617d8eb3398e70660763ee9984da6547efaaed7d9a103020000000200021af45f1ee12586456a15f1b77a4a2d88da021de40801000000000098968001031a81d1b585c012192166f5afa30d1245701e2073a904636f72651a81d1b585c012192166f5afa30d1245701e2073a90576656c61720576656c61720300000000069d4004021a81d1b585c012192166f5afa30d1245701e2073a906726f757465721c737761702d65786163742d746f6b656e732d666f722d746f6b656e73000000080100000000000000000000000000000001061a81d1b585c012192166f5afa30d1245701e2073a90477737478061a81d1b585c012192166f5afa30d1245701e2073a90576656c6172061a81d1b585c012192166f5afa30d1245701e2073a90477737478061a81d1b585c012192166f5afa30d1245701e2073a90576656c6172061a81d1b585c012192166f5afa30d1245701e2073a90564756d6d79010000000000000000000000000098968001000000000000000000000000069d4004",
    "stacksTransaction": {
        "version": 128,
        "auth": {
            "authType": 4,
            "spendingCondition": {
                "hashMode": 0,
                "signer": "f45f1ee12586456a15f1b77a4a2d88da021de408",
                "nonce": "384n",
                "fee": "2000000n",
                "keyEncoding": 0,
                "signature": {
                    "type": 9,
                    "data": "01a73f3d6276d764367782633bad0cf035d5fd55b87ccfe3774cb0873ab29721a377f73b2f8aaa9d81aa3d6617d8eb3398e70660763ee9984da6547efaaed7d9a1"
                }
            }
        },
        "payload": {
            "type": 8,
            "payloadType": 2,
            "contractAddress": {
                "type": 0,
                "version": 26,
                "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
            },
            "contractName": {
                "type": 2,
                "content": "router",
                "lengthPrefixBytes": 1,
                "maxLengthBytes": 128
            },
            "functionName": {
                "type": 2,
                "content": "swap-exact-tokens-for-tokens",
                "lengthPrefixBytes": 1,
                "maxLengthBytes": 128
            },
            "functionArgs": [
                {
                    "type": 1,
                    "value": "1n"
                },
                {
                    "type": 6,
                    "address": {
                        "type": 0,
                        "version": 26,
                        "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                    },
                    "contractName": {
                        "type": 2,
                        "content": "wstx",
                        "lengthPrefixBytes": 1,
                        "maxLengthBytes": 128
                    }
                },
                {
                    "type": 6,
                    "address": {
                        "type": 0,
                        "version": 26,
                        "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                    },
                    "contractName": {
                        "type": 2,
                        "content": "velar",
                        "lengthPrefixBytes": 1,
                        "maxLengthBytes": 128
                    }
                },
                {
                    "type": 6,
                    "address": {
                        "type": 0,
                        "version": 26,
                        "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                    },
                    "contractName": {
                        "type": 2,
                        "content": "wstx",
                        "lengthPrefixBytes": 1,
                        "maxLengthBytes": 128
                    }
                },
                {
                    "type": 6,
                    "address": {
                        "type": 0,
                        "version": 26,
                        "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                    },
                    "contractName": {
                        "type": 2,
                        "content": "velar",
                        "lengthPrefixBytes": 1,
                        "maxLengthBytes": 128
                    }
                },
                {
                    "type": 6,
                    "address": {
                        "type": 0,
                        "version": 26,
                        "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                    },
                    "contractName": {
                        "type": 2,
                        "content": "dummy",
                        "lengthPrefixBytes": 1,
                        "maxLengthBytes": 128
                    }
                },
                {
                    "type": 1,
                    "value": "10000000n"
                },
                {
                    "type": 1,
                    "value": "110968836n"
                }
            ]
        },
        "chainId": 2147483648,
        "postConditionMode": 2,
        "postConditions": {
            "type": 7,
            "lengthPrefixBytes": 4,
            "values": [
                {
                    "type": 5,
                    "conditionType": 0,
                    "principal": {
                        "type": 1,
                        "prefix": 2,
                        "address": {
                            "type": 0,
                            "version": 26,
                            "hash160": "f45f1ee12586456a15f1b77a4a2d88da021de408"
                        }
                    },
                    "conditionCode": 1,
                    "amount": "10000000n"
                },
                {
                    "type": 5,
                    "conditionType": 1,
                    "principal": {
                        "type": 1,
                        "prefix": 3,
                        "address": {
                            "type": 0,
                            "version": 26,
                            "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                        },
                        "contractName": {
                            "type": 2,
                            "content": "core",
                            "lengthPrefixBytes": 1,
                            "maxLengthBytes": 128
                        }
                    },
                    "conditionCode": 3,
                    "amount": "110968836n",
                    "assetInfo": {
                        "type": 4,
                        "address": {
                            "type": 0,
                            "version": 26,
                            "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                        },
                        "contractName": {
                            "type": 2,
                            "content": "velar",
                            "lengthPrefixBytes": 1,
                            "maxLengthBytes": 128
                        },
                        "assetName": {
                            "type": 2,
                            "content": "velar",
                            "lengthPrefixBytes": 1,
                            "maxLengthBytes": 128
                        }
                    }
                }
            ]
        },
        "anchorMode": 3
    }
}

**add-liquidity**
{
    "txId": "e3ef2967152e851dee6047fca09373c34e9f9eb2be6e21b3474cfad1f69873e8",
    "txRaw": "0x80800000000400f45f1ee12586456a15f1b77a4a2d88da021de408000000000000018100000000001e848000012b4b46250d280d3986998bf93023ba41c0671b6806e5ea075a5106e0c4ca94420688526b9d2f99ff238809a8d136617405f8021ddc21e7b8bcb5da66e2253a6903020000000200021af45f1ee12586456a15f1b77a4a2d88da021de4080300000000007a120001021af45f1ee12586456a15f1b77a4a2d88da021de4081a81d1b585c012192166f5afa30d1245701e2073a90576656c61720576656c61720300000000069cbb6e021a81d1b585c012192166f5afa30d1245701e2073a906726f757465720d6164642d6c6971756964697479000000080100000000000000000000000000000001061a81d1b585c012192166f5afa30d1245701e2073a90477737478061a81d1b585c012192166f5afa30d1245701e2073a90576656c6172061a81d1b585c012192166f5afa30d1245701e2073a90a777374782d76656c61720100000000000000000000000000989680010000000000000000000000000843ea4a01000000000000000000000000007a120001000000000000000000000000069cbb6e",
    "stacksTransaction": {
        "version": 128,
        "auth": {
            "authType": 4,
            "spendingCondition": {
                "hashMode": 0,
                "signer": "f45f1ee12586456a15f1b77a4a2d88da021de408",
                "nonce": "385n",
                "fee": "2000000n",
                "keyEncoding": 0,
                "signature": {
                    "type": 9,
                    "data": "012b4b46250d280d3986998bf93023ba41c0671b6806e5ea075a5106e0c4ca94420688526b9d2f99ff238809a8d136617405f8021ddc21e7b8bcb5da66e2253a69"
                }
            }
        },
        "payload": {
            "type": 8,
            "payloadType": 2,
            "contractAddress": {
                "type": 0,
                "version": 26,
                "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
            },
            "contractName": {
                "type": 2,
                "content": "router",
                "lengthPrefixBytes": 1,
                "maxLengthBytes": 128
            },
            "functionName": {
                "type": 2,
                "content": "add-liquidity",
                "lengthPrefixBytes": 1,
                "maxLengthBytes": 128
            },
            "functionArgs": [
                {
                    "type": 1,
                    "value": "1n"
                },
                {
                    "type": 6,
                    "address": {
                        "type": 0,
                        "version": 26,
                        "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                    },
                    "contractName": {
                        "type": 2,
                        "content": "wstx",
                        "lengthPrefixBytes": 1,
                        "maxLengthBytes": 128
                    }
                },
                {
                    "type": 6,
                    "address": {
                        "type": 0,
                        "version": 26,
                        "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                    },
                    "contractName": {
                        "type": 2,
                        "content": "velar",
                        "lengthPrefixBytes": 1,
                        "maxLengthBytes": 128
                    }
                },
                {
                    "type": 6,
                    "address": {
                        "type": 0,
                        "version": 26,
                        "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                    },
                    "contractName": {
                        "type": 2,
                        "content": "wstx-velar",
                        "lengthPrefixBytes": 1,
                        "maxLengthBytes": 128
                    }
                },
                {
                    "type": 1,
                    "value": "10000000n"
                },
                {
                    "type": 1,
                    "value": "138668618n"
                },
                {
                    "type": 1,
                    "value": "8000000n"
                },
                {
                    "type": 1,
                    "value": "110934894n"
                }
            ]
        },
        "chainId": 2147483648,
        "postConditionMode": 2,
        "postConditions": {
            "type": 7,
            "lengthPrefixBytes": 4,
            "values": [
                {
                    "type": 5,
                    "conditionType": 0,
                    "principal": {
                        "type": 1,
                        "prefix": 2,
                        "address": {
                            "type": 0,
                            "version": 26,
                            "hash160": "f45f1ee12586456a15f1b77a4a2d88da021de408"
                        }
                    },
                    "conditionCode": 3,
                    "amount": "8000000n"
                },
                {
                    "type": 5,
                    "conditionType": 1,
                    "principal": {
                        "type": 1,
                        "prefix": 2,
                        "address": {
                            "type": 0,
                            "version": 26,
                            "hash160": "f45f1ee12586456a15f1b77a4a2d88da021de408"
                        }
                    },
                    "conditionCode": 3,
                    "amount": "110934894n",
                    "assetInfo": {
                        "type": 4,
                        "address": {
                            "type": 0,
                            "version": 26,
                            "hash160": "81d1b585c012192166f5afa30d1245701e2073a9"
                        },
                        "contractName": {
                            "type": 2,
                            "content": "velar",
                            "lengthPrefixBytes": 1,
                            "maxLengthBytes": 128
                        },
                        "assetName": {
                            "type": 2,
                            "content": "velar",
                            "lengthPrefixBytes": 1,
                            "maxLengthBytes": 128
                        }
                    }
                }
            ]
        },
        "anchorMode": 3
    }
}
kyranjamie commented 1 year ago

@VelarBTC we're looking into this issue and would love more information to help us diagnose whether or not this is a wallet issue.

The post conditions are as described in the explorer:

image

If the transaction was failed by the network, this is likely an issue with either: 1) the contract call arguments constructed 2) the contract itself

Any more information appreciated, thanks

VelarBTC commented 1 year ago

Tx is succeding in allow mode, but is rolling back because of post conditions. The post conditions passed are valid and working for other functions from the same contract( we updated the router contract to router-v2 to add rev share, everything else is the same with originally shared contract in the issue) . Here are two tx's with valid post conditions , swap ones always fail , while add liquidity and remove liquidity ones are working.

SWAP - https://explorer.hiro.so/txid/0x893665fab54c52511d21f0b0b13f8fdee0f0ef1b44b25dc8c565b8069bc558b7?chain=testnet

ADD LIQUIDITY - https://explorer.hiro.so/txid/0x411b310b0819472e7769e9ccd116bae10333b518d1d9aaac02b7fd58312ddf8f?chain=testnet

kyranjamie commented 1 year ago

Tx is succeding in allow mode, but is rolling back because of post conditions

Not sure I follow. Either it succeeds and gets mined into a block, or it gets rolled back and is never successful?

Can you provide any more info into how this is a problem caused by the wallet? How do we know that this isn't just a problem with the contract? Does it work in Xverse, for example?

OmarTraderXBT commented 1 year ago

so, for example:

https://explorer.hiro.so/txid/0xda51face6996587a596fab34bb4101cc329d53951e36c8c749897deb6e1c620c?chain=testnet

fails with the error message "This transaction would have succeeded, but was rolled back by a supplied post-condition."

looking at the displayed post condition:

and comparing with the event generated by the (successfully evaluated) txn:

notably amt-out > post con expected transfer

by inspection of core.clar, lines 485, 486, the only transfers from the user wallet are for amt-in/amt-out.

so at a minimum I think its clear that there's a UI issue.

whether or not there's additionally an issue in the wallet, I'm not sure yet, currently reviewing front end code. any pointers as to what would be good functions to instrument or how to get better dumps for debugging appreciated :) ideally id love to get the final txn object thats broadcasted to the mempool from hiro somehow :)

OmarTraderXBT commented 1 year ago

oh yeah, setting post con mode to allow on the same inputs results in transfers that should pass the displayed post conditions also

OmarTraderXBT commented 1 year ago

nvm this was an issue on our end :) i guess you could turn this ticket into feature request: show which transfers caused post conditions to fail though 🤗

pete-watters commented 1 year ago

Thanks for the update @OmarTraderXBT , glad to hear you solved the issue.

markmhendrickson commented 1 year ago

i guess you could turn this ticket into feature request: show which transfers caused post conditions to fail though

Good idea, I'll reopen and rename this issue so it targets this future developer enhancement 🙏