Add OP_CHECKSIGADD and OP_SUCCESSxxx#644
Conversation
|
If I understand this correctly this change assumes everything is Tapscript. That doesn't seem right as old script will continue to exist. Perhaps put opcodes into different submodules? |
Yes, this is correct. I am in favor of doing this, but this seemed too much code diff for opcodes that will never be used (and are not meant to be used). And I was not too concerned about this because this is handled correctly with If you feel like the diff(a new opcodes submodule along with APIs for it, and updating all usage of current APIs) is worth it, I don't mind updating the PR. |
Ah, true, but I think so are |
|
Here is another possible alternative. We keep the opcodes as they are, only add |
1283b4f to
bd5d875
Compare
|
I like this alternative ... we already have issues with opcodes having multiple names (e.g. OP_TRUE vs OP_1, or OP_0 vs OP_FALSE vs OP_PUSHBYTES_0, or OP_NOPx vs OP_CSV, etc etc). So I think it's okay to rely on the classifier to figure out what an opcode "really" is. |
|
Oops, I think I misclicked close |
d3db64f to
b0ad674
Compare
src/blockdata/opcodes.rs
Outdated
| // 3 opcodes | ||
| match ctx { | ||
| ClassifyContext::TapScript => // 3 opcodes | ||
| if self == all::OP_VERIF || self == all::OP_VERNOTIF || |
There was a problem hiding this comment.
Nit: I guess that match (self, ctx) would be more readable.
There was a problem hiding this comment.
Concept ACK. While I definetly prefer having dedicated script types, suitable for context-specific tasks (like PubkeyScript, SigScript, TapScript etc, as I did in bitcoin_scripts crate), I understand that for the sake of Taproot implementation speed we should go with this for now.
Will be able to review against the spec tomorrow.
dr-orlovsky
left a comment
There was a problem hiding this comment.
Handling of OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY is missed. I will do a separate commit + PR to your branch to refactor classificator match as suggested by @Kixunil to make it more readable and address this issue
src/blockdata/opcodes.rs
Outdated
| } else if all::OP_PUSHNUM_1.code <= self.code && | ||
| self.code <= all::OP_PUSHNUM_16.code { |
There was a problem hiding this comment.
Nit:
all::PUSHNUM.code..=all::OP_PUSHNUM_16.code.contains(self.code) is more idiomatic; otherwise we will have clippy warning here (when we will start using it)
There was a problem hiding this comment.
Will change it. It was a copy-paste of the currently existing code
There was a problem hiding this comment.
.contains does not work for 1.29 :(
There was a problem hiding this comment.
Added to #510 so we don't forget it afterwards.
src/blockdata/opcodes.rs
Outdated
| } else { | ||
| Class::Ordinary(Ordinary::try_from_all(self).unwrap()) | ||
| pub fn classify(self, ctx: ClassifyContext) -> Class { | ||
| // 3 opcodes |
There was a problem hiding this comment.
Nit: we can do use all::* here and get rid of a lot of visual clutter with all:: prefixes
src/blockdata/opcodes.rs
Outdated
| (self.code >= 126 && self.code <= 129) || | ||
| (self.code >= 131 && self.code <= 134) || | ||
| (self.code >= 137 && self.code <= 138) || | ||
| (self.code >= 141 && self.code <= 142) || | ||
| (self.code >= 149 && self.code <= 153) || | ||
| (self.code >= 187 && self.code <= 254) { |
There was a problem hiding this comment.
Nit: 126..=129.contains(self.code) ... is more idiomatic (see my commend below)
src/blockdata/opcodes.rs
Outdated
| (self.code >= 187 && self.code <= 254) { | ||
| Class::SuccessOp | ||
| // 1 opcode | ||
| } else if self == all::OP_RETURN{ |
src/blockdata/opcodes.rs
Outdated
| (self.code >= 187 && self.code <= 254) { | ||
| Class::SuccessOp | ||
| // 1 opcode | ||
| } else if self == all::OP_RETURN{ |
There was a problem hiding this comment.
Also OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY according to BIP-342 must be classified as ReturnOp here. Potentially we need to rename ReturnOp into Terminating (as they named altogether in spec).
Thanks :) |
|
@sanket1729 sorry it happened not to be a PR but just commit - I didn't expect that I can push to your branch directly :( Should I force-push without my commit and to a PR from outside instead? |
a7664b6 to
c123040
Compare
src/blockdata/opcodes.rs
Outdated
There was a problem hiding this comment.
minor nit(don't fix unless needed): This was also an error in my code. 61 opcodes for Legacy and 60 for Tapscript.
There was a problem hiding this comment.
Fixed since force-push was anyway needed due to end-line space character removal requirement :D
No worries. Looks like I explicitly gave all maintainers the permission to edit it. |
dr-orlovsky
left a comment
There was a problem hiding this comment.
tACK c12304012469aaa307bea2ae35e812e21aa697fd
c123040 to
60ab984
Compare
60ab984 to
c75f3ef
Compare
| | (OP_RESERVED1, ctx) | (OP_RESERVED2, ctx) | ||
| | (OP_VER, ctx) if ctx == ClassifyContext::Legacy => Class::ReturnOp, | ||
|
|
||
| // 71 opcodes operating equally to `OP_RETURN` only in Legacy context |
There was a problem hiding this comment.
Thank you for doing all this counting, but honestly these numbers were originally there so I could check they all added up to 255 -- and now that we have multiple contexts, they don't, so there isn't so much value here :)
Adds support for
CHECKSIGADDandOP_SUCCESSxxx. BIP 342 link for reference https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki#specification .Also makes a minor change to add
INVALIDOPCODE(was previouslyOP_RETURN)