Merge pull request #10700 from ethereum/whiskers_check_template_contains_tag

[whiskers] Add check that template contain tags.
This commit is contained in:
chriseth
2021-01-25 14:17:05 +01:00
committed by GitHub
6 changed files with 38 additions and 22 deletions
+14 -11
View File
@@ -1231,9 +1231,10 @@ string ABIFunctions::abiDecodingFunctionCalldataArray(ArrayType const& _type)
"abi_decode_" +
_type.identifier();
return createFunction(functionName, [&]() {
string templ;
Whiskers w;
if (_type.isDynamicallySized())
templ = R"(
{
w = Whiskers(R"(
// <readableTypeName>
function <functionName>(offset, end) -> arrayPos, length {
if iszero(slt(add(offset, 0x1f), end)) { <revertStringOffset> }
@@ -1242,25 +1243,27 @@ string ABIFunctions::abiDecodingFunctionCalldataArray(ArrayType const& _type)
arrayPos := add(offset, 0x20)
if gt(add(arrayPos, mul(length, <stride>)), end) { <revertStringPos> }
}
)";
)");
w("revertStringOffset", revertReasonIfDebug("ABI decoding: invalid calldata array offset"));
w("revertStringLength", revertReasonIfDebug("ABI decoding: invalid calldata array length"));
}
else
templ = R"(
{
w = Whiskers(R"(
// <readableTypeName>
function <functionName>(offset, end) -> arrayPos {
arrayPos := offset
if gt(add(arrayPos, mul(<length>, <stride>)), end) { <revertStringPos> }
}
)";
Whiskers w{templ};
// TODO add test
w("revertStringOffset", revertReasonIfDebug("ABI decoding: invalid calldata array offset"));
w("revertStringLength", revertReasonIfDebug("ABI decoding: invalid calldata array length"));
)");
w("length", toCompactHexWithPrefix(_type.length()));
}
w("revertStringPos", revertReasonIfDebug("ABI decoding: invalid calldata array stride"));
w("functionName", functionName);
w("readableTypeName", _type.toString(true));
w("stride", toCompactHexWithPrefix(_type.calldataStride()));
if (!_type.isDynamicallySized())
w("length", toCompactHexWithPrefix(_type.length()));
// TODO add test
return w.render();
});
}
-8
View File
@@ -959,7 +959,6 @@ string YulUtilFunctions::overflowCheckedUnsignedExpFunction()
("functionName", functionName)
("panic", panicFunction(PanicCode::UnderOverflow))
("expLoop", overflowCheckedExpLoopFunction())
("shr_1", shiftRightFunction(1))
.render();
});
}
@@ -1326,8 +1325,6 @@ string YulUtilFunctions::byteArrayTransitLongToShortFunction(ArrayType const& _t
("functionName", functionName)
("dataPosition", arrayDataAreaFunction(_type))
("extractUsedApplyLen", shortByteArrayEncodeUsedAreaSetLengthFunction())
("shl", shiftLeftFunctionDynamic())
("ones", formatNumber((bigint(1) << 256) - 1))
.render();
});
}
@@ -1420,7 +1417,6 @@ string YulUtilFunctions::storageByteArrayPopFunction(ArrayType const& _type)
("encodeUsedSetLen", shortByteArrayEncodeUsedAreaSetLengthFunction())
("indexAccess", storageArrayIndexAccessFunction(_type))
("setToZero", storageSetToZeroFunction(*_type.baseType()))
("shl", shiftLeftFunctionDynamic())
.render();
});
}
@@ -1492,7 +1488,6 @@ string YulUtilFunctions::storageArrayPushFunction(ArrayType const& _type, Type c
("storeValue", updateStorageValueFunction(*_fromType, *_type.baseType()))
("maxArrayLength", (u256(1) << 64).str())
("shl", shiftLeftFunctionDynamic())
("shr", shiftRightFunction(248))
.render();
});
}
@@ -1658,7 +1653,6 @@ string YulUtilFunctions::clearStorageStructFunction(StructType const& _type)
}
)")
("functionName", functionName)
("storageSize", _type.storageSize().str())
("member", memberSetValues)
.render();
});
@@ -1742,7 +1736,6 @@ string YulUtilFunctions::copyArrayToStorageFunction(ArrayType const& _fromType,
templ("srcDataLocation", arrayDataAreaFunction(_fromType));
if (fromCalldata)
{
templ("dynamicallySizedBase", _fromType.baseType()->isDynamicallySized());
templ("dynamicallyEncodedBase", _fromType.baseType()->isDynamicallyEncoded());
if (_fromType.baseType()->isDynamicallyEncoded())
templ("accessCalldataTail", accessCalldataTailFunction(*_fromType.baseType()));
@@ -3380,7 +3373,6 @@ string YulUtilFunctions::copyStructToStorageFunction(StructType const& _from, St
solAssert(srcOffset == 0, "");
}
t("memberStorageSlotOffset", to_string(offset));
t("updateStorageValue", updateStorageValueFunction(
memberType,
*toStructMembers[i].type,
-1
View File
@@ -891,7 +891,6 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract)
}
t("fallback", fallbackCode);
t("revertNoSignature", "");
}
else
t(