Skip to content

Instantly share code, notes, and snippets.

@CJ42
Created March 20, 2023 16:46
Show Gist options
  • Save CJ42/476885820f156066b4ae0e9985ae5112 to your computer and use it in GitHub Desktop.
Save CJ42/476885820f156066b4ae0e9985ae5112 to your computer and use it in GitHub Desktop.
// 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