crytic / properties

Pre-built security properties for common Ethereum operations
GNU Affero General Public License v3.0
287 stars 44 forks source link

[Bug-Candidate]: Rename "clamp" to avoid confusion #49

Open CodeSandwich opened 11 months ago

CodeSandwich commented 11 months ago

Describe the issue:

The state

There's a set of functions in contracts/util/PropertiesHelper.sol named clamp... for making numbers fit in a fixed range by performing modulo. For example using such function to put numbers 0-10 in the range 4-6 will result in:

in:  0 1 2 3 4 5 6 7 8 9 10
out: 6 4 5 6 4 5 6 4 5 6 4

The problem

In the programming nomenclature the term "clamp" usually refers to putting number in a fixed range by assigning it the value of the boundary, if that boundary is exceeded. For example clamping numbers 0-10 in the range 4-6 would result in:

in:  0 1 2 3 4 5 6 7 8 9 10
out: 4 4 4 4 4 5 6 6 6 6 6

I'm writing this based on my experience, I got really confused when I saw PropertyHelper's clamp... functions in use for the first time. I checked my expectations by searching on the internet for "clamp a number", and all the resources were referring to "clamping" as assigning the exceeded boundary, not calculating the modulo. I think that many developers using PropertiesHelper for the first time will be confused or misled.

The solution

I think that the clamp... functions should be renamed to something less confusing. For example the name wrap... could be good, it would reflect how numbers exceeding the limit are returning into the range on the other end.

Steps to reproduce the issue:

Write code using PropertiesHelper.

If additional code is needed for reproducing, please copy it here, or drop us a link to the repository:

No response

Echidna version:

All of them.

Additional information:

No response