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

Handle OP_SUCCESS-like behavior for opcodes like CHECKCONTRACTVERIFY #10

Open
dgpv opened this issue Oct 3, 2023 · 5 comments
Open
Labels
enhancement New feature or request

Comments

@dgpv
Copy link
Owner

dgpv commented Oct 3, 2023

When we know that the upgradable opcode will definitely behave like OP_SUCCESS - when there's no possibility that it will behave as normal, we can stop the execution with a special "SUCCESS" code, rather than simply adding a warning.

This execution path need to be clearly marked in the report as "unconditional success because of SUCCESS-like behavior of upgradable opcode".

(edit)
An example of such opcode is CHECKCONTRACTVERIFY: https://github.com/Merkleize/bitcoin/blob/705dc9e41450edca86413710fc137906f6e5c949/src/script/interpreter.cpp#L1177 -- this is a proposed opcode that is currently not available in bitcoin. Still, if we would like to analyze scripts with opcode that might directly call set_success(), we need to consider how to handle this correctly

@dgpv dgpv added the enhancement New feature or request label Oct 3, 2023
@ajtowns
Copy link

ajtowns commented Oct 15, 2023

Note that OP_SUCCESS behaviour occurs at initial parsing time, before any actual execution. 1 OP_IF OP_RETURN OP_ELSE OP_SUCCESS OP_ENDIF always succeeds, for example. (So there's not really an "execution path" if this is relevant)

@dgpv
Copy link
Owner Author

dgpv commented Oct 15, 2023

I was thinking not about OP_SUCCESS itself, but about a cases where other opcodes can behave like OP_SUCCESS depending on their arguments. For example, upgradable pubkeys in tapscript. Right now, for upgradable pubkeys, there will be a warning, even when it is certain that the pubkey will not have length 32. For these cases, the report needs to show more than just a warning. Correction: upgradeable pubkeys do not entail OP_SUCCESS-like behavior, they just make signature check be successful.

It seems that the title and the first message did not clearly convey the intended meaning. I will edit them.

@dgpv dgpv changed the title Handle cases when OP_SUCCESS behavior for upgradeable opcodes is certain Handle cases when OP_SUCCESS-like behavior for opcodes is certain Oct 15, 2023
@dgpv dgpv changed the title Handle cases when OP_SUCCESS-like behavior for opcodes is certain Handle cases when OP_SUCCESS-like behavior for upgradable opcodes is certain Oct 15, 2023
@dgpv
Copy link
Owner Author

dgpv commented Oct 15, 2023

Regarding OP_SUCCESS itself, bsst do not recognize this opcode: there's no utility in analyzing scripts that contain explicit OP_SUCCESS, for exactly the reason that you have stated.

@ajtowns
Copy link

ajtowns commented Oct 16, 2023

I was thinking not about OP_SUCCESS itself, but about a cases where other opcodes can behave like OP_SUCCESS depending on their arguments. For example, upgradable pubkeys in tapscript.

Upgradable pubkeys isn't much different to setting your pubkey to G -- it's trivial to create a signature that satisfies the pubkey, but it doesn't change the behaviour of the rest of the script.

@dgpv
Copy link
Owner Author

dgpv commented Oct 16, 2023

You're correct, I has mixed up the case of upgradable pubkeys (which only cause their sig check operation to succeed) with the behavior defined for CHECKCONTRACTVERIFY: https://github.com/Merkleize/bitcoin/blob/705dc9e41450edca86413710fc137906f6e5c949/src/script/interpreter.cpp#L1177

That was my mistake, the cases of "upgradable pubkeys" and "undefined values for flags in CCV" are different. For CCV, it actually does set_success(), which should mean the script terminates immediately with success.

There are no currently enabled opcodes which call set_success directly. Maybe doing it for CCV was also not the best decision by the authors, although I don't have enough knowledge to say with certainty what is problematic with such approach of calling set_success from the opcode implementation. It complicates bsst analysis for sure though, by having us to consider this issue :-)

I will edit the title to explicitly mention CCV

@dgpv dgpv changed the title Handle cases when OP_SUCCESS-like behavior for upgradable opcodes is certain Handle OP_SUCCESS-like behavior for opcodes like CHECKCONTRACTVERIFY Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants