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

Issuemorefrom spends wrong UTXO #58

Open
cebe opened this issue Apr 25, 2018 · 14 comments
Open

Issuemorefrom spends wrong UTXO #58

cebe opened this issue Apr 25, 2018 · 14 comments

Comments

@cebe
Copy link

cebe commented Apr 25, 2018

Background

I am trying to create raw transactions with issuemorefrom. I am not using the issuemorefrom api call because I want to store some information in the application that creates the transation before sending it.

The problem

  • my own issuemorefrom transactions do not have an output that could be spent on new asset issues as it is the case with the transactions generated by issuemorefrom api call. I have not figured out what is the problem here, but that could be my own fault.
  • when I run issuemorefrom api call after my incorrect transaction is in the network it will spend asset outputs for generating new transactions, making these assets unusable.

How to reproduce

  1. create a new blockchain with permissions, everyone can connect, send, receive.
  2. api call listaddresses -> my admin address is 1RuottrEKTyLbi9EARtppJEwXLwUzPz48eB5s8
  3. api call issue 1RuottrEKTyLbi9EARtppJEwXLwUzPz48eB5s8 '{"name":"cointest","open":true}' 1 0.00000001
  4. api call issuemorefrom 1RuottrEKTyLbi9EARtppJEwXLwUzPz48eB5s8 1RuottrEKTyLbi9EARtppJEwXLwUzPz48eB5s8 cointest 5

The relevant transactions in the network are now:

  • the original issue TX (A):
    • outputs:
      • 0 - the issued assets
      • 1 - the issue metadata
      • 2 - output to be used for further asset issues
  • the issuemore TX (B):
    • inputs:
      • A 2
    • outputs:
      • 0 - the issued assets
      • 1 - output to be used for further asset issues

