Skip to content

Instantly share code, notes, and snippets.

@ilyar
Last active May 7, 2023 10:46
Show Gist options
  • Save ilyar/484360bdb5464a6f252bd8f8ec10aaff to your computer and use it in GitHub Desktop.
Save ilyar/484360bdb5464a6f252bd8f8ec10aaff to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
slugSha256() {
slug=$(echo -n "$1" | sha256sum | cut -d' ' -f1)
echo -n $((16#"${slug:0:8}"))
}
functionHash() {
hash=$(slugSha256 "$(echo -n "$1" | sed 's/ //g')")
if [[ "$1" == *constructor* ]] || [[ "$1" == *cell* ]] || [[ "$1" == *bytes* ]]; then
hash=$((hash ^ (2 ** 31)))
fi
if [[ "$1" == *cell* ]]; then hash=$((hash ^ (2 ** 31))); fi
if [[ "$1" == *bytes* ]]; then hash=$((hash ^ (2 ** 31))); fi
printf '0x%x' "$hash"
}
functionID() { functionHash "$1v2"; }
functionID "$1"
echo
@ilyar
Copy link
Author

ilyar commented Jul 21, 2022

$ bash es.sh "main()(string)"
0xb0992770
$ bash es.sh "redeem(uint256, string, uint256)()"
0x58160fa0
$ bash es.sh "constructor()()"
0x68b55f3f

Also see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment