Skip to content
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

feat: int cleanup #227

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/helpers/Logger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ library Logger {
}
}

function logUint(uint intToLog) internal view {
function logUint(uint256 intToLog) internal view {
if (block.chainid == 260) {
console.logUint(intToLog);
}
Expand Down
48 changes: 24 additions & 24 deletions src/libraries/JsmnSolLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ library JsmnSolLib {
PRIMITIVE
}

uint constant RETURN_SUCCESS = 0;
uint constant RETURN_ERROR_INVALID_JSON = 1;
uint constant RETURN_ERROR_PART = 2;
uint constant RETURN_ERROR_NO_MEM = 3;
uint256 constant RETURN_SUCCESS = 0;
uint256 constant RETURN_ERROR_INVALID_JSON = 1;
uint256 constant RETURN_ERROR_PART = 2;
uint256 constant RETURN_ERROR_NO_MEM = 3;

struct Token {
JsmnType jsmnType;
uint start;
uint256 start;
bool startSet;
uint end;
uint256 end;
bool endSet;
uint8 size;
}

struct Parser {
uint pos;
uint toknext;
int toksuper;
uint256 pos;
uint256 toknext;
int256 toksuper;
}

function init(uint length) internal pure returns (Parser memory, Token[] memory) {
function init(uint256 length) internal pure returns (Parser memory, Token[] memory) {
Parser memory p = Parser(0, 0, -1);
Token[] memory t = new Token[](length);
return (p, t);
Expand All @@ -68,7 +68,7 @@ library JsmnSolLib {
return (true, token);
}

function fillToken(Token memory token, JsmnType jsmnType, uint start, uint end) internal pure {
function fillToken(Token memory token, JsmnType jsmnType, uint256 start, uint256 end) internal pure {
token.jsmnType = jsmnType;
token.start = start;
token.startSet = true;
Expand All @@ -78,7 +78,7 @@ library JsmnSolLib {
}

function parseString(Parser memory parser, Token[] memory tokens, bytes memory s) internal pure returns (uint) {
uint start = parser.pos;
uint256 start = parser.pos;
bool success;
Token memory token;
parser.pos++;
Expand Down Expand Up @@ -124,7 +124,7 @@ library JsmnSolLib {

function parsePrimitive(Parser memory parser, Token[] memory tokens, bytes memory s) internal pure returns (uint) {
bool found = false;
uint start = parser.pos;
uint256 start = parser.pos;
bool success;
bytes1 c;
Token memory token;
Expand Down Expand Up @@ -155,16 +155,16 @@ library JsmnSolLib {
return RETURN_SUCCESS;
}

function parse(string memory json, uint numberElements) internal pure returns (uint, Token[] memory tokens, uint) {
function parse(string memory json, uint256 numberElements) internal pure returns (uint, Token[] memory tokens, uint) {
bytes memory s = bytes(json);
bool success;
Parser memory parser;
(parser, tokens) = init(numberElements);

// Token memory token;
uint r;
uint count = parser.toknext;
uint i;
uint256 r;
uint256 count = parser.toknext;
uint256 i;
Token memory token;

for (; parser.pos < s.length; parser.pos++) {
Expand Down Expand Up @@ -296,10 +296,10 @@ library JsmnSolLib {
return (RETURN_SUCCESS, tokens, parser.toknext);
}

function getBytes(string memory json, uint start, uint end) internal pure returns (string memory) {
function getBytes(string memory json, uint256 start, uint256 end) internal pure returns (string memory) {
bytes memory s = bytes(json);
bytes memory result = new bytes(end - start);
for (uint i = start; i < end; i++) {
for (uint256 i = start; i < end; i++) {
result[i - start] = s[i];
}
return string(result);
Expand All @@ -311,12 +311,12 @@ library JsmnSolLib {
}

// parseInt(parseFloat*10^_b)
function parseInt(string memory _a, uint _b) internal pure returns (int) {
function parseInt(string memory _a, uint256 _b) internal pure returns (int) {
bytes memory bresult = bytes(_a);
int mint = 0;
int256 mint = 0;
bool decimals = false;
bool negative = false;
for (uint i = 0; i < bresult.length; i++) {
for (uint256 i = 0; i < bresult.length; i++) {
if ((i == 0) && (bresult[i] == "-")) {
negative = true;
}
Expand Down Expand Up @@ -345,9 +345,9 @@ library JsmnSolLib {
function strCompare(string memory _a, string memory _b) internal pure returns (int) {
bytes memory a = bytes(_a);
bytes memory b = bytes(_b);
uint minLength = a.length;
uint256 minLength = a.length;
if (b.length < minLength) minLength = b.length;
for (uint i = 0; i < minLength; i++)
for (uint256 i = 0; i < minLength; i++)
if (a[i] < b[i]) return -1;
else if (a[i] > b[i]) return 1;
if (a.length < b.length) return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/validators/WebAuthValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ contract WebAuthValidator is VerifierCaller, IModuleValidator {

// parse out the important fields (type, challenge, and origin): https://goo.gl/yabPex
// TODO: test if the parse fails for more than 10 elements, otherwise can have a malicious header
(uint returnValue, JsmnSolLib.Token[] memory tokens, uint actualNum) = JsmnSolLib.parse(clientDataJSON, 20);
(uint256 returnValue, JsmnSolLib.Token[] memory tokens, uint256 actualNum) = JsmnSolLib.parse(clientDataJSON, 20);
if (returnValue != 0) {
return false;
}
Expand Down
Loading