transaction verification – Full record of “particular circumstances” throughout Bitcoin Script execution (p2sh, p2wsh, and many others.)?

0
47


As of January 2021, “high-level” script validation with all lively consensus guidelines on the community is roughly this:

Prime degree analysis

  • Execute the scriptSig, and name the ensuing stack stack. If execution aborts, fail.
  • Execute the scriptPubKey with stack as enter, and name the ensuing stack outcome. If execution aborts, fail.
  • If outcome is empty, or its high ingredient has numerical worth 0, fail.
  • If scriptPubKey is precisely equal to an OP_n (with n between 0 and 16, inclusive) adopted by a direct push of precisely 2 to 40 bytes inclusive:
    • If scriptSig not empty, fail.
    • Run segwit validation with the 2-to-40 byte push in scriptPubKey as program, the n worth as model, and witness as enter (see additional). If this execution aborts, fail.
  • If scriptPubKey is precisely equal to OP_HASH160 + a 20 byte push + OP_EQUAL, run P2SH validation:
    • If scriptSig doesn’t consists of solely pushes, fail.
    • If outcome is empty, fail.
    • Interpret the highest ingredient of outcome as a script, and execute it, with the remainder of outcome as enter. Name the ensuing stack p2sh_result. If this execution aborts, fail.
    • If p2sh_result is empty, or its high ingredient has numerical worth 0, fail.
    • If the highest ingredient of outcome is precisely OP_n (with n between 0 and 16 inclusive) adopted by a direct push of two by means of 40 bytes inclusive:
      • If scriptSig isn’t precisely a direct push of the highest ingredient of outcome, fail.
      • Run segwit validation with the 2-to-40 byte push within the high ingredient of outcome as program, the n worth as model, and witness as enter (see additional). If this execution aborts, fail.
  • If no failure occurred earlier than this level, the enter is legitimate.

Segwit validation

Segwit validation for model model, with program program, and enter enter:

  • If the model is 0:
    • If this system isn’t 20 or 32 bytes, fail.
    • If this system is 20 bytes hash:
      • Execute the script OP_DUP OP_HASH160 hash OP_EQUALVERIFY OP_CHECKSIG, with preliminary stack enter. If execution aborts, fail.
      • If the ensuing stack isn’t precisely one ingredient, or that ingredient has numerical worth 0, fail.
    • If this system is 32 bytes hash:
      • If enter is empty, or its high ingredient’s SHA256 hash doesn’t equal hash, fail.
      • Execute the highest ingredient of enter as script, with the opposite components as enter. If execution aborts, fail.
      • If the ensuing stack isn’t precisely one ingredient, or that ingredient has numerical worth 0, fail.
  • If no failure occurred up up to now, return success.

This reply doesn’t embody the adjustments launched by BIP341 and BIP342, as these should not lively on the community. It additionally doesn’t embody numerous standardness/coverage guidelines.

Supply: https://github.com/bitcoin/bitcoin/blob/v0.20.1/src/script/interpreter.cpp, capabilities VerifyScript, VerifyWitnessProgram, ExecuteWitnessScript.

TL;DR: solely the BIP16 P2SH sample (OP_HASH160 <20 bytes> OP_EQUAL) and the BIP141 segwit sample (OP_n <2 to 40 bytes>) are precise particular circumstances that set off extra guidelines. However the particulars are extra advanced.

LEAVE A REPLY

Please enter your comment!
Please enter your name here