From 6dae6583aff7d63e8b5e929fa396b98c0c231c33 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 15 May 2021 23:01:48 +0100 Subject: [PATCH] Turn toCompactHexWithPrefix into a template and support unsigned types This should help with boost::multiprecision versions where explicit unsigned/enum conversion to bigint do not exists (such as boost 1.76) --- libsolidity/codegen/CompilerContext.cpp | 2 +- libsolidity/codegen/YulUtilFunctions.cpp | 2 +- libsolutil/CommonData.h | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 35ff45965..f86ca506d 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -340,7 +340,7 @@ CompilerContext& CompilerContext::appendPanic(util::PanicCode _code) revert(0, 0x24) })"); templ("selector", util::selectorFromSignature("Panic(uint256)").str()); - templ("code", u256(_code).str()); + templ("code", toCompactHexWithPrefix(static_cast(_code))); appendInlineAssembly(templ.render()); return *this; } diff --git a/libsolidity/codegen/YulUtilFunctions.cpp b/libsolidity/codegen/YulUtilFunctions.cpp index a8741ebca..ef9dbc657 100644 --- a/libsolidity/codegen/YulUtilFunctions.cpp +++ b/libsolidity/codegen/YulUtilFunctions.cpp @@ -4377,7 +4377,7 @@ string YulUtilFunctions::panicFunction(util::PanicCode _code) )") ("functionName", functionName) ("selector", util::selectorFromSignature("Panic(uint256)").str()) - ("code", toCompactHexWithPrefix(_code)) + ("code", toCompactHexWithPrefix(static_cast(_code))) .render(); }); } diff --git a/libsolutil/CommonData.h b/libsolutil/CommonData.h index d5572d6f8..b33231a32 100644 --- a/libsolutil/CommonData.h +++ b/libsolutil/CommonData.h @@ -404,7 +404,8 @@ inline std::string toHex(u256 val, HexPrefix prefix = HexPrefix::DontAdd) return (prefix == HexPrefix::Add) ? "0x" + str : str; } -inline std::string toCompactHexWithPrefix(u256 const& _value) +template +inline std::string toCompactHexWithPrefix(T _value) { return toHex(toCompactBigEndian(_value, 1), HexPrefix::Add); }