Skip to content

Commit 5b0f4a7

Browse files
authored
Merge pull request #13354 from ethereum/fuzz-calldata-to-calldata-coding
Place calldata to calldata coder sanity checks.
2 parents 49a2db9 + 5394740 commit 5b0f4a7

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

test/tools/ossfuzz/abiV2ProtoFuzzer.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@ DEFINE_PROTO_FUZZER(Contract const& _input)
6666
// We don't care about EVM One failures other than EVMC_REVERT
6767
solAssert(result->status_code != EVMC_REVERT, "Proto ABIv2 fuzzer: EVM One reverted");
6868
if (result->status_code == EVMC_SUCCESS)
69-
solAssert(
70-
EvmoneUtility::zeroWord(result->output_data, result->output_size),
71-
"Proto ABIv2 fuzzer: ABIv2 coding failure found"
72-
);
69+
if (!EvmoneUtility::zeroWord(result->output_data, result->output_size))
70+
{
71+
solidity::bytes resultAsBytes;
72+
for (size_t i = 0; i < result->output_size; i++)
73+
resultAsBytes.push_back(result->output_data[i]);
74+
cout << solidity::util::toHex(resultAsBytes) << endl;
75+
solAssert(
76+
false,
77+
"Proto ABIv2 fuzzer: ABIv2 coding failure found"
78+
);
79+
}
7380
}
7481
}

test/tools/ossfuzz/protoToAbiV2.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ void ProtoConverter::appendTypedParamsExternal(
426426
("type", qualifiedTypeString)
427427
("varName", _varName)
428428
.render();
429+
m_untypedParamsExternal << Whiskers(R"(<delimiter><varName>)")
430+
("delimiter", delimiterToString(_delimiter))
431+
("varName", _varName)
432+
.render();
429433
}
430434

431435
// Adds the qualifier "memory" to non-value parameter of an external function.
@@ -671,14 +675,19 @@ string ProtoConverter::calldataHelperFunctions()
671675
return 0;
672676
}
673677
674-
function coder_calldata_external(<parameters_calldata>) external pure returns (uint) {
678+
function coder_calldata_external(<parameters_calldata>) external view returns (uint) {
679+
return this.coder_calldata_external_indirection(<untyped_parameters>);
680+
}
681+
682+
function coder_calldata_external_indirection(<parameters_calldata>) external pure returns (uint) {
675683
<equality_checks>
676684
return 0;
677685
}
678686
)")
679687
("parameters_memory", typedParametersAsString(CalleeType::PUBLIC))
680688
("equality_checks", equalityChecksAsString())
681689
("parameters_calldata", typedParametersAsString(CalleeType::EXTERNAL))
690+
("untyped_parameters", m_untypedParamsExternal.str())
682691
.render();
683692

684693
return calldataHelperFuncs.str();

test/tools/ossfuzz/protoToAbiV2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ class ProtoConverter
390390
/// Contains typed parameter list to be passed to callee functions
391391
std::ostringstream m_typedParamsExternal;
392392
std::ostringstream m_typedParamsPublic;
393+
/// Contains parameter list to be passed to callee functions
394+
std::ostringstream m_untypedParamsExternal;
393395
/// Contains type string to be passed to Isabelle API
394396
std::ostringstream m_isabelleTypeString;
395397
/// Contains values to be encoded in the format accepted

0 commit comments

Comments
 (0)