Skip to content

Commit

Permalink
Merge pull request #3810 from nspcc-dev/nested-levels
Browse files Browse the repository at this point in the history
core: fix `too many nesting levels` bug
  • Loading branch information
roman-khimov authored Feb 13, 2025
2 parents 62972eb + 75d1208 commit e05863d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/core/transaction/witness_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func DecodeBinaryCondition(r *io.BinReader) WitnessCondition {
}

func decodeBinaryCondition(r *io.BinReader, maxDepth int) WitnessCondition {
if maxDepth <= 0 {
if maxDepth < 0 {
r.Err = errors.New("too many nesting levels")
return nil
}
Expand Down Expand Up @@ -629,7 +629,7 @@ func UnmarshalConditionJSON(data []byte) (WitnessCondition, error) {
}

func unmarshalConditionJSON(data []byte, maxDepth int) (WitnessCondition, error) {
if maxDepth <= 0 {
if maxDepth < 0 {
return nil, errors.New("too many nesting levels")
}
aux := &conditionAux{}
Expand Down
7 changes: 7 additions & 0 deletions pkg/core/transaction/witness_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func TestWitnessConditionSerDes(t *testing.T) {
{&ConditionAnd{}, false, nil},
{&ConditionOr{}, false, nil},
{&ConditionNot{&ConditionNot{&ConditionNot{(*ConditionBoolean)(&someBool)}}}, false, nil},
{&ConditionAnd{
&ConditionCalledByContract{0x2b, 0xa9, 0x44, 0x44, 0xd4, 0x3c, 0x9a, 0x08, 0x4a, 0x56, 0x60, 0x98, 0x2a, 0x9f, 0x95, 0xf4, 0x3f, 0x07, 0x42, 0x2e},
&ConditionOr{
&ConditionScriptHash{0xd2, 0xa4, 0xcf, 0xf3, 0x19, 0x13, 0x01, 0x61, 0x55, 0xe3, 0x8e, 0x47, 0x4a, 0x2c, 0x06, 0xd0, 0x8b, 0xe2, 0x76, 0xcf},
&ConditionScriptHash{0xef, 0x40, 0x73, 0xa0, 0xf2, 0xb3, 0x05, 0xa3, 0x8e, 0xc4, 0x05, 0x0e, 0x4d, 0x3d, 0x28, 0xbc, 0x40, 0xea, 0x63, 0xf5},
},
}, true, nil},
}
var maxSubCondAnd = &ConditionAnd{}
var maxSubCondOr = &ConditionAnd{}
Expand Down

0 comments on commit e05863d

Please sign in to comment.