now I create my transaction:

  • `createrawtransaction '[{"txid":"B","vout":1}]' '{"someaddress":{"issuemore":{"asset":"cointest","raw":500}}}'
  • appendrawdata hex-from-above '{"details":{"origin":"us","stage":"two"}}'
  • signrawtransaction hex-from-above [] ['pk of 1RuottrEKTyLbi9EARtppJEwXLwUzPz48eB5s8 obtained via dumpprivkey']
  • sendrawtransaction hex-from-above

This transaction has only the output of the asset issue and the meta data.

now make api call issuemorefrom 1RuottrEKTyLbi9EARtppJEwXLwUzPz48eB5s8 1RuottrEKTyLbi9EARtppJEwXLwUzPz48eB5s8 cointest 5

This transactions spends the asset issued in step 4! As far as I see this is a major issue and such a transaction should never be accepted on the network.

@gidgreen
Copy link
Contributor

The transaction is legitimate, but as you say it doesn't leave another unspent output available for the next transaction. There are many ways to solve this but the easiest is to use the createrawsendfrom API. This also will allow you to built the transaction, add data, sign and send in a single API call.

@cebe
Copy link
Author

cebe commented Apr 26, 2018

Thanks for your response, I created the issue mainly because I expected issuemorefrom to fail with an error instead of spending an output it should not spend.

Also the tutorial for raw transactions contains a section about issuing assets. After using the approach described there this issue occurs.
I would expect the method described in the tutorial to result in a state of the blockchain that does not break the issuemorefrom behavior.

@gidgreen
Copy link
Contributor

There are two versions of the raw transactions tutorials. The first uses createrawsendfrom which ensures a change output is available. The second uses preparelockunspentfrom (which ensures a change output is available) + createrawtransaction. It looks like you used the second method but without preparelockunspentfrom?

@cebe
Copy link
Author

cebe commented Apr 26, 2018

If I try to send a transaction that spends the same output that issuemorefrom is spending it gets rejected:

sendrawtransaction 0100000001af1552693570bde671a7128ca294436917f434a8f9a9ea79411c57a82a3e43d1000000006a47304402207b5482ebd6cc801930b8363ae4340486aeecc323471ce32f2f1b0131f657b9680220299f91832ccb9215a067259694cada34dfec3c7292493f588c15790d2c2afc13012102829134390eb5ac0a8096858eeb0a0d1b68011d3a0a405145b7502a90334cd900ffffffff0300000000000000003776a914e28c0d35ece372299a5bee7f483ada3c0d2a87f088ac1c73706b6f17f434a8f9a9ea79411c57a82a3e43d100c2eb0b000000007500000000000000001976a914b84f95dad5f4c4c9f8461fd34f9db4241b16900d88ac0000000000000000911473706b6517f434a8f9a9ea79411c57a82a3e43d1754c7773706b75016465736372697074696f6e001d65786368616e67652066726f6d20416c70636f696e20436c6173736963636c61737369635f74786964002a54586236363265643533353764363139363639353539656662333131393365666136353036326432326565786368616e67655f72617465000131756a00000000

failed with error 500 Internal Server Error: {"result":null,"error":{"code":-26,"message":"64: Asset transfer script rejected - mismatch in input/output quantities"},"id":"bo5ae191309efb3"}

I expect the same to happen for issuemorefrom.

@gidgreen
Copy link
Contributor

Can you please explain this point again, I couldn't understand it because you cannot spend the same output more than once, in any circumstances.

@cebe
Copy link
Author

cebe commented Apr 26, 2018

It looks like you used the second method but without preparelockunspentfrom?

as far as I understand preparelockunspentfrom provides the output to use as input to the raw transaction. Does it also affect the result of createrawtransaction?

Can you please explain this point again, I couldn't understand it because you cannot spend the same output more than once, in any circumstances.

I was trying to replicate the behavior of issuemorefrom, i.e. spending an asset output as input of a transaction that only issues more assets. However I noticed that my transaction was different from the behavior of issuemorefrom, so forget about this point.

@cebe
Copy link
Author

cebe commented Apr 26, 2018

I was able to add an empty output to spend on further asset issues to my raw transaction via appendrawtransaction with {"adminaddress": 0}.
The remaining issue is that issuemorefrom will not generate such an output when executed on a broken chain.

@gidgreen
Copy link
Contributor

The preparelockunspentfrom command creates two outputs - one that it reports on, for spending, and another that is available for future use.

If you want to resurrect the ability to call issuemorefrom from an address that no longer has any unspent outputs, someone else on the chain needs to send something to that address. It can be anything, including a permission grant or sending a 0-asset output:

sendfrom from-address to-address 0

@cebe
Copy link
Author

cebe commented Apr 27, 2018

okay, thanks for your help. This is mainly about confusing behavior. If you want to fix issuemorefrom, you can keep this issue open, if not, feel free to close it.

@gidgreen
Copy link
Contributor

Can you please explain what you expected issuemorefrom to do, that it didn't do? We're not clear on what it can do if it has no unspent outputs to spend.

@cebe
Copy link
Author

cebe commented Apr 27, 2018

As far as I see, it currently takes an asset output from another transaction and produces two outputs:

  • one that issues the new assets
  • and another one that outputs the same amount of assets from the output it spent.

It should ideally also fix the current situation and create a new empty output that can be spent for further issues.

@cebe
Copy link
Author

cebe commented Apr 27, 2018

Also the tutorial should be fixed by adding a note that adding an empty output is needed to allow further issuremore calls.

@gidgreen
Copy link
Contributor

But issuemorefrom doesn't need an empty output, it can use any output, empty or not.

@cebe
Copy link
Author

cebe commented Apr 28, 2018

I understand that, but it should create an empty output in any case. Otherwise the structure of the blockchain becomes confusing in my opinion. As I said, it's all working but it's confusing, so I suggest to make sure an empty output is created in all cases. If you think nothing needs to be changed, I'm fine with that too, feel free to close the issue then.

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

2 participants