Skip to content

bitcoin-util evalscript subcommand - #58

Merged
ajtowns merged 6 commits into
bitcoin-inquisition:27.xfrom
ajtowns:202405-inq27-evalscript
May 17, 2024
Merged

ajtowns merged 6 commits into
bitcoin-inquisition:27.xfrom
ajtowns:202405-inq27-evalscript

Conversation

@ajtowns

@ajtowns ajtowns commented May 8, 2024 •

Copy link
Copy Markdown

Introduces an evalscript subcommand for bitcoin-util that evaluates a script directly.

Relies on upstream PRs bitcoin#28802 and bitcoin#28806.

Example:

$ ./bitcoin-util evalscript '515293'
{
  "script": {
    "asm": "1 2 OP_ADD",
    "hex": "515293",
    "type": "nonstandard"
  },
  "sigversion": "witness_v0",
  "script_flags":  [
    "CHECKLOCKTIMEVERIFY",
    "CHECKSEQUENCEVERIFY",
    "DERSIG",
    "NULLDUMMY",
    "P2SH",
    "TAPROOT,WITNESS"
  ],
  "stack-after": [
    "03"
  ],
  "sigop-count": 0,
  "success": true
}

Provides --sigversion (base, witness_v0 or tapscript) to select different script versions, and --script_flags to enable the various script flags, eg:

$ ./bitcoin-util --sigversion=tapscript --script_flags=OP_CAT evalscript '51527e'
{
  "script": {
    "asm": "1 2 OP_CAT",
    "hex": "51527e",
    "type": "nonstandard"
  },
  "sigversion": "tapscript",
  "script_flags": [
    "OP_CAT"
  ],
  "stack-after": [
    "0102"
  ],
  "sigop-count": 0,
  "success": true
}

@ajtowns
ajtowns force-pushed the 202405-inq27-evalscript branch 5 times, most recently from 9441cd1 to c171271 Compare May 9, 2024 05:41
@ajtowns

ajtowns commented May 9, 2024

Copy link
Copy Markdown
Author

I think the signature checking is usable now:

$ ./bitcoin-util --sigversion=tapscript \
  --tx=02000000000101d1b5f18e8dcbaaa382b398a578f968e69fd72176768ccd4649a06491beb713310000000000e0070000012c4c000000000000225120fb4ea97f00be442dac392022a0c6b813f01881aa2fc006aaa225495365af68f30340ec3517b63e035c22f3659bfd30b9f440049b697a8d1cb8ef721658d683fa66c6c3f598d25682381c43fba7c94b5f994537041960d0c0e8c596fdcc1170b241c826201bd43c4c240e0244871afe0650bdbedb13780a9d0644c4aa2398f46f20f46130ad02e007b261c050929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0614534a82971ff9ddda889c53b1e2ec43baa9db27da7d6c49b4121c18756c28dcc2dea9ee4098432b2c61221c4bfbc793f5ecdd2d42d3544a0146ae693c5493d00000000 \
  --input=0 \
  --spent_output=204e000000000000225120bc2d293f6482e242e12330379bb255f9f2f853a25ec19ed40f54a149c3af6315 \
  --ipk=50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0 \
  --script_flags=STANDARD \
  evalscript \
  '0x201bd43c4c240e0244871afe0650bdbedb13780a9d0644c4aa2398f46f20f46130 OP_CHECKSIGVERIFY 2016 OP_CHECKSEQUENCEVERIFY' \
  'ec3517b63e035c22f3659bfd30b9f440049b697a8d1cb8ef721658d683fa66c6c3f598d25682381c43fba7c94b5f994537041960d0c0e8c596fdcc1170b241c8'  
{
  "script": {
    "asm": "1bd43c4c240e0244871afe0650bdbedb13780a9d0644c4aa2398f46f20f46130 OP_CHECKSIGVERIFY 2016 OP_CHECKSEQUENCEVERIFY",
    "hex": "201bd43c4c240e0244871afe0650bdbedb13780a9d0644c4aa2398f46f20f46130ad02e007b2",
    "type": "nonstandard"
  },
  "sigversion": "tapscript",
  "script_flags": [
    "ANYPREVOUT",
    "CHECKLOCKTIMEVERIFY",
    "CHECKSEQUENCEVERIFY",
    "CLEANSTACK",
    "CONST_SCRIPTCODE",
    "DEFAULT_CHECK_TEMPLATE_VERIFY_HASH",
    "DERSIG",
    "DISCOURAGE_OP_SUCCESS",
    "DISCOURAGE_UPGRADABLE_CHECK_TEMPLATE_VERIFY_HASH",
    "DISCOURAGE_UPGRADABLE_NOPS",
    "DISCOURAGE_UPGRADABLE_PUBKEYTYPE",
    "DISCOURAGE_UPGRADABLE_TAPROOT_VERSION",
    "DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM",
    "LOW_S",
    "MINIMALDATA",
    "MINIMALIF",
    "NULLDUMMY",
    "NULLFAIL",
    "OP_CAT",
    "P2SH",
    "STRICTENC",
    "TAPROOT",
    "WITNESS",
    "WITNESS_PUBKEYTYPE"
  ],
  "stack-after": [
    "e007"
  ],
  "sigop-count": 0,
  "success": true
}

(Taken from tx 928f9e4c445d2f67d44a29600bf48616aa16797e9d0b8a9ef81532358a6211e7 on signet)

@ajtowns
ajtowns marked this pull request as ready for review May 9, 2024 05:54
@ajtowns

ajtowns commented May 9, 2024 •

Copy link
Copy Markdown
Author

CHECKSIG doesn't work if you don't specify the various options, and CSV/CLTV don't work unless you specify a tx that actually satisfies the constraints. Might be good to grab the DummySignatureChecker from script/sign.cpp and use that when the --tx etc args aren't specified.

EDIT: now done

@ajtowns ajtowns added this to the 27.x milestone May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant