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

tappsbt: add AltLeaf support to vPacket #1180

Merged
merged 11 commits into from
Nov 14, 2024
Merged

tappsbt: add AltLeaf support to vPacket #1180

merged 11 commits into from
Nov 14, 2024

Conversation

jharveyb
Copy link
Contributor

@jharveyb jharveyb commented Nov 7, 2024

Introduce the AltLeaves field for vPackets, which can be used to carry non-asset data alongside a Taproot Assets transfer. This data will be anchored alongside any assets involved in a transfer, allowing for other protocols to operate in the same anchor TXs as Taproot Assets.

@jharveyb
Copy link
Contributor Author

jharveyb commented Nov 7, 2024

Remaining TODOs from existing feedback:

  • Add explicit negative test cases for []AltLeaf with either duplicate script keys or total size over the 64K limit.
  • Explore a better interface definition for AltLeaf using *T to save on save manual type annotation.
  • Update AltLeaf constructor to accept a script key, as a field that is not allowed to be nil.
  • Update AltLeaves en/decoder to reject duplicate script keys.
  • Add a type def for AltLeaf[Asset].

Worth noting that with this more minimal encoder, the minimal size for a leaf is 42 bytes vs. 128 for a normal Asset.

@coveralls
Copy link

coveralls commented Nov 7, 2024

Pull Request Test Coverage Report for Build 11804187328

Details

  • 529 of 629 (84.1%) changed or added relevant lines in 10 files are covered.
  • 28 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.4%) to 41.023%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tappsbt/interface.go 0 3 0.0%
tappsbt/decode.go 13 17 76.47%
asset/asset.go 69 75 92.0%
tappsbt/mock.go 144 150 96.0%
asset/mock.go 71 80 88.75%
asset/encoding.go 53 70 75.71%
asset/generators.go 155 210 73.81%
Files with Coverage Reduction New Missed Lines %
tappsbt/decode.go 1 84.64%
internal/test/helpers.go 2 86.95%
tappsbt/create.go 2 53.22%
tapgarden/planter.go 2 74.87%
commitment/tap.go 2 83.91%
asset/asset.go 2 80.79%
tapchannel/aux_leaf_signer.go 3 36.33%
tapgarden/caretaker.go 4 68.5%
universe/interface.go 10 51.12%
Totals Coverage Status
Change from base Build 11789807486: 0.4%
Covered Lines: 25155
Relevant Lines: 61319

💛 - Coveralls

@dstadulis dstadulis added this to the v0.5 (v0.4.2 rename) milestone Nov 9, 2024
@jharveyb jharveyb force-pushed the psbt_aux_leaves branch 2 times, most recently from 191d54c to 29ff5f3 Compare November 12, 2024 00:30
@jharveyb
Copy link
Contributor Author

Rebased, addressed all TODO items, and added some further changes to the definition of an AltLeaf.

Specifically, the lockTime and relativeLocktime must be 0. The SplitCommitmentRoot must also be empty.

Prop tests were updated to reflect this, and there are failing cases for each condition of ValidateAltLeaf() committed as well.

@jharveyb jharveyb requested review from gijswijs, Roasbeef and guggero and removed request for gijswijs November 12, 2024 02:48
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of nits, otherwise LGTM 🎉

asset/encoding.go Show resolved Hide resolved
tappsbt/interface.go Outdated Show resolved Hide resolved
asset/asset.go Outdated Show resolved Hide resolved
asset/asset.go Outdated Show resolved Hide resolved
tappsbt/mock.go Outdated Show resolved Hide resolved
tappsbt/mock.go Outdated Show resolved Hide resolved
In this commit, we add the AltLeaf interface, which is used to carry
non-Asset data inside a Tap commitment. The Asset type meets this
interface, and we add a separate encoder that removes static fields for
an Asset being used as an AltLeaf.
In this commit, we add property tests for the AltLeaf validation logic
and the AltLeaf encoder and decoder. We also add Generator functions for
many types, including the Asset type.
In this commit, we add a new test to ensure that if a Packet is missing
the Unknown values we need to identify VPackets, the decoder fails. We
also check that decoding does not fail if Unknown values unrelated to
VPackets are included.
@jharveyb
Copy link
Contributor Author

Addressed nits, updated encoding to drop the Type field, rebased.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🦚

Nice work! Rapid testdata dir adds a bit of bloat, but I think in the short term, it's best to continue committing the test cases to the repo. In the future, we may end up reaching for an external corpus like we do with fuzzing stuff, or perhaps there's a way to minimize the test cases it adds after the fact.


// Always use the normal witness encoding, since the asset version is
// always V0.
if len(a.PrevWitnesses) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the alt leaf version ever have a use for the prev witness value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I don't expect it to, but that's also the only field left here that's 'consensus' wrt. being handled by parts of tapd, compared to the unknown odd field. Which may be useful for future features.

Given the size limits for []AltLeaves I'm not too worried about it causing dysfunction.

tappsbt/interface.go Show resolved Hide resolved
internal/test/helpers.go Show resolved Hide resolved
asset/asset_test.go Show resolved Hide resolved
var (
// Simple generators.

VersionGen = rapid.SampledFrom([]Version{V0, V1})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Was writing some tests with rapid in another PR and nearly reached to write custom gens for everything, but decided not to, but glad you did

@Roasbeef Roasbeef added this pull request to the merge queue Nov 14, 2024
Merged via the queue into main with commit f0907b5 Nov 14, 2024
18 checks passed
@guggero guggero deleted the psbt_aux_leaves branch November 14, 2024 08:52
@jharveyb
Copy link
Contributor Author

In the future, we may end up reaching for an external corpus like we do with fuzzing stuff, or perhaps there's a way to minimize the test cases it adds after the fact.

Yeah, the framework has some settings around minimization but I think that does not account for the size of the input, but maybe how quickly the code under test fails?

The default shrinking time is 30 seconds, but reaching failing cases was much faster than that. I'm not sure exactly how we can shrink the fail cases, especially which structs that have value fields and not pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

5 participants