Skip to content

Commit

Permalink
Remove NOP1..10 (#1761)
Browse files Browse the repository at this point in the history
  • Loading branch information
constantineatdaglabs authored Jun 20, 2021
1 parent 9bedf84 commit bdd4290
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 441 deletions.
196 changes: 38 additions & 158 deletions domain/consensus/utils/txscript/data/script_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -1216,38 +1216,12 @@
"",
"OK"
],
[
"1",
"NOP1 NOP2 NOP3 NOP4 NOP5 NOP6 NOP7 NOP8 NOP9 NOP10 1 EQUAL",
"",
"OK"
],
[
"'NOP_1_to_10'",
"NOP1 NOP2 NOP3 NOP4 NOP5 NOP6 NOP7 NOP8 NOP9 NOP10 'NOP_1_to_10' EQUAL",
"",
"OK"
],
[
"1",
"NOP",
"DISCOURAGE_UPGRADABLE_NOPS",
"OK",
"Discourage NOPx flag allows OP_NOP"
],
[
"0",
"IF NOP10 ENDIF 1",
"DISCOURAGE_UPGRADABLE_NOPS",
"OK",
"Discouraged NOPs are allowed if not executed"
],
[
"0",
"IF 0xbc ELSE 1 ENDIF",
"IF 0xb2 ELSE 1 ENDIF",
"",
"OK",
"opcodes above NOP10 invalid if executed"
"opcodes above OP_CHECKSEQUENCEVERIFY invalid if executed"
],
[
"0",
Expand Down Expand Up @@ -2187,66 +2161,6 @@
"",
"OK"
],
[
"",
"NOP1 1",
"",
"OK"
],
[
"",
"NOP2 1",
"",
"OK"
],
[
"",
"NOP3 1",
"",
"OK"
],
[
"",
"NOP4 1",
"",
"OK"
],
[
"",
"NOP5 1",
"",
"OK"
],
[
"",
"NOP6 1",
"",
"OK"
],
[
"",
"NOP7 1",
"",
"OK"
],
[
"",
"NOP8 1",
"",
"OK"
],
[
"",
"NOP9 1",
"",
"OK"
],
[
"",
"NOP10 1",
"",
"OK"
],
[
"",
"0 0 CHECKMULTISIG VERIFY DEPTH 0 EQUAL",
Expand Down Expand Up @@ -3761,100 +3675,78 @@
"disabled"
],
[
"0x50",
"1",
"NOP1 NOP2 NOP3 NOP4 NOP5 NOP6 NOP7 NOP8 NOP9 NOP10 2 EQUAL",
"",
"EVAL_FALSE"
],
[
"'NOP_1_to_10'",
"NOP1 NOP2 NOP3 NOP4 NOP5 NOP6 NOP7 NOP8 NOP9 NOP10 'NOP_1_to_11' EQUAL",
"",
"EVAL_FALSE"
],
[
"Ensure 100% coverage of discouraged NOPS"
],
[
"1",
"NOP1",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS"
"BAD_OPCODE",
"opcode 0x50 is reserved"
],
[
"1",
"NOP2",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS"
"IF 0xb2 ELSE 1 ENDIF",
"",
"BAD_OPCODE",
"opcodes above OP_CHECKSEQUENCEVERIFY invalid if executed"
],
[
"1",
"NOP3",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS"
"IF 0xb3 ELSE 1 ENDIF",
"",
"BAD_OPCODE"
],
[
"1",
"NOP4",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS"
"IF 0xb4 ELSE 1 ENDIF",
"",
"BAD_OPCODE"
],
[
"1",
"NOP5",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS"
"IF 0xb5 ELSE 1 ENDIF",
"",
"BAD_OPCODE"
],
[
"1",
"NOP6",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS"
"IF 0xb6 ELSE 1 ENDIF",
"",
"BAD_OPCODE"
],
[
"1",
"NOP7",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS"
"IF 0xb7 ELSE 1 ENDIF",
"",
"BAD_OPCODE"
],
[
"1",
"NOP8",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS"
"IF 0xb8 ELSE 1 ENDIF",
"",
"BAD_OPCODE"
],
[
"1",
"NOP9",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS"
"IF 0xb9 ELSE 1 ENDIF",
"",
"BAD_OPCODE"
],
[
"1",
"NOP10",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS"
],
[
"1 0x01 0xbb",
"BLAKE2B 0x20 0x4324d0dc945c746e3be93be15b636ec1684108806912a479e8a34b2858be114a EQUAL",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS",
"Discouraged NOP10 in redeemScript"
"IF 0xba ELSE 1 ENDIF",
"",
"BAD_OPCODE"
],
[
"0x50",
"1",
"IF 0xbb ELSE 1 ENDIF",
"",
"BAD_OPCODE",
"opcode 0x50 is reserved"
"BAD_OPCODE"
],
[
"1",
"IF 0xbc ELSE 1 ENDIF",
"",
"BAD_OPCODE",
"opcodes above NOP10 invalid if executed"
"BAD_OPCODE"
],
[
"1",
Expand Down Expand Up @@ -4337,12 +4229,6 @@
"SCRIPT_SIZE",
"10,001-byte scriptPubKey"
],
[
"",
"NOP1 NOP10",
"",
"EVAL_FALSE"
],
[
"1",
"VER",
Expand Down Expand Up @@ -4387,10 +4273,10 @@
],
[
"1",
"0xbc",
"0xb2",
"",
"BAD_OPCODE",
"0xbc == OP_NOP10 + 1"
"0xb2 == OP_CHECKSEQUENCEVERIFY + 1"
],
[
"2147483648",
Expand Down Expand Up @@ -4847,12 +4733,6 @@
"SIG_PUSHONLY",
"Tests for Script.IsPushOnly()"
],
[
"NOP1 0x01 1",
"BLAKE2B 0x20 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b EQUAL",
"",
"SIG_PUSHONLY"
],
[
"0 0x01 0x50",
"BLAKE2B 0x20 0xece424a6bb6ddf4db592c0faed60685047a361b1 EQUAL",
Expand Down
8 changes: 0 additions & 8 deletions domain/consensus/utils/txscript/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ type ScriptFlags uint32
const (
// ScriptNoFlags is used when you want to use ScriptFlags without raising any flags
ScriptNoFlags ScriptFlags = 0

// ScriptDiscourageUpgradableNops defines whether to verify that
// NOP1 through NOP10 are reserved for future soft-fork upgrades. This
// flag must not be used for consensus critical code nor applied to
// blocks as this flag is only for stricter standard transaction
// checks. This flag is only applied when the above opcodes are
// executed.
ScriptDiscourageUpgradableNops ScriptFlags = 1 << iota
)

const (
Expand Down
84 changes: 39 additions & 45 deletions domain/consensus/utils/txscript/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,6 @@ const (
// Failures related to soft forks.
// -------------------------------

// ErrDiscourageUpgradableNOPs is returned when the
// ScriptDiscourageUpgradableNops flag is set and a NOP opcode is
// encountered in a script.
ErrDiscourageUpgradableNOPs

// ErrNegativeLockTime is returned when a script contains an opcode that
// interprets a negative lock time.
ErrNegativeLockTime
Expand All @@ -226,46 +221,45 @@ const (

// Map of ErrorCode values back to their constant names for pretty printing.
var errorCodeStrings = map[ErrorCode]string{
ErrInternal: "ErrInternal",
ErrInvalidFlags: "ErrInvalidFlags",
ErrInvalidIndex: "ErrInvalidIndex",
ErrUnsupportedAddress: "ErrUnsupportedAddress",
ErrNotMultisigScript: "ErrNotMultisigScript",
ErrTooManyRequiredSigs: "ErrTooManyRequiredSigs",
ErrEarlyReturn: "ErrEarlyReturn",
ErrEmptyStack: "ErrEmptyStack",
ErrEvalFalse: "ErrEvalFalse",
ErrScriptUnfinished: "ErrScriptUnfinished",
ErrInvalidProgramCounter: "ErrInvalidProgramCounter",
ErrScriptTooBig: "ErrScriptTooBig",
ErrElementTooBig: "ErrElementTooBig",
ErrTooManyOperations: "ErrTooManyOperations",
ErrStackOverflow: "ErrStackOverflow",
ErrInvalidPubKeyCount: "ErrInvalidPubKeyCount",
ErrInvalidSignatureCount: "ErrInvalidSignatureCount",
ErrNumberTooBig: "ErrNumberTooBig",
ErrVerify: "ErrVerify",
ErrEqualVerify: "ErrEqualVerify",
ErrNumEqualVerify: "ErrNumEqualVerify",
ErrCheckSigVerify: "ErrCheckSigVerify",
ErrCheckMultiSigVerify: "ErrCheckMultiSigVerify",
ErrDisabledOpcode: "ErrDisabledOpcode",
ErrReservedOpcode: "ErrReservedOpcode",
ErrMalformedPush: "ErrMalformedPush",
ErrInvalidStackOperation: "ErrInvalidStackOperation",
ErrUnbalancedConditional: "ErrUnbalancedConditional",
ErrMinimalData: "ErrMinimalData",
ErrInvalidSigHashType: "ErrInvalidSigHashType",
ErrSigLength: "ErrSigLength",
ErrSigHighS: "ErrSigHighS",
ErrNotPushOnly: "ErrNotPushOnly",
ErrPubKeyFormat: "ErrPubKeyFormat",
ErrCleanStack: "ErrCleanStack",
ErrNullFail: "ErrNullFail",
ErrDiscourageUpgradableNOPs: "ErrDiscourageUpgradableNOPs",
ErrNegativeLockTime: "ErrNegativeLockTime",
ErrUnsatisfiedLockTime: "ErrUnsatisfiedLockTime",
ErrMinimalIf: "ErrMinimalIf",
ErrInternal: "ErrInternal",
ErrInvalidFlags: "ErrInvalidFlags",
ErrInvalidIndex: "ErrInvalidIndex",
ErrUnsupportedAddress: "ErrUnsupportedAddress",
ErrNotMultisigScript: "ErrNotMultisigScript",
ErrTooManyRequiredSigs: "ErrTooManyRequiredSigs",
ErrEarlyReturn: "ErrEarlyReturn",
ErrEmptyStack: "ErrEmptyStack",
ErrEvalFalse: "ErrEvalFalse",
ErrScriptUnfinished: "ErrScriptUnfinished",
ErrInvalidProgramCounter: "ErrInvalidProgramCounter",
ErrScriptTooBig: "ErrScriptTooBig",
ErrElementTooBig: "ErrElementTooBig",
ErrTooManyOperations: "ErrTooManyOperations",
ErrStackOverflow: "ErrStackOverflow",
ErrInvalidPubKeyCount: "ErrInvalidPubKeyCount",
ErrInvalidSignatureCount: "ErrInvalidSignatureCount",
ErrNumberTooBig: "ErrNumberTooBig",
ErrVerify: "ErrVerify",
ErrEqualVerify: "ErrEqualVerify",
ErrNumEqualVerify: "ErrNumEqualVerify",
ErrCheckSigVerify: "ErrCheckSigVerify",
ErrCheckMultiSigVerify: "ErrCheckMultiSigVerify",
ErrDisabledOpcode: "ErrDisabledOpcode",
ErrReservedOpcode: "ErrReservedOpcode",
ErrMalformedPush: "ErrMalformedPush",
ErrInvalidStackOperation: "ErrInvalidStackOperation",
ErrUnbalancedConditional: "ErrUnbalancedConditional",
ErrMinimalData: "ErrMinimalData",
ErrInvalidSigHashType: "ErrInvalidSigHashType",
ErrSigLength: "ErrSigLength",
ErrSigHighS: "ErrSigHighS",
ErrNotPushOnly: "ErrNotPushOnly",
ErrPubKeyFormat: "ErrPubKeyFormat",
ErrCleanStack: "ErrCleanStack",
ErrNullFail: "ErrNullFail",
ErrNegativeLockTime: "ErrNegativeLockTime",
ErrUnsatisfiedLockTime: "ErrUnsatisfiedLockTime",
ErrMinimalIf: "ErrMinimalIf",
}

// String returns the ErrorCode as a human-readable name.
Expand Down
Loading

0 comments on commit bdd4290

Please sign in to comment.