Bitcoin Forum
May 14, 2024, 12:55:08 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What is latest good practice to store data in a transaction  (Read 1733 times)
guillaume.bonnot (OP)
Jr. Member
*
Offline Offline

Activity: 30
Merit: 1


View Profile
January 06, 2015, 10:04:20 AM
 #1

Hi everyone !

I need to embed a 256 bits hash + a few bits of metadata in the bitcoin blockchain.

What is the best way to achieve this ? What are the size constraints ?

Thanks for your reply.
1715691308
Hero Member
*
Offline Offline

Posts: 1715691308

View Profile Personal Message (Offline)

Ignore
1715691308
Reply with quote  #2

1715691308
Report to moderator
"In a nutshell, the network works like a distributed timestamp server, stamping the first transaction to spend a coin. It takes advantage of the nature of information being easy to spread but hard to stifle." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715691308
Hero Member
*
Offline Offline

Posts: 1715691308

View Profile Personal Message (Offline)

Ignore
1715691308
Reply with quote  #2

1715691308
Report to moderator
1715691308
Hero Member
*
Offline Offline

Posts: 1715691308

View Profile Personal Message (Offline)

Ignore
1715691308
Reply with quote  #2

1715691308
Report to moderator
hexafraction
Sr. Member
****
Offline Offline

Activity: 392
Merit: 259

Tips welcomed: 1CF4GhXX1RhCaGzWztgE1YZZUcSpoqTbsJ


View Profile
January 06, 2015, 11:17:22 AM
 #2

You can use a data-carrier transaction. Just push that data onto the script stack and use OP_RETURN. Note that a small percentage of nodes is configured not to relay them, and some miners won't confirm them, though they should work. Note that any coins sent this way are not spendable. I recommend either spending a small unspent output or sending change back to an address you control.

I have recently become active again after a long period of inactivity. Cryptographic proof that my account has not been compromised is available.
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4172
Merit: 8420



View Profile WWW
January 06, 2015, 11:58:29 AM
 #3

Do you actually need to embed the hash or do you just need to commit to it?

If you only need to commit to it you are better of using a pay-to-contract (https://github.com/Blockstream/contracthashtool) or potentially the sign-to-contract (an analog with the contract commitment in the nonce), because the result takes less space (lower transaction fees) and is not easily censorable by miners or tracable to third parties that you don't wish to share the information with.
guillaume.bonnot (OP)
Jr. Member
*
Offline Offline

Activity: 30
Merit: 1


View Profile
January 06, 2015, 02:01:28 PM
 #4

Thanks for the replies !

So i can make a transaction with 1 input and 2 outputs where the first one is the change and the other one is data with the op_return code. Sounds great !

Is there any consensus on the fees required ? Where can i find this information updated ?

I need all the data to be embedded on the blockchain, and if i understand well what a commitement is, you need to communicate the full data via another channel. It is like embedding a proof of existence right ?
BrianDeery
Full Member
***
Offline Offline

Activity: 144
Merit: 100


View Profile
January 06, 2015, 05:46:37 PM
 #5

Is what you are describing an implementation of Timo Hanke's 2013 San Jose presentation?

https://www.youtube.com/watch?v=qwyALGlG33Q

DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
January 06, 2015, 06:54:06 PM
Last edit: January 07, 2015, 05:54:07 PM by DeathAndTaxes
 #6

Thanks for the replies !

So i can make a transaction with 1 input and 2 outputs where the first one is the change and the other one is data with the op_return code. Sounds great !

Is there any consensus on the fees required ? Where can i find this information updated ?

Yes that is correct 1 in 2 out (OP RETURN+ change) is the most common.  It can also be "combined" with a normal transaction to reduce cost so that would be 1 or more inputs, plus 1 or more "paying" outputs (including change) plus the OP_RETURN.  Fee shouldn't need to be more than any other transaction.  The minimum is 1,000 satoshis per KB.  If you upgrade to v0.10 of the client there is an RPC call which estimates the fee required to be quickly confirmed.  It can be used for any transaction (including those with OP_RETURN outputs).

In the past this was done by dumping the data into a "normal" output which would be unspent.  Please don't do this as the network has no way of knowing that output is "fake" and thus it remains in the UTXO set forever.  OP_RETURN allows you to create an output which is included in a block but is marked as unspendable thus not bloating the UTXO (a more critical resource often ignored by most).

Three important points to consider about OP_RETURN:
1) More than one OP_RETURN output in a transaction is invalid non-standard (and won't be relayed by most nodes).
2) A "payload" of more than 40 bytes in the OP RETURN output is invalid non-standard as well.
3) Any value assigned to the OP_RETURN output is unspendable so the "coins" are effectively destroyed.  Unless you intentionally want to destroy some coins, you should ensure the OP_RETURN outputs always have a value of zero.

Some additional info:
http://bitcoin.stackexchange.com/questions/29554/explanation-of-what-an-op-return-transaction-looks-like

On edit: Thanks Gavin for non-standard vs invalid and routine counting correction.
 
guillaume.bonnot (OP)
Jr. Member
*
Offline Offline

Activity: 30
Merit: 1


View Profile
January 06, 2015, 08:31:37 PM
 #7

