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

stringsEqual can be made more efficient without jeopardizing correctness #15

Open
georgercarder opened this issue Jul 14, 2024 · 0 comments

Comments

@georgercarder
Copy link

georgercarder commented Jul 14, 2024

keccak256(abi.encodePacked(_a)) == keccak256(abi.encodePacked(_b));

This function compares two strings by taking the keccak256 of their abi.encodePacked()ings.

We know the input type of keccak256 is bytes and string is easily converted to bytes by simple casting.

So this comparison can be made where each parameter is digested by keccak256(bytes(PARAM)).

This gives an equivalent correct check and saves gas drastically, as abi.encodePacked is really a superfluous operation here.

Granted, this function may be for validation during "callstatic" svg renderings, but even in that context gas savings may be ideal especially if the rendering of the artwork hits close to the available gas allowance of the queried provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant