Skip to content

Commit 5b4395e

Browse files
committed
universe: add new BurnTree interface
In this commit, we add a new interface, the BurnTree. This interface will be used by a future sub-system to maintain the on-chain asset commitment for a given asset group. The structure of this tree is very similar to the existing issuance tree. The main difference is that we'll only insert burn proofs into this tree.
1 parent db28a03 commit 5b4395e

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

universe/interface.go

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package universe
22

33
import (
4+
"bytes"
45
"context"
56
"crypto/sha256"
67
"encoding/hex"
@@ -1212,7 +1213,8 @@ type AuthenticatedIgnoreTuple struct {
12121213
// TupleQueryResp is the response to a query for ignore tuples.
12131214
type TupleQueryResp = lfn.Result[lfn.Option[[]AuthenticatedIgnoreTuple]]
12141215

1215-
// SumQueryResp is the response to a query for the sum of ignore tuples.
1216+
// SumQueryResp is the response to a query to obtain the root sum of an MS-SMT
1217+
// tree.
12161218
type SumQueryResp = lfn.Result[lfn.Option[uint64]]
12171219

12181220
// AuthIgnoreTuples is a type alias for a slice of AuthenticatedIgnoreTuple.
@@ -1237,3 +1239,90 @@ type IgnoreTree interface {
12371239
QueryTuples(context.Context, asset.Specifier,
12381240
...IgnoreTuple) TupleQueryResp
12391241
}
1242+
1243+
// BurnLeaf is a type that represents a burn leaf within the universe tree.
1244+
type BurnLeaf struct {
1245+
// UniverseKey is the key that the burn leaf is stored at.
1246+
UniverseKey LeafKey
1247+
1248+
// BurnProof is the burn proof that is stored within the burn leaf.
1249+
BurnProof *proof.Proof
1250+
}
1251+
1252+
// UniverseLeafNode returns the leaf node for the burn leaf.
1253+
func (b *BurnLeaf) UniverseLeafNode() (*mssmt.LeafNode, error) {
1254+
var proofBuf bytes.Buffer
1255+
if err := b.BurnProof.Encode(&proofBuf); err != nil {
1256+
return nil, fmt.Errorf("unable to encode burn "+
1257+
"proof: %w", err)
1258+
}
1259+
rawProofBytes := proofBuf.Bytes()
1260+
1261+
return mssmt.NewLeafNode(rawProofBytes, b.BurnProof.Asset.Amount), nil
1262+
}
1263+
1264+
// AuthenticatedBurnLeaf is a type that represents a burn leaf within the
1265+
// Universe tree. This includes the MS-SMT inclusion proofs.
1266+
type AuthenticatedBurnLeaf struct {
1267+
*BurnLeaf
1268+
1269+
// BurnTreeRoot is the root of the burn tree that the burn leaf resides
1270+
// within.
1271+
BurnTreeRoot mssmt.Node
1272+
1273+
// BurnProof is the universe inclusion proof for the burn leaf within
1274+
// the universe tree.
1275+
BurnProof *mssmt.Proof
1276+
}
1277+
1278+
// BurnDesc is a type that represents a burn leaf within the universe tree. This
1279+
// is useful for querying the state without needing the proof itself.
1280+
type BurnDesc struct {
1281+
// AssetSpec is the asset specifier for the burn leaf.
1282+
AssetSpec asset.Specifier
1283+
1284+
// Amt is the total amount burned.
1285+
Amt uint64
1286+
1287+
// BurnPoint is the outpoint of the transaction that created the burn.
1288+
BurnPoint wire.OutPoint
1289+
}
1290+
1291+
// BurnLeafResp is the response when inserting a new set of burn leaves. This
1292+
// includes the updated merkle inclusion proofs for the inserted leaves.
1293+
type BurnLeafResp = lfn.Result[[]*AuthenticatedBurnLeaf]
1294+
1295+
// BurnLeafQueryResp is the response to a query for burn leaves. If none of the
1296+
// target burn leafs are found, then None is returned with a result value.
1297+
type BurnLeafQueryResp = lfn.Result[lfn.Option[[]*AuthenticatedBurnLeaf]]
1298+
1299+
// BurnTree sum is the response to a query of the total amount burned in a given
1300+
// burn tree.
1301+
type BurnTreeSum = SumQueryResp
1302+
1303+
// ListBurnsResp is the response to a query for burn leaves.
1304+
type ListBurnsResp = lfn.Result[lfn.Option[[]*BurnDesc]]
1305+
1306+
// BurnTree represents a tree that stores all the 1st party burn events (created
1307+
// by the issuer). The tree structure is similar to the normal issuance tree,
1308+
// but all the proofs are burn proofs.
1309+
type BurnTree interface {
1310+
// Sum returns the sum of the burn leaves for the given asset.
1311+
Sum(context.Context, asset.Specifier) BurnTreeSum
1312+
1313+
// InsertBurns attempts to insert a set of new burn leaves into the burn
1314+
// tree identifier by the passed asset.Specifier. If a given proof isn't
1315+
// a true burn proof, then an error is returned. This check is performed
1316+
// upfront. If the proof is valid, then the burn leaf is inserted into
1317+
// the tree, with a new merkle proof returned.
1318+
InsertBurns(context.Context, asset.Specifier, ...*BurnLeaf) BurnLeafResp
1319+
1320+
// QueryBurns attempts to query a set of burn leaves for the given asset
1321+
// specifier. If the burn leaf points are empty, then all burn leaves
1322+
// are returned.
1323+
QueryBurns(context.Context, asset.Specifier,
1324+
...wire.OutPoint) BurnLeafQueryResp
1325+
1326+
// ListBurns attempts to list all burn leaves for the given asset.
1327+
ListBurns(context.Context, asset.Specifier) ListBurnsResp
1328+
}

0 commit comments

Comments
 (0)