-
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
Closed
gsteenkamp89
wants to merge
41
commits into
gerhard/uma-2547-adding-unsupported-treasury-crashes-proposal-page
from
validation-fixes
Closed
Validation fixes #161
gsteenkamp89
wants to merge
41
commits into
gerhard/uma-2547-adding-unsupported-treasury-crashes-proposal-page
from
validation-fixes
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
gsteenkamp89
commented
Apr 12, 2024
gsteenkamp89
commented
Apr 12, 2024
gsteenkamp89
commented
Apr 12, 2024
Comment on lines
+187
to
+220
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
gsteenkamp89
commented
Apr 12, 2024
daywiss
reviewed
Apr 12, 2024
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
daywiss
approved these changes
Apr 19, 2024
gsteenkamp89
changed the base branch from
master
to
gerhard/uma-2547-adding-unsupported-treasury-crashes-proposal-page
April 19, 2024 10:59
…oposal-page' into validation-fixes
Co-authored-by: ChaituVR <ChaituVR@users.noreply.github.com>
Co-authored-by: Den Smalonski <dzianis.smalonski@protofire.io>
* fix: Privacy label name for any option * lower case
Co-authored-by: ChaituVR <ChaituVR@users.noreply.github.com>
Co-authored-by: ChaituVR <ChaituVR@users.noreply.github.com>
Co-authored-by: ChaituVR <ChaituVR@users.noreply.github.com>
Co-authored-by: ChaituVR <ChaituVR@users.noreply.github.com>
* fix: Add created_gt filter to aliases query * Use spread operator
Co-authored-by: ChaituVR <ChaituVR@users.noreply.github.com>
Co-authored-by: ChaituVR <ChaituVR@users.noreply.github.com>
* 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 <ChaituVR@users.noreply.github.com>
Co-authored-by: ChaituVR <ChaituVR@users.noreply.github.com>
Co-authored-by: ChaituVR <ChaituVR@users.noreply.github.com>
Merged upstream |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.