Skip to content

Commit

Permalink
remove ECDSA verification from CSFSV
Browse files Browse the repository at this point in the history
  • Loading branch information
reardencode committed Apr 25, 2024
1 parent 359ce6c commit 9ddaa2c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 37 deletions.
19 changes: 0 additions & 19 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,25 +371,6 @@ static bool EvalChecksigFromStack(const valtype& sig, const valtype& msg, const
XOnlyPubKey pubkey{pubkey_in};

if (!pubkey.VerifySchnorr(msg, sig)) return set_error(serror, SCRIPT_ERR_SCHNORR_SIG);
} else if (pubkey_in.size() == 33 && (pubkey_in[0] == 0x02 || pubkey_in[0] == 0x03) && (sigversion == SigVersion::BASE || sigversion == SigVersion::WITNESS_V0)) {
// Pubkeys of length 33 are only constrained in legacy and segwitv0. In these script types only those beginning
// with 0x02 or 0x03 are constrained. Others are unknown pubkey types.
if (!success) return true;

// Add sighash flag to pass format validation
valtype vchSig{sig.begin(), sig.begin() + sig.size()};
vchSig.emplace_back(SIGHASH_ALL);
if (!CheckSignatureEncoding(vchSig, flags | SCRIPT_VERIFY_LOW_S, serror)) {
// serror is set
return false;
}

if (msg.size() != 32) return set_error(serror, SCRIPT_ERR_INVALID_DATA_LENGTH);

CPubKey pubkey(pubkey_in);
if (!pubkey.IsValid()) return set_error(serror, SCRIPT_ERR_PUBKEYTYPE);

if (!pubkey.Verify(uint256(msg), sig)) return set_error(serror, SCRIPT_ERR_SIG_NULLFAIL);
} else {
/*
* New public key version softforks should be defined before this `else` block.
Expand Down
2 changes: 0 additions & 2 deletions src/script/script_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ std::string ScriptErrorString(const ScriptError serror)
return "OP_RETURN was encountered";
case SCRIPT_ERR_UNBALANCED_CONDITIONAL:
return "Invalid OP_IF construction";
case SCRIPT_ERR_INVALID_DATA_LENGTH:
return "Invalid data length for operation";
case SCRIPT_ERR_NEGATIVE_LOCKTIME:
return "Negative locktime";
case SCRIPT_ERR_UNSATISFIED_LOCKTIME:
Expand Down
1 change: 0 additions & 1 deletion src/script/script_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ typedef enum ScriptError_t
SCRIPT_ERR_INVALID_STACK_OPERATION,
SCRIPT_ERR_INVALID_ALTSTACK_OPERATION,
SCRIPT_ERR_UNBALANCED_CONDITIONAL,
SCRIPT_ERR_INVALID_DATA_LENGTH,

/* CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY */
SCRIPT_ERR_NEGATIVE_LOCKTIME,
Expand Down
6 changes: 3 additions & 3 deletions src/test/data/tx_invalid.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,12 @@
155000]],
"0200000000010197e5046ea9335a2ce209f677f0d0a303cd266461ff42316f73c53360a92f52a20000000000ffffffff01f04902000000000022512040104c71081b266fdf4008db8b0a1c3291f2e1cb680753936de9b76dac45a6ef0340b5258eeb9df148d499d14b8e23fe5315a230b7f1dee497a04605426ffe068f2e0920c9b63ba28b1c6cea39c0e659af1658825d23e859c5ae773a0be996f1c4744520feadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef204835c505a762f5e55c2e8eda1c05437d973809a0236178510208a6ac3f7632bfcc008721c050929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac000000000",
"P2SH,WITNESS,TAPROOT,CHECKSIGFROMSTACK"],
["Test OP_CHECKSIGFROMSTACKVERIFY ECDSA, fails for small data"],
["Test OP_CHECKSIGFROMSTACKVERIFY fails with sig for wrong data"],
[[["a2522fa96033c5736f3142ff616426cd03a3d0f077f609e22c5a33a96e04e597",
0,
"0 0x20 0xa0bf5dba5465c2ad955eb0bec70fa18a40c7584b2ab064168c4824b35dd034b1",
"0 0x20 0x1668c36ebff165b0ca132d821ee4980e6fc7a8a2e0553efb7bb3f176b58acf70",
155000]],
"0200000000010197e5046ea9335a2ce209f677f0d0a303cd266461ff42316f73c53360a92f52a20000000000ffffffff01f04902000000000022512040104c71081b266fdf4008db8b0a1c3291f2e1cb680753936de9b76dac45a6ef0246304402207b76769769f17f10d4dfe7a2f4de969542aa845ae15347d299fb434fa0d64b8b02207412523f0797d43704b47b21d0bfb85e1bff5354dabb483d2eb9c349051f05fe3611636865636b73696766726f6d737461636b21024835c505a762f5e55c2e8eda1c05437d973809a0236178510208a6ac3f7632bfb46d00000000",
"0200000000010197e5046ea9335a2ce209f677f0d0a303cd266461ff42316f73c53360a92f52a20000000000ffffffff01f049020000000000225120dfb6463daf8d5604ac6bf89db279af0eaf938fbd51c0aaa95723350d9138a46d02402c768087db59d9ba37e53c7c1010a5e7502d532f219b711b9d12305df02401a1b7fa63087e004c0f78afe93e3f106999ccff6390c58b6eed56f2d402c195702c4420feadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef2014e372138fe7a6722c57b82e060962efcde14ec5992a22ac034c27fa90dd5cd6b46d00000000",
"P2SH,WITNESS,CHECKSIGFROMSTACK"],

["Make diffs cleaner by leaving a comment here without comma at the end"]
Expand Down
17 changes: 5 additions & 12 deletions src/test/data/tx_valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,6 @@
"1 0x20 0x26eb744004735dd8b2ef8a3e99bb473da3eee33762fed358adc04c527f378310",
155000]],
"02000000000101d58631133c4d4f6188abbd0fa0a7aa64bfde05ce4297e3349b38599ceebaf2e20000000000ffffffff01f0490200000000002251203408099b8f38a71ab6dfafdf0b266bd0a0f58096b5c453624c752bae6c0f19560340cd3e61f2754dd13e51a6d86d18092f795c626d36deaf0cf076a87648d9f4e4cfceaaa8e8a7eee1ee13dd09ef2c14eedd475f4e9adcf8a2391b910271b2203aa24420deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef208fdb638cf9201fcae809f31b7d5b5ef9ae712cd374c8c89b06d52b9d2c3885bfb46d21c050929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac000000000",
"DISCOURAGE_CHECKSIGFROMSTACK"],
["Test P2WSH OP_CHECKSIGFROMSTACKVERIFY"],
[[["e2f2baee9c59389b34e39742ce05debf64aaa7a00fbdab88614f4d3c133186d5",
0,
"0 0x20 0x83fa00d8773b2f1815c6d89098b20804e971aafcb537e6b83f6aa5d2e51bcb52",
155000]],
"02000000000101d58631133c4d4f6188abbd0fa0a7aa64bfde05ce4297e3349b38599ceebaf2e20000000000ffffffff01f0490200000000002251203408099b8f38a71ab6dfafdf0b266bd0a0f58096b5c453624c752bae6c0f195602463044022012309adbc1507fa077108439f9d0dc2c959cb3ca084bd39ea9319f98092fb5bd022061ca05a15a97ebc4cd921dde9ee521579852d3ceb0cc926b8b1d0ae580a014444520deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef21038fdb638cf9201fcae809f31b7d5b5ef9ae712cd374c8c89b06d52b9d2c3885bfb46d00000000",
"DISCOURAGE_CHECKSIGFROMSTACK"],
["Test P2WSH OP_CHECKSIGFROMSTACKVERIFY BIP340"],
[[["e2f2baee9c59389b34e39742ce05debf64aaa7a00fbdab88614f4d3c133186d5",
Expand All @@ -576,19 +569,19 @@
155000]],
"02000000000101d58631133c4d4f6188abbd0fa0a7aa64bfde05ce4297e3349b38599ceebaf2e20000000000ffffffff01f0490200000000002251203408099b8f38a71ab6dfafdf0b266bd0a0f58096b5c453624c752bae6c0f195602403c5a935ce7a3856bc3e75eae403a21ff2e5a9f919c0f6f4d6bf7f58c834c13484882fc6f98587fe48e6945a49c0ca4fc62fb5f641a216ea62ac2dbc0071976833511636865636b73696766726f6d737461636b208fdb638cf9201fcae809f31b7d5b5ef9ae712cd374c8c89b06d52b9d2c3885bfb46d00000000",
"DISCOURAGE_CHECKSIGFROMSTACK"],
["Test P2SH OP_CHECKSIGFROMSTACKVERIFY"],
["Test P2SH OP_CHECKSIGFROMSTACKVERIFY BIP340"],
[[["e2f2baee9c59389b34e39742ce05debf64aaa7a00fbdab88614f4d3c133186d5",
0,
"OP_HASH160 0x14 0x4cb7d0b6053798a67632c8ed8bc3372e6f01b17e OP_EQUAL",
"OP_HASH160 0x14 0xab63e1e6ba40acfcc58dc31d0458264e977b8605 OP_EQUAL",
155000]],
"0200000001d58631133c4d4f6188abbd0fa0a7aa64bfde05ce4297e3349b38599ceebaf2e2000000008d463044022012309adbc1507fa077108439f9d0dc2c959cb3ca084bd39ea9319f98092fb5bd022061ca05a15a97ebc4cd921dde9ee521579852d3ceb0cc926b8b1d0ae580a014444520deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef21038fdb638cf9201fcae809f31b7d5b5ef9ae712cd374c8c89b06d52b9d2c3885bfb46dffffffff01f0490200000000002251203408099b8f38a71ab6dfafdf0b266bd0a0f58096b5c453624c752bae6c0f195600000000",
"0200000001d58631133c4d4f6188abbd0fa0a7aa64bfde05ce4297e3349b38599ceebaf2e2000000008640ac0205291ba90c62363093fc70c1088466dc69ee10f59daf785c20766885b6c2bf9ff0d0eca73f09bbff97a79c829253611073dc014d2a63ecfe2f1b6c86f7354420deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef2032f46ec18b34a835141c1a48aa033129f46cb1523e288539af40ea3aaacd1e25b46dffffffff01f0490200000000002251206542cc4bfbe60ebaeec8a927bb37cf27ead2de944e10b1f5169936a90e8749dd00000000",
"DISCOURAGE_CHECKSIGFROMSTACK"],
["Test bare OP_CHECKSIGFROMSTACKVERIFY"],
[[["e2f2baee9c59389b34e39742ce05debf64aaa7a00fbdab88614f4d3c133186d5",
0,
"0x20 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef 0x21 0x03193c33954240709ded920960a9f7a740baac76a947ab75ea7ad52ae0e7756043 OP_CHECKSIGFROMSTACKVERIFY OP_2DROP",
"0x20 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef 0x20 0x32f46ec18b34a835141c1a48aa033129f46cb1523e288539af40ea3aaacd1e25 OP_CHECKSIGFROMSTACKVERIFY OP_2DROP",
155000]],
"0200000001d58631133c4d4f6188abbd0fa0a7aa64bfde05ce4297e3349b38599ceebaf2e20000000047463044022046b9abc584ad1e04419e8f2e7e9ab1bdac5c42fa0936b488525289135d347e1802206117872a3da184fc4b43ea50c33426bb8f01dd8102eff7a596b7063c6625a8d6ffffffff01f0490200000000002251202ca3bc76489a54904ad2507005789afc1e6b362b451be89f69de39ddf9ba8abf00000000",
"0200000001d58631133c4d4f6188abbd0fa0a7aa64bfde05ce4297e3349b38599ceebaf2e2000000004140ac0205291ba90c62363093fc70c1088466dc69ee10f59daf785c20766885b6c2bf9ff0d0eca73f09bbff97a79c829253611073dc014d2a63ecfe2f1b6c86f735ffffffff01f0490200000000002251202ca3bc76489a54904ad2507005789afc1e6b362b451be89f69de39ddf9ba8abf00000000",
"DISCOURAGE_CHECKSIGFROMSTACK"],

["Make diffs cleaner by leaving a comment here without comma at the end"]
Expand Down

0 comments on commit 9ddaa2c

Please sign in to comment.