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

[BLU-3626] replace start value of i when Regen Address is verified #55

Merged
Merged
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
30 changes: 16 additions & 14 deletions contracts/ToucanRegenBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,22 @@ contract ToucanRegenBridge is Ownable, Pausable, AccessControl {
uint256 accountLen = account.length;
require(accountLen == 44 || accountLen == 64, "regen address must be 44 or 64 chars");

// verification: check address starts with "regen1" prefix
bytes memory prefix = "regen1";
for (uint8 i = 0; i < 6; ++i)
require(prefix[i] == account[i], "regen address must start with 'regen1'");

// verification: check address contains only alphanumeric characters
for (uint64 i = 0; i < accountLen; i++) {
bytes1 char = account[i];
require(
(char >= 0x30 && char <= 0x39) || //9-0
(char >= 0x41 && char <= 0x5A) || //A-Z
(char >= 0x61 && char <= 0x7A), //a-z
"regen address must contain only alphanumeric characters"
);
unchecked {
// verification: check address starts with "regen1" prefix
bytes memory prefix = "regen1";
for (uint8 i = 0; i < 6; ++i)
require(prefix[i] == account[i], "regen address must start with 'regen1'");

// verification: check address contains only alphanumeric characters
for (uint8 i = 6; i < accountLen; ++i) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: isn't it actually cheaper to use uint256 here and in the loop above instead of uint8? It'd be great to run these over gas-reporter.

Copy link
Collaborator Author

@bezerrablockchain bezerrablockchain Feb 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I conducted a small tests using remix and it seems that in newer compiler version using small sized types are using less gas. But I am running same test using gas-reporter as well

bytes1 char = account[i];
require(
(char >= 0x30 && char <= 0x39) || //9-0
(char >= 0x41 && char <= 0x5A) || //A-Z
(char >= 0x61 && char <= 0x7A), //a-z
"regen address must contain only alphanumeric characters"
);
}
}
_;
}
Expand Down