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

Add support for passing data from Bitcoin as inscriptions #2478

Closed
5 tasks done
Tracked by #2760
fadeev opened this issue Jul 15, 2024 · 4 comments · Fixed by #2957
Closed
5 tasks done
Tracked by #2760

Add support for passing data from Bitcoin as inscriptions #2478

fadeev opened this issue Jul 15, 2024 · 4 comments · Fixed by #2957
Labels
chain:bitcoin Bitcoin chain related epic Group issues under a high-level objective feature:idea An early idea for a feature. Used as reference to follow new feature integrations

Comments

@fadeev
Copy link
Member

fadeev commented Jul 15, 2024

Is your feature request related to a problem? Please describe.

Currently, ZetaChain supports passing data using the op_return opcode, which has an 80-byte limit. This limitation restricts the amount of data that can be included in cross-chain transactions, posing challenges for applications that require more data, such as omnichain NFTs and complex smart contract interactions.

Describe the solution you'd like

To address this limitation, we propose adding support for passing data as inscriptions. Inscriptions allow for longer messages by utilizing the witness portion of a Bitcoin transaction, enabling applications to include more comprehensive data.

Inscriptions involve wrapping data into a Taproot script and injecting it into the witness portion of a Bitcoin transaction. This process allows for data pushes up to 520 bytes, and larger data files can be managed through multiple data pushes. Creating an inscription requires a commit transaction (hash reference) and a reveal transaction (revealing the entire script).

We propose maintaining support for both op_return and inscriptions. The advantage of op_return is that it allows for a single transaction, making it simpler and potentially less costly for users. On the other hand, inscriptions support longer messages, providing more flexibility for applications that need to pass larger amounts of data. A user-facing app could potentially choose which method to use depending on the length of the data being passed.

Tasks

Preview Give feedback
  1. chain:bitcoin
    gartnera
  2. UPGRADE_TESTS breaking:cli
  3. chain:bitcoin zetaclient
@fadeev fadeev added the feature:idea An early idea for a feature. Used as reference to follow new feature integrations label Jul 15, 2024
@bitSmiley
Copy link
Contributor

Zetachain Extending EVM Calldata Size From Bitcoin

Introduction

Currently btc to zeta ominchain call cannot contain arbitrary long evm contract call data length. The current limit is 80
bytes and this is probably too much of a restriction.

From a technical point of view, this comes from BTC "OP_RETURN" opcode that allows only 80 bytes.

This document proposals a possible solution to extend to a larger calldata size by utilizing tapscript based solution,
very much like inscription.

Tapscript

Similar to inscriptions used, this approach makes use of the tapscript in bitcoin. Unlike inscription, the current protocol
does not have as many attributes, with just the raw hex bytes. To be more specific, the script looks as follows:

OP_FALSE
OP_IF
  OP_PUSH 0x...
  OP_PUSH 0x...
OP_ENDIF

The caller will first makes a "commit" script that hashes the tapscript, then makes a "reveal" script that reveals the
tapscript. The protocol does not import on the number of inputs of the reveal transaction, but the number of outputs should
just be 1 and targeted to the specific recipient address with value more than the minimal fee. It is possible to have multiple
outputs, but keep things simple for now.

The indexer will have to listen to transactions with output targeting TSS address. Once a tapscript is detected, it will
concat the bytes in OP_PUSH into one large bytes array and this is the arbitrary call data.

So with the above change, a new method is proposed GetBtcEventWithTapscript:

func GetBtcEventWithTapscript(
	rpcClient interfaces.BTCRPCClient,
	tx btcjson.TxRawResult,
	tssAddress string,
	blockNumber uint64,
	logger zerolog.Logger,
	netParams *chaincfg.Params,
	depositorFee float64,
) (*BTCInboundEvent, error) {
  // a call to existing method first
  event, err := GetBtcEvent(...);

  if event != nil {
    return event, nil;
  }

  if len(tx.Vout) > 0 {
    return tryParseTapscript(...);
  }

  return err("ignore charity txn")
}

There should be no other changes to existing code.

Deliverables and Timeline

There are two major deliverables:

  • A typescript/nodejs library/example for creating the commit and reveal txns based on bitcoin-js library (1 week).
  • Addition of GetBtcEventWithTapscript method:
    • 2 weeks for development + unit testing
    • 1 week for integration testing + additional documentation

@lumtis
Copy link
Member

lumtis commented Jul 18, 2024

@bitSmiley thank you for sharing this solution

Just a note on the testing side, our general process for new feature and for validation is to introduce a E2E test. You can see more info on this in this doc: https://github.com/zeta-chain/node/blob/develop/docs/development/LOCAL_TESTING.md

For example, a test_bitcoin_deposit_with_tapscript.go can be introduced for the E2E test.

@bitSmiley
Copy link
Contributor

@lumtis Thx for the tip, I will check them out first. Will take some time to try it.

@bitSmiley
Copy link
Contributor

With the above two PRs merged, the next step is really carrying out integration testing in btc networks:

  • BTC regtest
  • BTC mainnet: actually the inscription transactions were created, just the listener not tested

@CharlieMc0 CharlieMc0 added this to the September Release milestone Aug 5, 2024
@lumtis lumtis added chain:bitcoin Bitcoin chain related epic Group issues under a high-level objective labels Aug 19, 2024
@lumtis lumtis removed this from the September Release milestone Aug 27, 2024
@CharlieMc0 CharlieMc0 added this to the September Release milestone Aug 28, 2024
@lumtis lumtis removed this from the September Release (v21) milestone Aug 29, 2024
@CharlieMc0 CharlieMc0 added this to the September Release (v21) milestone Sep 25, 2024
@lumtis lumtis linked a pull request Oct 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chain:bitcoin Bitcoin chain related epic Group issues under a high-level objective feature:idea An early idea for a feature. Used as reference to follow new feature integrations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants