Created
March 20, 2023 16:46
-
-
Save CJ42/476885820f156066b4ae0e9985ae5112 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.0; | |
contract PanicErrorExample { | |
function countTrailingZeroBytes(bytes32 data) public pure returns (uint256) { | |
uint256 index = 31; | |
// CHECK each bytes of the key, starting from the end (right to left) | |
// skip each empty bytes `0x00` to find the first non-empty byte | |
while (data[index] == 0x00) index--; | |
return 32 - (index + 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment