stacks-network / sbtc-bridge-api

GNU Affero General Public License v3.0
6 stars 4 forks source link

Bug: Withdrawal to wrong stacks address #88

Closed radicleart closed 12 months ago

radicleart commented 12 months ago

This withdraw transaction fails because the stacks address does not match the senders stacks address.

The incorrect stacks address has 0 balance and the burn (ft-burn?) fails with error u1 - insufficient balance.

The bridge may be encoding the stacks address / signature data incorrectly ?

radicleart commented 12 months ago

See [sBTC DR] Withdraw on testnet via sbtc bridge fails https://github.com/stacks-network/sbtc-bridge-web/pull/266

radicleart commented 12 months ago

Added tool to bridge to parse transaction data.

Screenshot 2023-10-12 at 13 22 03
radicleart commented 12 months ago

The code that builds the data seems to accord with the spec

export function getDataToSign(network:string, amount:number, bitcoinAddress:string):Uint8Array {
    const net = (network === 'testnet') ? btc.TEST_NETWORK : btc.NETWORK;
    const tx = new btc.Transaction({ allowUnknowOutput: true, allowUnknownInputs:true, allowUnknownOutputs:true });
    console.log('getDataToSign:bitcoinAddress: ' + bitcoinAddress)
    tx.addOutputAddress(bitcoinAddress, BigInt(dust), net);
    const amtBuf = amountToBigUint64(amount, 8);
    const data = concat(amtBuf, tx.getOutput(0).script!);
    const dataLen = hex.decode(data.length.toString(8));
    return concat(dataLen, data);
}
radicleart commented 12 months ago

Closing in favour of https://github.com/stacks-network/sbtc/issues/266