Is what you are describing an implementation of Timo Hanke's 2013 San Jose presentation?

https://www.youtube.com/watch?v=qwyALGlG33Q

This video made my day, amaze !

If you upgrade to v0.10 of the client there is an RPC call which estimates the fee required to be quickly confirmed.

Exactly the answer i was looking for. Great !
Gavin Andresen
Legendary
*
qt
Offline Offline

Activity: 1652
Merit: 2216


Chief Scientist


View Profile WWW
January 07, 2015, 02:54:43 PM
 #8

Three important points to consider about OP_RETURN:
1) A transaction can only have one OP_RETURN output.  Two or more is simply invalid (not non-standard but invalid) and will be rejected by all nodes.
2) The "payload" of the OP RETURN output is limited to 40 bytes.  More than 40 bytes is invalid as well.
4) The OP_RETURN output is unspendable and thus normally should have a value of 0 BTC however be aware you can set it to any valid value and if you do so accidentally then the coins are effectively destroyed.

"Three sir!"

Actually, 1 and 2 aren't correct: the one-output and only-40-bytes checks are "what is a standard transaction" policy rules. If you can get a miner to include it in a block, a transaction with 11 100-byte OP_RETURN outputs is valid.

How often do you get the chance to work on a potentially world-changing project?
dexX7
Legendary
*
Offline Offline

Activity: 1106
Merit: 1024



View Profile WWW
January 07, 2015, 03:16:34 PM
 #9

Yes that is correct 1 in 2 out (OP RETURN+ change) is the most common.  It can also be "combined" with a normal transaction to reduce cost so that would be 1 or more inputs, plus 1 or more "paying" outputs (including change) plus the OP_RETURN.  Fee shouldn't need to be more than any other transaction.

As posted in the OP_RETURN discussion thread on GitHub, one should be aware that with the standard rules regarding OP_RETURN it might not be as efficient as embedding data in a bare multisig or P2SH transaction.


DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
January 07, 2015, 05:58:56 PM
 #10

As posted in the OP_RETURN discussion thread on GitHub, one should be aware that with the standard rules regarding OP_RETURN it might not be as efficient as embedding data in a bare multisig or P2SH transaction.

True but it is generally considered poor practice to embed hundreds of bytes instead of just embedding a hash.  Personally given that one can encode data in "fake" transactions (which are not prunable) I wish there was no limit on OP_RETURN at all but that ship has sailed.  My point was that fees are per KB and that means the OP should be able to "price" the txn the same as any other txn.
DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
January 07, 2015, 06:09:04 PM
 #11

the one-output and only-40-bytes checks are "what is a standard transaction" policy rules. If you can get a miner to include it in a block, a transaction with 11 100-byte OP_RETURN outputs is valid.

Corrected.  It hindsight it makes sense.  This is no more effective at spamming than large low value "normal" outputs (which are also non-standard not invalid).  Spam/bloat prevention wouldn't be improved by making one method invalid and the other non-standard. Attacker will simply use the method which is available.

Of course one can only hope non-malicious miners would see the burden of a bloated UTXO set and thus not include those types of transactions.   At least their interests are aligned with general users.
doge94
Sr. Member
****
Offline Offline

Activity: 349
Merit: 250


View Profile
January 17, 2015, 11:13:13 PM
 #12

Three important points to consider about OP_RETURN:
1) A transaction can only have one OP_RETURN output.  Two or more is simply invalid (not non-standard but invalid) and will be rejected by all nodes.
2) The "payload" of the OP RETURN output is limited to 40 bytes.  More than 40 bytes is invalid as well.
4) The OP_RETURN output is unspendable and thus normally should have a value of 0 BTC however be aware you can set it to any valid value and if you do so accidentally then the coins are effectively destroyed.

"Three sir!"

Actually, 1 and 2 aren't correct: the one-output and only-40-bytes checks are "what is a standard transaction" policy rules. If you can get a miner to include it in a block, a transaction with 11 100-byte OP_RETURN outputs is valid.

Most nodes will not propagate a tx with 11 OP_RETURN outputs because it is a non standard transaction.
Another way to embed lots of data that will be accepted by more nodes in the network is to embed the data in a multisig output. This will clutter the UTXO though.

Alternatively you could just submit a 40 byte hash of the data in a standard OP_RETURN. This has the benefit of not messing up the UTXO set and being a standard transaction.
dexX7
Legendary
*
Offline Offline

Activity: 1106
Merit: 1024



View Profile WWW
January 18, 2015, 06:29:02 PM
 #13

This will clutter the UTXO though.

Not, if you include one public key that you have control over. I build http://redeem.bitwatch.co to prepare a transaction to sweep those.

Peter Todd
Legendary
*
expert
Offline Offline

Activity: 1120
Merit: 1150


View Profile
January 19, 2015, 06:44:10 PM
 #14

re: pay-to-contract, note how using it creates very significant and dangerous backup risks. Every pay-to-contract transaction creates a scriptPubKey that isn't derivable from the HD wallet seed, which means you need to immediately create a backup of your wallet metadata least you risk losing user funds. I strongly recommend not implementing it for this reason, without carefully considering this risk. Storing metadata in OP_RETURN outputs - as is done in stealth addresses - is an excellent way of avoiding this risk.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!