Skip to content

Instantly share code, notes, and snippets.

@leonardoalt
Created July 21, 2020 13:53
Show Gist options
  • Save leonardoalt/c4ad8f8f1e679fe39a5f2c216e96fc5c to your computer and use it in GitHub Desktop.
Save leonardoalt/c4ad8f8f1e679fe39a5f2c216e96fc5c to your computer and use it in GitHub Desktop.
#!/usr/bin/sh
TMPDIR=$(mktemp -d)
cd "$TMPDIR"
compile()
{
solc --yul --yul-dialect evm $1 2> /dev/null | awk 'f{print;f=0} /Binary representation:/{f=1}'
}
echo ""
echo "Checking optimization equivalence for $1"
nonopt_bin=$(compile $1)
if [ -z "$nonopt_bin" ]
then
echo "Could not compile nonoptimized code."
exit 1
fi
sed '0,/^\/\/ step:/d' $1 | sed -e 's!\/\/!!' > optsource
opt_bin=$(compile optsource)
if [ -z "$opt_bin" ]
then
echo "Could not compile optimized code."
exit 1
fi
if [[ "$nonopt_bin" == "$opt_bin" ]]
then
echo "Nonoptimized and optimized bytecodes are the same."
exit 1
fi
echo "Checking bytecode equivalence: $nonopt_bin vs $opt_bin"
timeout 10s /home/leonardo/devel/dapptools/src/hevm/hevm equivalence --code-a $nonopt_bin --code-b $opt_bin --smttimeout 1000
if [[ $? == 124 ]]
then
echo "HEVM timeout."
fi
rm -rf "$TMPDIR"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment