mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00
Remove IsPushOnlyScript from mempool validation (#1492)
* Remove IsPushOnlyScript from mempool validation * Fix TestCheckTransactionStandard
This commit is contained in:
parent
6bc7a4eb85
commit
d30f05b250
@ -192,7 +192,7 @@ const (
|
|||||||
// or to be in compressed format as a 32 byte string prefixed with 0x02 or 0x03 to signal oddness.
|
// or to be in compressed format as a 32 byte string prefixed with 0x02 or 0x03 to signal oddness.
|
||||||
ErrPubKeyFormat
|
ErrPubKeyFormat
|
||||||
|
|
||||||
// ErrCleanStack is returned when after evalution, the stack
|
// ErrCleanStack is returned when after evaluation, the stack
|
||||||
// contains more than one element.
|
// contains more than one element.
|
||||||
ErrCleanStack
|
ErrCleanStack
|
||||||
|
|
||||||
|
@ -84,17 +84,6 @@ func isPushOnly(pops []parsedOpcode) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsPushOnlyScript returns whether or not the passed script only pushes data.
|
|
||||||
//
|
|
||||||
// False will be returned when the script does not parse.
|
|
||||||
func IsPushOnlyScript(script []byte) (bool, error) {
|
|
||||||
pops, err := parseScript(script)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return isPushOnly(pops), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseScriptTemplate is the same as parseScript but allows the passing of the
|
// parseScriptTemplate is the same as parseScript but allows the passing of the
|
||||||
// template list for testing purposes. When there are parse errors, it returns
|
// template list for testing purposes. When there are parse errors, it returns
|
||||||
// the list of parsed opcodes up to the point of failure along with the error.
|
// the list of parsed opcodes up to the point of failure along with the error.
|
||||||
|
@ -3723,6 +3723,17 @@ func TestPushedData(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isPushOnlyScript returns whether or not the passed script only pushes data.
|
||||||
|
//
|
||||||
|
// False will be returned when the script does not parse.
|
||||||
|
func isPushOnlyScript(script []byte) (bool, error) {
|
||||||
|
pops, err := parseScript(script)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return isPushOnly(pops), nil
|
||||||
|
}
|
||||||
|
|
||||||
// TestHasCanonicalPush ensures the canonicalPush function works as expected.
|
// TestHasCanonicalPush ensures the canonicalPush function works as expected.
|
||||||
func TestHasCanonicalPush(t *testing.T) {
|
func TestHasCanonicalPush(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@ -3734,8 +3745,8 @@ func TestHasCanonicalPush(t *testing.T) {
|
|||||||
err)
|
err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if result, _ := IsPushOnlyScript(script); !result {
|
if result, _ := isPushOnlyScript(script); !result {
|
||||||
t.Errorf("IsPushOnlyScript: test #%d failed: %x\n", i,
|
t.Errorf("isPushOnlyScript: test #%d failed: %x\n", i,
|
||||||
script)
|
script)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -3760,8 +3771,8 @@ func TestHasCanonicalPush(t *testing.T) {
|
|||||||
t.Errorf("StandardPushesTests test #%d unexpected error: %v\n", i, err)
|
t.Errorf("StandardPushesTests test #%d unexpected error: %v\n", i, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if result, _ := IsPushOnlyScript(script); !result {
|
if result, _ := isPushOnlyScript(script); !result {
|
||||||
t.Errorf("StandardPushesTests IsPushOnlyScript test #%d failed: %x\n", i, script)
|
t.Errorf("StandardPushesTests isPushOnlyScript test #%d failed: %x\n", i, script)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pops, err := parseScript(script)
|
pops, err := parseScript(script)
|
||||||
@ -3889,9 +3900,9 @@ func TestHasCanonicalPushes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestIsPushOnlyScript ensures the IsPushOnlyScript function returns the
|
// TestIsPushOnly ensures the isPushOnly function returns the
|
||||||
// expected results.
|
// expected results.
|
||||||
func TestIsPushOnlyScript(t *testing.T) {
|
func TestIsPushOnly(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -3922,19 +3933,19 @@ func TestIsPushOnlyScript(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
isPushOnly, err := IsPushOnlyScript(test.script)
|
isPushOnly, err := isPushOnlyScript(test.script)
|
||||||
|
|
||||||
if isPushOnly != test.expectedResult {
|
if isPushOnly != test.expectedResult {
|
||||||
t.Errorf("IsPushOnlyScript (%s) wrong result\ngot: %v\nwant: "+
|
t.Errorf("isPushOnlyScript (%s) wrong result\ngot: %v\nwant: "+
|
||||||
"%v", test.name, isPushOnly, test.expectedResult)
|
"%v", test.name, isPushOnly, test.expectedResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.shouldFail && err == nil {
|
if test.shouldFail && err == nil {
|
||||||
t.Errorf("IsPushOnlyScript (%s) expected an error but got <nil>", test.name)
|
t.Errorf("isPushOnlyScript (%s) expected an error but got <nil>", test.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !test.shouldFail && err != nil {
|
if !test.shouldFail && err != nil {
|
||||||
t.Errorf("IsPushOnlyScript (%s) expected no error but got: %v", test.name, err)
|
t.Errorf("isPushOnlyScript (%s) expected no error but got: %v", test.name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,19 +222,6 @@ func checkTransactionStandard(tx *consensusexternalapi.DomainTransaction, policy
|
|||||||
maxStandardSigScriptSize)
|
maxStandardSigScriptSize)
|
||||||
return txRuleError(RejectNonstandard, str)
|
return txRuleError(RejectNonstandard, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Each transaction input signature script must only contain
|
|
||||||
// opcodes which push data onto the stack.
|
|
||||||
isPushOnly, err := txscript.IsPushOnlyScript(txIn.SignatureScript)
|
|
||||||
if err != nil {
|
|
||||||
str := fmt.Sprintf("transaction input %d: IsPushOnlyScript: %t. Error %s", i, isPushOnly, err)
|
|
||||||
return txRuleError(RejectNonstandard, str)
|
|
||||||
}
|
|
||||||
if !isPushOnly {
|
|
||||||
str := fmt.Sprintf("transaction input %d: signature "+
|
|
||||||
"script is not push only", i)
|
|
||||||
return txRuleError(RejectNonstandard, str)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// None of the output public key scripts can be a non-standard script or
|
// None of the output public key scripts can be a non-standard script or
|
||||||
|
@ -235,18 +235,6 @@ func TestCheckTransactionStandard(t *testing.T) {
|
|||||||
isStandard: false,
|
isStandard: false,
|
||||||
code: RejectNonstandard,
|
code: RejectNonstandard,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "Signature script that does more than push data",
|
|
||||||
tx: consensusexternalapi.DomainTransaction{Version: 0, Inputs: []*consensusexternalapi.DomainTransactionInput{{
|
|
||||||
PreviousOutpoint: dummyPrevOut,
|
|
||||||
SignatureScript: []byte{
|
|
||||||
txscript.OpCheckSigVerify},
|
|
||||||
Sequence: constants.MaxTxInSequenceNum,
|
|
||||||
}}, Outputs: []*consensusexternalapi.DomainTransactionOutput{&dummyTxOut}},
|
|
||||||
height: 300000,
|
|
||||||
isStandard: false,
|
|
||||||
code: RejectNonstandard,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "Valid but non standard public key script",
|
name: "Valid but non standard public key script",
|
||||||
tx: consensusexternalapi.DomainTransaction{Version: 0, Inputs: []*consensusexternalapi.DomainTransactionInput{&dummyTxIn}, Outputs: []*consensusexternalapi.DomainTransactionOutput{{
|
tx: consensusexternalapi.DomainTransaction{Version: 0, Inputs: []*consensusexternalapi.DomainTransactionInput{&dummyTxIn}, Outputs: []*consensusexternalapi.DomainTransactionOutput{{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user