-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation fixes #161
base: gerhard/uma-2547-adding-unsupported-treasury-crashes-proposal-page
Are you sure you want to change the base?
Validation fixes #161
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
function isValidInt(value: string, type: Integer) { | ||
// check if is number like | ||
if (!isBigNumberish(value)) { | ||
return false; | ||
} | ||
|
||
const unsigned = type.startsWith('uint'); | ||
const signed = type.startsWith('int'); | ||
if (!unsigned && !signed) { | ||
throw new Error( | ||
'Invalid type specified. Type must be either an unsigned integer (uint) or a signed integer (int).' | ||
); | ||
} | ||
|
||
const bits = parseInt(type.slice(unsigned ? 4 : 3)); | ||
|
||
if (isNaN(bits) || bits % 8 !== 0 || bits < 8 || bits > 256) { | ||
throw new Error( | ||
'Invalid integer type specified. Bit size must be a multiple of 8 with a max of 256' | ||
); | ||
} | ||
|
||
const number = BigNumber.from(value); | ||
// range checks | ||
if (unsigned) { | ||
const max = BigNumber.from(2).pow(bits).sub(1); | ||
return number.gte(0) && number.lte(max); | ||
} else { | ||
const halfRange = BigNumber.from(2).pow(bits - 1); | ||
const min = halfRange.mul(-1); | ||
const max = halfRange.sub(1); | ||
return number.gte(min) && number.lte(max); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validation for Integers.
- check if number
- check number is within range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will spend more time on this monday
…oposal-page' into validation-fixes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: ChaituVR <[email protected]>
Co-authored-by: Den Smalonski <[email protected]>
* fix: Privacy label name for any option * lower case
Co-authored-by: ChaituVR <[email protected]>
Co-authored-by: ChaituVR <[email protected]>
Co-authored-by: ChaituVR <[email protected]>
Co-authored-by: ChaituVR <[email protected]>
* fix: Add created_gt filter to aliases query * Use spread operator
Co-authored-by: ChaituVR <[email protected]>
Co-authored-by: ChaituVR <[email protected]>
* feat: Boost reward to winning option * Change text
* feat: add `network` params to follow/unfollow sign * fix: use different default network depending on env
Co-authored-by: ChaituVR <[email protected]>
Co-authored-by: ChaituVR <[email protected]>
Co-authored-by: ChaituVR <[email protected]>
rebase too time consuming, commits cherry-picked from original PR
motivation
Currently our transaction builder is not parsing or validating array or tuple param types AT ALL!
This PR seeks to properly parse array inputs and validate members of those arrays.
both
array
andtuple
inputs require an array (square brackets) in the input field.but
array
param members are always the same type so if the type isuint256[]
then we validate each member of teh array as auint156
but tuples are more complex since they generally represent struct values, so a tuple's type can be
[uint256,address,bool]
To test
requestPrice
requestSettings
, the tuple type is[bool,bool,bool,Int,Int]
Or find any ABI with function parameters of type Array or Tuple and test the input.
@daywiss I've added better checks for Integers as well. We now do range checks for all integer types. I noticed this bug because I was able to insert values for
uint32
that were out of bounds and the app didn't catch it.