code-423n4 / 2023-06-canto-findings

1 stars 0 forks source link

Invalid Validation of Auto Swap Threshold #15

Closed code423n4 closed 1 year ago

code423n4 commented 1 year ago

Lines of code

https://github.com/code-423n4/2023-06-canto/blob/main/Canto/x/onboarding/types/params.go#L75

Vulnerability details

Impact

The bug in the contract leads to incorrect validation of the autoSwapThreshold parameter. This has the following impacts:

It is crucial to address this bug by correcting the validation logic to ensure the autoSwapThreshold parameter is properly validated as a positive value.

Proof of Concept

This contract implements a contract package for managing parameters. , I identified a bug related to the validation of the autoSwapThreshold field. The bug allows a negative value to be considered valid, which contradicts the intended behavior of the code.

Steps to Reproduce:

1 . Set a negative value for the autoSwapThreshold parameter. 2 . Call the Validate function on the Params struct.

Additional Details:

The bug is located in the validateAutoSwapThreshold function, which is responsible for validating the autoSwapThreshold parameter. The function attempts to type-assert the input value (i) as an sdk.Int. However, the assertion check is incorrect, leading to the bug. The correct type assertion should be v, ok := i.(*sdk.Int) instead of v, ok := i.(sdk.Int).

Proposed Fix:

To fix the bug, the validateAutoSwapThreshold function should be modified as follows:

func validateAutoSwapThreshold(i interface{}) error { v, ok := i.(*sdk.Int) if !ok { return fmt.Errorf("invalid parameter type: %T", i) }

if v.IsNegative() {
    return fmt.Errorf("auto swap threshold must be positive: %s", v.String())
}

return nil

}

After applying this fix, the validateAutoSwapThreshold function will correctly validate the autoSwapThreshold parameter and ensure that it is a positive value.

Assessed type

Invalid Validation

c4-pre-sort commented 1 year ago

JeffCX marked the issue as low quality report

JeffCX commented 1 year ago

This requires very significant admin misconfiguration, QA

c4-judge commented 1 year ago

0xean changed the severity to QA (Quality Assurance)

c4-judge commented 1 year ago

0xean marked the issue as grade-b