Skip to content

Commit

Permalink
improve the implementation for 12. missing validation of parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
larry0x committed Aug 30, 2023
1 parent 88f3fe5 commit d1b955b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions x/abstractaccount/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ func (p *Params) Validate() error {
}

// allowed list must contain non-zero, unique, and sorted code IDs
prev := uint64(0)
prevCodeID := uint64(0)
for _, codeID := range p.AllowedCodeIDs {
if codeID == 0 {
if prevCodeID >= codeID {
return ErrMalformedAllowList
}

if prev >= codeID {
return ErrMalformedAllowList
}

prev = codeID
prevCodeID = codeID
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion x/abstractaccount/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestValidateParams(t *testing.T) {
desc: "allow list contains zero code ID",
params: &types.Params{
AllowAllCodeIDs: false,
AllowedCodeIDs: []uint64{1, 0, 3},
AllowedCodeIDs: []uint64{0, 1, 2},
MaxGasBefore: types.DefaultMaxGas,
MaxGasAfter: types.DefaultMaxGas,
},
Expand Down

0 comments on commit d1b955b

Please sign in to comment.