MCPcopy Create free account
hub / github.com/argotorg/solidity / overflowCheckedIntDivFunction

Method overflowCheckedIntDivFunction

libsolidity/codegen/YulUtilFunctions.cpp:850–878  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

848}
849
850std::string YulUtilFunctions::overflowCheckedIntDivFunction(IntegerType const& _type)
851{
852 std::string functionName = "checked_div_" + _type.identifier();
853 return m_functionCollector.createFunction(functionName, [&]() {
854 return
855 Whiskers(R"(
856 function <functionName>(x, y) -> r {
857 x := <cleanupFunction>(x)
858 y := <cleanupFunction>(y)
859 if iszero(y) { <panicDivZero>() }
860 <?signed>
861 // overflow for minVal / -1
862 if and(
863 eq(x, <minVal>),
864 eq(y, sub(0, 1))
865 ) { <panicOverflow>() }
866 </signed>
867 r := <?signed>s</signed>div(x, y)
868 }
869 )")
870 ("functionName", functionName)
871 ("signed", _type.isSigned())
872 ("minVal", toCompactHexWithPrefix(u256(_type.minValue())))
873 ("cleanupFunction", cleanupFunction(_type))
874 ("panicDivZero", panicFunction(PanicCode::DivisionByZero))
875 ("panicOverflow", panicFunction(PanicCode::UnderOverflow))
876 .render();
877 });
878}
879
880std::string YulUtilFunctions::wrappingIntDivFunction(IntegerType const& _type)
881{

Callers 2

binaryOperationMethod · 0.80

Calls 7

WhiskersClass · 0.85
toCompactHexWithPrefixFunction · 0.85
identifierMethod · 0.80
renderMethod · 0.80
createFunctionMethod · 0.45
isSignedMethod · 0.45
minValueMethod · 0.45

Tested by

no test coverage detected