Merge pull request #13354 from ethereum/fuzz-calldata-to-calldata-coding

Place calldata to calldata coder sanity checks.
This commit is contained in:
Kamil Śliwak 2022-08-08 12:40:38 +02:00 committed by GitHub
commit 5b0f4a724a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 5 deletions

View File

@ -66,9 +66,16 @@ DEFINE_PROTO_FUZZER(Contract const& _input)
// We don't care about EVM One failures other than EVMC_REVERT // We don't care about EVM One failures other than EVMC_REVERT
solAssert(result->status_code != EVMC_REVERT, "Proto ABIv2 fuzzer: EVM One reverted"); solAssert(result->status_code != EVMC_REVERT, "Proto ABIv2 fuzzer: EVM One reverted");
if (result->status_code == EVMC_SUCCESS) if (result->status_code == EVMC_SUCCESS)
solAssert( if (!EvmoneUtility::zeroWord(result->output_data, result->output_size))
EvmoneUtility::zeroWord(result->output_data, result->output_size), {
"Proto ABIv2 fuzzer: ABIv2 coding failure found" solidity::bytes resultAsBytes;
); for (size_t i = 0; i < result->output_size; i++)
resultAsBytes.push_back(result->output_data[i]);
cout << solidity::util::toHex(resultAsBytes) << endl;
solAssert(
false,
"Proto ABIv2 fuzzer: ABIv2 coding failure found"
);
}
} }
} }

View File

@ -426,6 +426,10 @@ void ProtoConverter::appendTypedParamsExternal(
("type", qualifiedTypeString) ("type", qualifiedTypeString)
("varName", _varName) ("varName", _varName)
.render(); .render();
m_untypedParamsExternal << Whiskers(R"(<delimiter><varName>)")
("delimiter", delimiterToString(_delimiter))
("varName", _varName)
.render();
} }
// Adds the qualifier "memory" to non-value parameter of an external function. // Adds the qualifier "memory" to non-value parameter of an external function.
@ -671,7 +675,11 @@ string ProtoConverter::calldataHelperFunctions()
return 0; return 0;
} }
function coder_calldata_external(<parameters_calldata>) external pure returns (uint) { function coder_calldata_external(<parameters_calldata>) external view returns (uint) {
return this.coder_calldata_external_indirection(<untyped_parameters>);
}
function coder_calldata_external_indirection(<parameters_calldata>) external pure returns (uint) {
<equality_checks> <equality_checks>
return 0; return 0;
} }
@ -679,6 +687,7 @@ string ProtoConverter::calldataHelperFunctions()
("parameters_memory", typedParametersAsString(CalleeType::PUBLIC)) ("parameters_memory", typedParametersAsString(CalleeType::PUBLIC))
("equality_checks", equalityChecksAsString()) ("equality_checks", equalityChecksAsString())
("parameters_calldata", typedParametersAsString(CalleeType::EXTERNAL)) ("parameters_calldata", typedParametersAsString(CalleeType::EXTERNAL))
("untyped_parameters", m_untypedParamsExternal.str())
.render(); .render();
return calldataHelperFuncs.str(); return calldataHelperFuncs.str();

View File

@ -390,6 +390,8 @@ private:
/// Contains typed parameter list to be passed to callee functions /// Contains typed parameter list to be passed to callee functions
std::ostringstream m_typedParamsExternal; std::ostringstream m_typedParamsExternal;
std::ostringstream m_typedParamsPublic; std::ostringstream m_typedParamsPublic;
/// Contains parameter list to be passed to callee functions
std::ostringstream m_untypedParamsExternal;
/// Contains type string to be passed to Isabelle API /// Contains type string to be passed to Isabelle API
std::ostringstream m_isabelleTypeString; std::ostringstream m_isabelleTypeString;
/// Contains values to be encoded in the format accepted /// Contains values to be encoded in the format accepted