Skip to content

Single patch of changes required by BitVM#2613

Closed
tcharding wants to merge 1 commit intomasterfrom
bitvm
Closed

Single patch of changes required by BitVM#2613
tcharding wants to merge 1 commit intomasterfrom
bitvm

Conversation

@tcharding
Copy link
Member

All Steven's changes in a single patch.

Taken from

  • repo: github.com/stevenroose/rust-bitcoin
  • commit: 639d552

Did minor changes to reduce the size of the patch, notably removed the opcodes::all re-export.

This is draft until after v0.32.0 release when we can start to think merging stuff from this. I'd pull out discreet PRs of course.

All Steven's changes in a single patch.

Taken from

- repo: github.com/stevenroose/rust-bitcoin
- commit: 639d552

Did minor changes to reduce the size of the patch, notably removed the
`opcodes::all` re-export.
@github-actions github-actions bot added ci C-bitcoin PRs modifying the bitcoin crate test labels Mar 19, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 8338808138

Details

  • 239 of 289 (82.7%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.05%) to 83.775%

Changes Missing Coverage Covered Lines Changed/Added Lines %
bitcoin/src/blockdata/witness.rs 91 93 97.85%
bitcoin/src/blockdata/locktime/relative.rs 0 11 0.0%
bitcoin/src/blockdata/script/mod.rs 93 130 71.54%
Totals Coverage Status
Change from base Build 8318043190: -0.05%
Covered Lines: 19936
Relevant Lines: 23797

💛 - Coveralls

} else {
Some(LockTime::from(Height::from(low16)))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This one we already have (for u32s) in #2549.

We could add a wrapper function for i64s since that's what you get from scriptnums, but I think it might make more sense to just directly add the ability to parse locktimes from Script.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it might make more sense to just directly add the ability to parse locktimes from Script.

Yes, please!

Copy link
Member

Choose a reason for hiding this comment

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

cc #2535 where we talked about this (and I wanted to mention this issue but couldn't find it since it is titled "Single patch" lol).

Also cc #2849 which is the "followup to #2535" issue.

};

/// The default maximum size of scriptints.
const DEFAULT_MAX_SCRIPTINT_SIZE: usize = 4;
Copy link
Member

Choose a reason for hiding this comment

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

The purpose of this constant is that

  • All script opcodes take maximum 4-byte numbers as inputs.
  • Except CLTV which takes a maximum 5-byte number.

Personally I think it'd be clearer if we just had a read_scriptint and read_cltv_scriptint method which each passed into a read_scriptint_internal and hardcoded the 4 and 5. It's a minor refactor relative to what's here but I'd find it easier to follow if everything was together and we didn't have a new constant to memorize the value of.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also encode the constraints in the types.

let mut buf = [0u8; 8];
let len = write_scriptint(&mut buf, n);
buf[0..len].to_vec()
}
Copy link
Member

Choose a reason for hiding this comment

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

We already have script::Builder::push_int. Should look into the purpose of this method.

}

Ok(builder.into_script())
}
Copy link
Member

Choose a reason for hiding this comment

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

This is interesting but it makes our existing "asm" output first class. We should maybe think about whether we want to change it (bearing in mind that it's currently heavily used, at least in user display, in e.g. Esplora).

  • Do we want to encode decimal numbers at all?
  • Do we want to drop the OP_ prefix from opcodes?
  • Should the OP_PUSHNUM_x names be shortened to just OP_x? How about the OP_PUSHBYTES_n?
  • Should we handle OP_TRUE as an alias for OP_1? OP_FALSE for OP_0? OP_PUSHBYTES_0 for OP_0? etc
  • Should we allow the old NOPx names for CSV and CLTV?

We don't need to answer these here ofc but there will be a long debate on the actual PR that introduces this.

.map(Script::from_bytes)
self.last().and_then(|last| {
// From BIP341:
// If there are at least two witness elements, and the first byte of
Copy link
Member

Choose a reason for hiding this comment

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

This change appears to make the logic inconsistent with the comment.

} else {
None
}
})
Copy link
Member

Choose a reason for hiding this comment

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

I think these three methods should be a single one which returns some sort of composite structure which describes whether there is a control block, whether there is an annex, whether there is a tapscript, etc.

But should be debated in another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wanted this too and also to allow going in the opposite direction: create the struct and then "serialize" it as a witness.

@tcharding
Copy link
Member Author

Thanks for taking the time to look @apoelstra, I had not looked that closely myself yet even!

@tcharding
Copy link
Member Author

I'm not sure what to do with this PR.

  1. Pull down the BitVM codebase, patch the manifest to this branch and make sure everything works and then tease this into proper PRs
  2. Someone points out things in this PR that are useful without even needing to look at BitVM codebase and makes issues that we can then do individually

The least work for me is (2), but that "someone" probably has to be @apoelstra. If you think the BitVM usecase is just in general important enough Andrew then I'll do (1). FTR my priorities currently are:

  1. hashes module
  2. primitives crate
  3. Work on rust-bitcoind-json-rpc any time I don't have mental capacity to work on hashes.

Thanks

@apoelstra
Copy link
Member

Sounds good. Agreed that hashes and primitives are higher priority. And similar with rpc stuff.

I will maybe work on this then when I have some spare mental capacity. I'm glad that Kix bumped it so that I was able to find it again.

@tcharding
Copy link
Member Author

Feel free to re-name it

@tcharding tcharding changed the title Single patch of changes Single patch of changes required by BitVM Jun 11, 2024
@storopoli
Copy link
Contributor

@tcharding this was discussed internally in a BitVM Alliance group meeting today.

A lot of folks are using this branch in their Cargo.tomls for BitVM-based open source implementations1.

I want to help migrating these changes to a new PR and going over the review rounds.

How do you want to tackle this @tcharding? Should I do a new PR, since this will be the 9th circle of rebasing hell?

Related to BitVM/BitVM#23

Footnotes

  1. Examples: bitvm/bitvm and alpenlabs/strata-bridge-poc.

@apoelstra
Copy link
Member

@storopoli if you are willing to take this on, please do! I am happy to do review to try to push it forward. I think BitVM is very important ... but I guess, not important enough for me to actively do the work.

@tcharding
Copy link
Member Author

Yeah man go for it, that would be great.

@storopoli storopoli mentioned this pull request Dec 11, 2024
@tcharding
Copy link
Member Author

@storopoli has got this covered.

@tcharding tcharding closed this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bitcoin PRs modifying the bitcoin crate ci test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants