solc-bin: Validate version reported by the compiler in the bytecode PR check

This commit is contained in:
Kamil Śliwak 2021-03-29 14:02:53 +02:00
parent d4e95a76e4
commit 03a0998b5b

View File

@ -57,6 +57,40 @@ die()
exit 1
}
get_reported_solc_version()
{
local solc_binary="$1"
local version_banner; version_banner=$("$solc_binary" --version)
if [[ ! $(echo "$version_banner" | head -n 1) =~ ^solc,.*$ ]]; then
die "%s\nFULL OUTPUT:\n" "Invalid format of --version output" "$version_banner"
fi
echo "$version_banner" | tail -n 1 | sed -n -E 's/^Version: (.*)$/\1/p'
}
validate_reported_version()
{
local reported_version="$1"
local expected_version_and_commit="$2"
if [[ $reported_version =~ [\-.]mod\. ]]; then
die "Version '%s' reported by the '%s' binary indicates that it was built from modified source." "$reported_version" "$expected_version_and_commit"
fi
local actual_version_and_commit; actual_version_and_commit=$(
echo "$reported_version" |
sed -E 's/^[[:space:]]*([0-9.]+\+commit\.[0-9a-f]+)\..+\..+$/\1/'
)
if [[ $actual_version_and_commit != "$expected_version_and_commit" ]]; then
die "Binary identifies itself as version '%s' which does not match '%s' present in its name." "$actual_version_and_commit" "$expected_version_and_commit"
fi
echo "Binary for version ${expected_version_and_commit} reports correct version."
}
(( $# == 5 )) || die "ERROR: Not enough arguments."
platform="$1"
@ -97,7 +131,8 @@ echo "$modified_release_versions"
platform_binaries="$(git ls-files "solc-${platform}-v*+commit.*" | sort -V)"
for binary_name in $platform_binaries; do
solidity_version=$(echo "$binary_name" | sed -n -E 's/^solc-'"${platform}"'-v([0-9.]+)\+commit.+$/\1/p')
solidity_version_and_commit=$(echo "$binary_name" | sed -n -E 's/^solc-'"${platform}"'-v([0-9.]+\+commit\.[0-9a-f]+).*$/\1/p')
solidity_version=$(echo "$solidity_version_and_commit" | sed -n -E 's/^([0-9.]+).*$/\1/p')
if echo "$modified_release_versions" | grep -x "$solidity_version"; then
echo "Binary ${binary_name} (version ${solidity_version}) matches one of the modified versions."
@ -116,6 +151,10 @@ for binary_name in $platform_binaries; do
ln -s "${solcjs_dir}" solc-js
cp "${script_dir}/bytecodecompare/prepare_report.js" prepare_report.js
validate_reported_version \
"$(solc-js/solcjs --version)" \
"$solidity_version_and_commit"
# shellcheck disable=SC2035
./prepare_report.js --strip-smt-pragmas *.sol > "${report_dir}/report-${binary_name}.txt"
else
@ -124,6 +163,10 @@ for binary_name in $platform_binaries; do
yul_optimizer_flags+=(--force-no-optimize-yul)
fi
validate_reported_version \
"$(get_reported_solc_version "${solc_bin_dir}/${platform}/${binary_name}")" \
"$solidity_version_and_commit"
"${script_dir}/bytecodecompare/prepare_report.py" "${solc_bin_dir}/${platform}/${binary_name}" \
--interface cli \
--smt-use strip-pragmas \