Skip to content

Conversation

@ChrisCho-H
Copy link
Contributor

@ChrisCho-H ChrisCho-H commented Aug 30, 2024

Script number can be up to 2^39 - 1 to encode locktime.
If it's only for the integer operation besides locktime, it must be 2^31 - 1, not 2^31.

I agree with apoelstra opinion to deprecate this value.

@github-actions github-actions bot added the C-bitcoin PRs modifying the bitcoin crate label Aug 30, 2024
@coveralls
Copy link

coveralls commented Aug 30, 2024

Pull Request Test Coverage Report for Build 10654351438

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 82.736%

Totals Coverage Status
Change from base Build 10654259874: 0.0%
Covered Lines: 19707
Relevant Lines: 23819

💛 - Coveralls

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

Honestly, this looks like unclear documentation/API to me. I'd could argue that both representations make sense and both changing it and not changing it are wrong.

If this constant is kept then we should instead create two other constants: MAX_SCRIPT_INT and MAX_SCRIPT_LOCK_TIME and deprecate MAX_SCRIPT_INT in favor of those because of unclear semantics.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's weird that the constant is just thrown here with no code using it. While it's pub it's such an internal detail that probably nobody should use it and use the methods on Script instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the history is from when rust-miniscript implemented locktime.
rust-bitcoin/rust-miniscript#408 (comment)

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 we should deprecate this constant (and not change it to reduce breakage). It's such a weird thing. Elsewhere I have advocated having push_locktime method(s) to push locktimes, which as you note, have a different maximum value than every other scriptnum.

Another possible, though unlikely, interpretation of this constant is that it could be the maximum output of an arithmetic opcode. This, I think, is 2^31 - 1.

Also it's weird that we have a maximum value represented as a u32, and no minimum value.

My feeling is that if you are doing something that cares about this constant, you should define your own constants that clearly represent whatever it is you mean. Good find @ChrisCho-H that this constant originates in Miniscript doing something fairly specific, propagating poorly-documented constants into this library, and apparently getting it wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with @apoelstra. It'd be better not to expose this weird constant. Overflow can be checked internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just force pushed 9620cdf, removing this constant rather than changing its value.

@github-actions
Copy link

github-actions bot commented Sep 1, 2024

🚨 API BREAKING CHANGE DETECTED

To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section.

@github-actions github-actions bot added the API break This PR requires a version bump for the next release label Sep 1, 2024
@ChrisCho-H ChrisCho-H changed the title fix: max script num is up to 2^39 - 1 fix: deprecate wrong and unused max script num Sep 1, 2024
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't hide it, that's just confusing. The deprecation message will be shown in the doc so there's no risk of people using it accidentally.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also I think we should add since = "TBD"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes warning if remove original comment without hidden doc. Should I leave the comment as it was?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please do.

Also, I would change the deprecation message to `This constant has ambiguous semantics. Please carefully check your intended use-case and define a new constant reflecting that.'

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 345d3da successfully ran local tests

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 345d3da

@apoelstra apoelstra merged commit 6a06c02 into rust-bitcoin:master Sep 2, 2024
@ChrisCho-H ChrisCho-H deleted the fix/max-script-num branch September 20, 2024 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API break This PR requires a version bump for the next release C-bitcoin PRs modifying the bitcoin crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants