Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions internal/core/application/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,17 +554,11 @@ func (s *service) SubmitOffchainTx(
)
}

tapleafScript := ptx.Inputs[inputIndex].TaprootLeafScript[0]
checkpointTapscript := &waddrmgr.Tapscript{
RevealedScript: tapleafScript.Script,
}

ins = append(ins, offchain.VtxoInput{
Outpoint: &checkpointPsbt.UnsignedTx.TxIn[0].PreviousOutPoint,
Tapscript: tapscript,
CheckpointTapscript: checkpointTapscript,
RevealedTapscripts: tapscripts,
Amount: int64(vtxo.Amount),
Outpoint: &checkpointPsbt.UnsignedTx.TxIn[0].PreviousOutPoint,
Tapscript: tapscript,
RevealedTapscripts: tapscripts,
Amount: int64(vtxo.Amount),
})
}

Expand Down
20 changes: 5 additions & 15 deletions pkg/ark-lib/offchain/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ type VtxoInput struct {
Amount int64
// Tapscript is the path used to spend the vtxo
Tapscript *waddrmgr.Tapscript
// CheckpointTapscript is the path used to craft checkpoint output script
// it is combined with the signer's unroll script to creaft a new "checkpoint" output script
// it can be nil, defaulting to Tapscript if not set
CheckpointTapscript *waddrmgr.Tapscript
RevealedTapscripts []string
// RevealedTapscripts is the whole taproot tree of the vtxo
// it must be revealed to the ark operator in order to verify the spent paths are valid
RevealedTapscripts []string
}

// BuildTxs builds the ark and checkpoint txs for the given inputs and outputs.
Expand Down Expand Up @@ -167,15 +165,7 @@ func buildArkTx(vtxos []VtxoInput, outputs []*wire.TxOut) (*psbt.Packet, error)
func buildCheckpointTx(
vtxo VtxoInput, signerUnrollScript *script.CSVMultisigClosure,
) (*psbt.Packet, *VtxoInput, error) {
// create the checkpoint vtxo script from collaborative closure
checkpointCollaborativeTapscript := vtxo.Tapscript
if vtxo.CheckpointTapscript != nil {
checkpointCollaborativeTapscript = vtxo.CheckpointTapscript
}

collaborativeClosure, err := script.DecodeClosure(
checkpointCollaborativeTapscript.RevealedScript,
)
collaborativeClosure, err := script.DecodeClosure(vtxo.Tapscript.RevealedScript)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -205,7 +195,7 @@ func buildCheckpointTx(
// Now that we have the checkpoint tx, we need to return the corresponding output that will be
// used as input for the ark tx.
tapLeafHash := txscript.NewBaseTapLeaf(
checkpointCollaborativeTapscript.RevealedScript,
vtxo.Tapscript.RevealedScript,
).TapHash()
collaborativeLeafProof, err := tapTree.GetTaprootMerkleProof(tapLeafHash)
if err != nil {
Expand Down
33 changes: 10 additions & 23 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,6 @@ func TestSendToConditionMultisigClosure(t *testing.T) {
require.NoError(t, err)

closure := vtxoScript.ForfeitClosures()[0]
checkpointClosure := vtxoScript.ForfeitClosures()[1]

bobAddr := arklib.Address{
HRP: "tark",
Expand All @@ -1567,9 +1566,6 @@ func TestSendToConditionMultisigClosure(t *testing.T) {
scriptBytes, err := closure.Script()
require.NoError(t, err)

checkpointScript, err := checkpointClosure.Script()
require.NoError(t, err)

merkleProof, err := vtxoTapTree.GetTaprootMerkleProof(
txscript.NewBaseTapLeaf(scriptBytes).TapHash(),
)
Expand All @@ -1578,24 +1574,11 @@ func TestSendToConditionMultisigClosure(t *testing.T) {
ctrlBlock, err := txscript.ParseControlBlock(merkleProof.ControlBlock)
require.NoError(t, err)

checkpointMerkleProof, err := vtxoTapTree.GetTaprootMerkleProof(
txscript.NewBaseTapLeaf(checkpointScript).TapHash(),
)
require.NoError(t, err)

checkpointCtrlBlock, err := txscript.ParseControlBlock(checkpointMerkleProof.ControlBlock)
require.NoError(t, err)

tapscript := &waddrmgr.Tapscript{
ControlBlock: ctrlBlock,
RevealedScript: merkleProof.Script,
}

checkpointTapscript := &waddrmgr.Tapscript{
ControlBlock: checkpointCtrlBlock,
RevealedScript: checkpointMerkleProof.Script,
}

bobAddrStr, err := bobAddr.EncodeV0()
require.NoError(t, err)

Expand Down Expand Up @@ -1666,17 +1649,16 @@ func TestSendToConditionMultisigClosure(t *testing.T) {
unilateralExitDelayType = arklib.LocktimeTypeBlock
}

ptx, checkpointsPtx, err := offchain.BuildTxs(
arkPtx, checkpointsPtx, err := offchain.BuildTxs(
[]offchain.VtxoInput{
{
Outpoint: &wire.OutPoint{
Hash: virtualPtx.UnsignedTx.TxHash(),
Index: bobOutputIndex,
},
Amount: bobOutput.Value,
Tapscript: tapscript,
CheckpointTapscript: checkpointTapscript,
RevealedTapscripts: tapscripts,
Amount: bobOutput.Value,
Tapscript: tapscript,
RevealedTapscripts: tapscripts,
},
},
[]*wire.TxOut{
Expand All @@ -1699,7 +1681,11 @@ func TestSendToConditionMultisigClosure(t *testing.T) {

explorer := explorer.NewExplorer("http://localhost:3000", arklib.BitcoinRegTest)

encodedVirtualTx, err := ptx.B64Encode()
// add condition witness to the ark ptx
err = txutils.AddConditionWitness(0, arkPtx, wire.TxWitness{preimage[:]})
require.NoError(t, err)

encodedVirtualTx, err := arkPtx.B64Encode()
require.NoError(t, err)

signedTx, err := bobWallet.SignTransaction(
Expand All @@ -1724,6 +1710,7 @@ func TestSendToConditionMultisigClosure(t *testing.T) {
ptx, err := psbt.NewFromRawBytes(strings.NewReader(checkpoint), true)
require.NoError(t, err)

// add condition witness to the checkpoint ptx
err = txutils.AddConditionWitness(0, ptx, wire.TxWitness{preimage[:]})
require.NoError(t, err)

Expand Down
Loading