Firaenix / bsv-wasm

BSV stdlib written in Rust and runs in WASM environments
MIT License
70 stars 19 forks source link

error serializing transactions on 1.3.0 Beta, breaking data tegridy #52

Closed utxo-detective closed 2 years ago

utxo-detective commented 2 years ago

im unable to upgrade bsv-wasm to latest version, but would like to use the new testnet address support. Im currently using 1.2.3 in prod with no issues. When i upgrade to 1.3.0-beta.6, bsv-wasm butchers my op_return script when calling .toHex() on a transaction.

ASM string i want to publish, its a twetch post

OP_FALSE OP_RETURN 31394878696756345179427633744870515663554551797131707a5a56646f417574 676d 746578742f706c61696e 74657874 7477657463685f7477746578745f313634373533323430393832322e747874 7c 3150755161374b36324d694b43747373534c4b79316b683536575755374d74555235 534554 7477646174615f6a736f6e 6e756c6c 75726c 676d 636f6d6d656e74 6e756c6c 6d625f75736572 6e756c6c 7265706c79 6e756c6c 74797065 706f7374 74696d657374616d70 6e756c6c 617070 747765746368 696e766f696365 64373935653432622d323462342d343938372d386562382d353665343733316637636237 7c 313550636948473232534e4c514a584d6f5355615756693757537163376843667661 424954434f494e5f4543445341 314a4d6f6456736e376d7248643273646447645742566d324d4d7039517338565146 4834384e5336544d7977496c6a527662615849743041546b4246514b2b5431444b2f504f562b496f59326d53616c6576526b3562644232424876654d5a736a64422f4b3333577071484d5037717a79493958626d332b773d

ASM I get from decoding on WOC the rawtx from transaction.toHex()

OP_FALSE OP_RETURN 31394878696756345179427633744870515663554551797131707a5a56646f417574 676d 746578742f706c61696e 74657874 7477657463685f7477746578745f313634373533323335343733352e747874 OP_SWAP 3150755161374b36324d694b43747373534c4b79316b683536575755374d74555235 534554 7477646174615f6a736f6e 6e756c6c 75726c 676d 636f6d6d656e74 6e756c6c 6d625f75736572 6e756c6c 7265706c79 6e756c6c 74797065 706f7374 74696d657374616d70 6e756c6c 617070 747765746368 696e766f696365 37353839326639392d613436612d343462652d393134382d303737613134326535353236 OP_SWAP 313550636948473232534e4c514a584d6f5355615756693757537163376843667661 424954434f494e5f4543445341 314a4d6f6456736e376d7248643273646447645742566d324d4d7039517338565146 OP_8 397371626775475a58366e433931327577686877707a524e3575575947585561725250373776646e56634751447943355071614759515564545a58367a597478646d364848793166 [error]

rawtx i get from 1.3.0-beta.6 with improper formatting of my op_return script

0200000001570de65ef5fed67a1f702e0dc5f944843dbfb4efad0cacdcad49a278f68f206d010000006b483045022100a33e42d41f0656ab0e9b41cfb923a78672295e8898236292d6e89f0649b8ba43022044014d0d9a00168eb3922271d216315cf084097271bfa970940c1b9b7ab3f8754121029f470ec0384edb3fcdf98dd0c136fe3ff4cfc7e3a7bdb1bdfcc87ee87d90da1effffffff020000000000000000fdbe01006a2231394878696756345179427633744870515663554551797131707a5a56646f41757402676d0a746578742f706c61696e04746578741f7477657463685f7477746578745f313634373533323430393832322e747874017c223150755161374b36324d694b43747373534c4b79316b683536575755374d74555235035345540b7477646174615f6a736f6e046e756c6c0375726c02676d07636f6d6d656e74046e756c6c076d625f75736572046e756c6c057265706c79046e756c6c047479706504706f73740974696d657374616d70046e756c6c036170700674776574636807696e766f6963652464373935653432622d323462342d343938372d386562382d353665343733316637636237017c22313550636948473232534e4c514a584d6f53556157566937575371633768436676610d424954434f494e5f454344534122314a4d6f6456736e376d7248643273646447645742566d324d4d7039517338565146584834384e5336544d7977496c6a527662615849743041546b4246514b2b5431444b2f504f562b496f59326d53616c6576526b3562644232424876654d5a736a64422f4b3333577071484d5037717a79493958626d332b773de4ab0200000000001976a914be6961b83778feb6917a26070b794dc5c70fbaba88ac00000000

rawtx from 1.2.3 with proper formatting of my op_return script

0200000001570de65ef5fed67a1f702e0dc5f944843dbfb4efad0cacdcad49a278f68f206d010000006b483045022100c4d56808cef9d5b49ea6af76efdcfccde41564a3c62cd5aa5fab7c269d18fc07022012a1cf5ea5fefe215bfeba321921fba9f530b50f4a9333c250b1cdd4c7f1224f4121029f470ec0384edb3fcdf98dd0c136fe3ff4cfc7e3a7bdb1bdfcc87ee87d90da1effffffff020000000000000000fdbf01006a2231394878696756345179427633744870515663554551797131707a5a56646f41757402676d0a746578742f706c61696e04746578741f7477657463685f7477746578745f313634373533333130393339372e747874017c223150755161374b36324d694b43747373534c4b79316b683536575755374d74555235035345540b7477646174615f6a736f6e046e756c6c0375726c02676d07636f6d6d656e74046e756c6c076d625f75736572046e756c6c057265706c79046e756c6c047479706504706f73740974696d657374616d70046e756c6c036170700674776574636807696e766f6963652464646438633964642d653164632d343435622d396533312d353466316130333136663733017c22313550636948473232534e4c514a584d6f53556157566937575371633768436676610d424954434f494e5f454344534122314a4d6f6456736e376d7248643273646447645742566d324d4d70395173385651464c58494d525777484632796b676a56532f7a582b52467a717a76446d726a6a6935316e5378626d4d562f53356757555535673872454842465a79544d76726c64787245573766757354334d7142374f5076784b464147434f303de4ab0200000000001976a914be6961b83778feb6917a26070b794dc5c70fbaba88ac00000000

As you can see, bsv-wasm is adding op codes in the middle of my data, no tegridy

utxo-detective commented 2 years ago

image

utxo-detective commented 2 years ago

image

utxo-detective commented 2 years ago

Here is a minimal way of reproducing.

On 1.2.3 i get expected results

Screen Shot 1400-12-26 at 20 38 10

On 1.3.0 i get unexpected results

Screen Shot 1400-12-26 at 20 38 24
import { Transaction, Script, TxOut } from 'bsv-wasm'

const ASM = '0 OP_RETURN 31394878696756345179427633744870515663554551797131707a5a56646f417574 676d 746578742f706c61696e 74657874 7477657463685f7477746578745f313634373533323430393832322e747874 7c 3150755161374b36324d694b43747373534c4b79316b683536575755374d74555235 534554 7477646174615f6a736f6e 6e756c6c 75726c 676d 636f6d6d656e74 6e756c6c 6d625f75736572 6e756c6c 7265706c79 6e756c6c 74797065 706f7374 74696d657374616d70 6e756c6c 617070 747765746368 696e766f696365 64373935653432622d323462342d343938372d386562382d353665343733316637636237 7c 313550636948473232534e4c514a584d6f5355615756693757537163376843667661 424954434f494e5f4543445341 314a4d6f6456736e376d7248643273646447645742566d324d4d7039517338565146 4834384e5336544d7977496c6a527662615849743041546b4246514b2b5431444b2f504f562b496f59326d53616c6576526b3562644232424876654d5a736a64422f4b3333577071484d5037717a79493958626d332b773d'

const rawtx = '0200000000010000000000000000fdbf01006a2231394878696756345179427633744870515663554551797131707a5a56646f41757402676d0a746578742f706c61696e04746578741f7477657463685f7477746578745f313634373533323430393832322e747874017c223150755161374b36324d694b43747373534c4b79316b683536575755374d74555235035345540b7477646174615f6a736f6e046e756c6c0375726c02676d07636f6d6d656e74046e756c6c076d625f75736572046e756c6c057265706c79046e756c6c047479706504706f73740974696d657374616d70046e756c6c036170700674776574636807696e766f6963652464373935653432622d323462342d343938372d386562382d353665343733316637636237017c22313550636948473232534e4c514a584d6f53556157566937575371633768436676610d424954434f494e5f454344534122314a4d6f6456736e376d7248643273646447645742566d324d4d70395173385651464c584834384e5336544d7977496c6a527662615849743041546b4246514b2b5431444b2f504f562b496f59326d53616c6576526b3562644232424876654d5a736a64422f4b3333577071484d5037717a79493958626d332b773d00000000'

;(async () => {
    const tx = new Transaction(2, null)
    const script = Script.fromASMString(ASM);
    const output = new TxOut(BigInt(0), script)

    tx.addOutput(output)

    console.log(tx.toHex())

    const newTx = Transaction.fromHex(tx.toHex())

    console.log('rawtx matches expected', rawtx === tx.toHex())
    console.log('asm matches expected', newTx.getOutput(0).getScriptPubKey().toASMString() === ASM)
})()
utxo-detective commented 2 years ago

image

deanmlittle commented 2 years ago

Fixed in 1.3.0-beta7