Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eof: Enable compilation to EOF for all EVMVersionRestrictedTestCase tests by default #15666

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 0 additions & 17 deletions .circleci/soltest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@ REPODIR="$(realpath "$(dirname "$0")/..")"
IFS=" " read -r -a BOOST_TEST_ARGS <<< "$BOOST_TEST_ARGS"
IFS=" " read -r -a SOLTEST_FLAGS <<< "$SOLTEST_FLAGS"

# TODO: [EOF] These won't pass on EOF yet. Reenable them when the implementation is complete.
EOF_EXCLUDES=(
--run_test='!Assembler/all_assembly_items'
--run_test='!Assembler/immutable'
--run_test='!Assembler/immutables_and_its_source_maps'
--run_test='!Optimiser/jumpdest_removal_subassemblies'
--run_test='!Optimiser/jumpdest_removal_subassemblies/*'
--run_test='!SolidityCompiler/does_not_include_creation_time_only_internal_functions'
--run_test='!SolidityInlineAssembly/Analysis/create2'
--run_test='!SolidityInlineAssembly/Analysis/inline_assembly_shadowed_instruction_declaration'
--run_test='!SolidityInlineAssembly/Analysis/large_constant'
--run_test='!SolidityInlineAssembly/Analysis/staticcall'
--run_test='!ViewPureChecker/assembly_staticcall'
--run_test='!yulStackLayout/literal_loop'
)

# shellcheck source=scripts/common.sh
source "${REPODIR}/scripts/common.sh"
# Test result output directory (CircleCI is reading test results from here)
Expand Down Expand Up @@ -96,7 +80,6 @@ do
"--logger=HRF,error,stdout"
"${BOOST_TEST_ARGS[@]}"
)
(( EOF_VERSION != 0 )) && BOOST_TEST_ARGS_RUN+=("${EOF_EXCLUDES[@]}")
SOLTEST_ARGS=("--evm-version=$EVM" "${SOLTEST_FLAGS[@]}")

test "${OPTIMIZE}" = "1" && SOLTEST_ARGS+=(--optimize)
Expand Down
7 changes: 7 additions & 0 deletions test/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ bool isValidSemanticTestPath(boost::filesystem::path const& _testPath)
return true;
}

boost::unit_test::precondition::predicate_t nonEOF()
{
return [](boost::unit_test::test_unit_id) {
return !solidity::test::CommonOptions::get().eofVersion().has_value();
};
}

boost::unit_test::precondition::predicate_t minEVMVersionCheck(langutil::EVMVersion _minEVMVersion)
{
return [_minEVMVersion](boost::unit_test::test_unit_id) {
Expand Down
4 changes: 4 additions & 0 deletions test/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ bool isValidSemanticTestPath(boost::filesystem::path const& _testPath);
/// @return A predicate (function) that can be passed into @a boost::unit_test::precondition().
boost::unit_test::precondition::predicate_t minEVMVersionCheck(langutil::EVMVersion _minEVMVersion);

/// Helper that can be used to skip tests when the EOF is not supported by the test case.
/// @return A predicate (function) that can be passed into @a boost::unit_test::precondition().
boost::unit_test::precondition::predicate_t nonEOF();

bool loadVMs(CommonOptions const& _options);

/**
Expand Down
2 changes: 1 addition & 1 deletion test/TestCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void EVMVersionRestrictedTestCase::processBytecodeFormatSetting()
// EOF only available since Prague
solAssert(!eofVersion.has_value() ||solidity::test::CommonOptions::get().evmVersion() >= langutil::EVMVersion::prague());

std::string bytecodeFormatString = m_reader.stringSetting("bytecodeFormat", "legacy");
std::string bytecodeFormatString = m_reader.stringSetting("bytecodeFormat", "legacy,>=EOFv1");
if (bytecodeFormatString == "legacy,>=EOFv1" || bytecodeFormatString == ">=EOFv1,legacy")
return;

Expand Down
9 changes: 6 additions & 3 deletions test/libevmasm/Assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

using namespace solidity::langutil;
using namespace solidity::evmasm;
using namespace solidity::test;
using namespace std::string_literals;

namespace solidity::frontend::test
Expand All @@ -54,7 +55,7 @@ namespace

BOOST_AUTO_TEST_SUITE(Assembler)

BOOST_AUTO_TEST_CASE(all_assembly_items)
BOOST_AUTO_TEST_CASE(all_assembly_items, *boost::unit_test::precondition(nonEOF()))
{
std::map<std::string, unsigned> indices = {
{ "root.asm", 0 },
Expand Down Expand Up @@ -216,7 +217,8 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
BOOST_CHECK_EQUAL(util::jsonCompactPrint(_assembly.assemblyJSON(indices)), util::jsonCompactPrint(jsonValue));
}

BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps)
// TODO: Implement EOF counterpart
BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps, *boost::unit_test::precondition(nonEOF()))
{
EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion();
// Tests for 1, 2, 3 number of immutables.
Expand Down Expand Up @@ -301,7 +303,8 @@ BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps)
}
}

BOOST_AUTO_TEST_CASE(immutable)
// TODO: Implement EOF counterpart
BOOST_AUTO_TEST_CASE(immutable, *boost::unit_test::precondition(nonEOF()))
{
std::map<std::string, unsigned> indices = {
{ "root.asm", 0 },
Expand Down
5 changes: 3 additions & 2 deletions test/libevmasm/Optimiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

using namespace solidity::langutil;
using namespace solidity::evmasm;
using namespace solidity::test;

namespace solidity::frontend::test
{
Expand Down Expand Up @@ -1329,7 +1330,7 @@ BOOST_AUTO_TEST_CASE(jumpdest_removal)
);
}

BOOST_AUTO_TEST_CASE(jumpdest_removal_subassemblies)
BOOST_AUTO_TEST_CASE(jumpdest_removal_subassemblies, *boost::unit_test::precondition(nonEOF()))
{
// This tests that tags from subassemblies are not removed
// if they are referenced by a super-assembly. Furthermore,
Expand All @@ -1346,7 +1347,7 @@ BOOST_AUTO_TEST_CASE(jumpdest_removal_subassemblies)
settings.evmVersion = solidity::test::CommonOptions::get().evmVersion();
settings.expectedExecutionsPerDeployment = OptimiserSettings{}.expectedExecutionsPerDeployment;

Assembly main{settings.evmVersion, false, solidity::test::CommonOptions::get().eofVersion(), {}};
Assembly main{settings.evmVersion, false, std::nullopt, {}};
AssemblyPointer sub = std::make_shared<Assembly>(settings.evmVersion, true, solidity::test::CommonOptions::get().eofVersion(), std::string{});

sub->append(u256(1));
Expand Down
8 changes: 5 additions & 3 deletions test/libsolidity/InlineAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

using namespace solidity::langutil;
using namespace solidity::yul;
using namespace solidity::test;

namespace solidity::frontend::test
{
Expand Down Expand Up @@ -294,7 +295,8 @@ BOOST_AUTO_TEST_CASE(designated_invalid_instruction)
BOOST_CHECK(successAssemble("{ invalid() }"));
}

BOOST_AUTO_TEST_CASE(inline_assembly_shadowed_instruction_declaration)
// TODO: Implement EOF counterpart
BOOST_AUTO_TEST_CASE(inline_assembly_shadowed_instruction_declaration, *boost::unit_test::precondition(nonEOF()))
{
CHECK_ASSEMBLE_ERROR("{ let gas := 1 }", ParserError, "Cannot use builtin");
}
Expand Down Expand Up @@ -333,14 +335,14 @@ BOOST_AUTO_TEST_CASE(returndatacopy)
BOOST_CHECK(successAssemble("{ returndatacopy(0, 32, 64) }"));
}

BOOST_AUTO_TEST_CASE(staticcall)
BOOST_AUTO_TEST_CASE(staticcall, *boost::unit_test::precondition(nonEOF()))
{
if (!solidity::test::CommonOptions::get().evmVersion().hasStaticCall())
return;
BOOST_CHECK(successAssemble("{ pop(staticcall(10000, 0x123, 64, 0x10, 128, 0x10)) }"));
}

BOOST_AUTO_TEST_CASE(create2)
BOOST_AUTO_TEST_CASE(create2, *boost::unit_test::precondition(nonEOF()))
{
if (!solidity::test::CommonOptions::get().evmVersion().hasCreate2())
return;
Expand Down
39 changes: 39 additions & 0 deletions test/libsolidity/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,45 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
}
}

BOOST_AUTO_TEST_CASE(metadata_eof_experimental)
{
// Check that setting an EOF version results in the experimental flag being set.
char const* sourceCode = R"(
pragma solidity >=0.0;
contract test {
function g(function(uint) external returns (uint) x) public {}
}
)";
for (auto metadataFormat: std::set<CompilerStack::MetadataFormat>{
CompilerStack::MetadataFormat::NoMetadata,
CompilerStack::MetadataFormat::WithReleaseVersionTag,
CompilerStack::MetadataFormat::WithPrereleaseVersionTag
})
{
CompilerStack compilerStack;
compilerStack.setMetadataFormat(metadataFormat);
compilerStack.setSources({{"", sourceCode}});
compilerStack.setEVMVersion(langutil::EVMVersion::prague());
compilerStack.setViaIR(true);
compilerStack.setEOFVersion(1);
compilerStack.setOptimiserSettings(true);
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
bytes const& bytecode = compilerStack.runtimeObject("test").bytecode;
std::string const& metadata = compilerStack.metadata("test");
BOOST_CHECK(solidity::test::isValidMetadata(metadata));

auto const cborMetadata = requireParsedCBORMetadata(bytecode, metadataFormat);

if (metadataFormat == CompilerStack::MetadataFormat::NoMetadata)
BOOST_CHECK(cborMetadata.count("experimental") == 0);
else
{
BOOST_CHECK(cborMetadata.count("experimental") == 1);
BOOST_CHECK(cborMetadata.at("experimental") == "true");
}
}
}

BOOST_AUTO_TEST_CASE(metadata_relevant_sources)
{
CompilerStack compilerStack;
Expand Down
3 changes: 3 additions & 0 deletions test/libsolidity/SMTCheckerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ SMTCheckerTest::SMTCheckerTest(std::string const& _filename):

auto const& bmcLoopIterations = m_reader.sizetSetting("BMCLoopIterations", 1);
m_modelCheckerSettings.bmcLoopIterations = std::optional<unsigned>{bmcLoopIterations};

if (m_evmVersion < langutil::EVMVersion::prague() && CommonOptions::get().eofVersion().has_value())
m_shouldRun = false;
}

void SMTCheckerTest::setupCompiler(CompilerStack& _compiler)
Expand Down
4 changes: 3 additions & 1 deletion test/libsolidity/SolidityCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <boost/test/unit_test.hpp>

using namespace solidity::test;

namespace solidity::frontend::test
{
Expand All @@ -42,7 +43,8 @@ class SolidityCompilerFixture: protected AnalysisFramework

BOOST_FIXTURE_TEST_SUITE(SolidityCompiler, SolidityCompilerFixture)

BOOST_AUTO_TEST_CASE(does_not_include_creation_time_only_internal_functions)
// TODO: Implement EOF counterpart
BOOST_AUTO_TEST_CASE(does_not_include_creation_time_only_internal_functions, *boost::unit_test::precondition(nonEOF()))
{
char const* sourceCode = R"(
contract C {
Expand Down
4 changes: 3 additions & 1 deletion test/libsolidity/SyntaxTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ SyntaxTest::SyntaxTest(
{
static std::set<std::string> const compileViaYulAllowedValues{"true", "false"};

m_compileViaYul = m_reader.stringSetting("compileViaYul", "false");
auto const eofEnabled = solidity::test::CommonOptions::get().eofVersion().has_value();

m_compileViaYul = m_reader.stringSetting("compileViaYul", eofEnabled ? "true" : "false");
if (!util::contains(compileViaYulAllowedValues, m_compileViaYul))
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid compileViaYul value: " + m_compileViaYul + "."));
m_optimiseYul = m_reader.boolSetting("optimize-yul", true);
Expand Down
3 changes: 2 additions & 1 deletion test/libsolidity/ViewPureChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <tuple>

using namespace solidity::langutil;
using namespace solidity::test;

namespace solidity::frontend::test
{
Expand Down Expand Up @@ -133,7 +134,7 @@ BOOST_AUTO_TEST_CASE(address_staticcall)
}


BOOST_AUTO_TEST_CASE(assembly_staticcall)
BOOST_AUTO_TEST_CASE(assembly_staticcall, *boost::unit_test::precondition(nonEOF()))
{
std::string text = R"(
contract C {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
contract C {
uint120[3] x;
function f() public returns (bytes32 hash1, bytes32 hash2, bool hash3NonZero) {
uint120[] memory y = new uint120[](3);
x[0] = y[0] = uint120(type(uint).max - 1);
x[1] = y[1] = uint120(type(uint).max - 2);
x[2] = y[2] = uint120(type(uint).max - 3);
hash1 = keccak256(abi.encodePacked(x));
hash2 = keccak256(abi.encodePacked(y));
hash3NonZero = bytes32(0) != keccak256(abi.encodePacked(this.f));
}
}
// ====
// EVMVersion: >=prague
// bytecodeFormat: >=EOFv1
// ----
// f() -> 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, true
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ contract C {
hash3 = keccak256(abi.encodePacked(this.f));
}
}
// ====
// bytecodeFormat: legacy
// ----
// f() -> 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, 0xba4f20407251e4607cd66b90bfea19ec6971699c03e4a4f3ea737d5818ac27ae, 0x0e9229fb1d2cd02cee4b6c9f25497777014a8766e3479666d1c619066d2887ec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ contract C {
}
// ====
// EVMVersion: >homestead
// bytecodeFormat: legacy
// ----
// f(uint256), 2000 ether: 0 -> true
// f(uint256), 2000 ether: 100 -> false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
contract A1 {}
contract B1 is A1 { constructor() payable {} }

contract A2 { constructor() {} }
contract B2 is A2 { constructor() payable {} }

contract B3 { constructor() payable {} }

contract C {
function f() public payable returns (bool) {
// Make sure none of these revert.
new B1{value: 10, salt: hex"00"}();
new B2{value: 10, salt: hex"01"}();
new B3{value: 10, salt: hex"02"}();
return true;
}
}
// ====
// bytecodeFormat: >=EOFv1
// EVMVersion: >=prague
// ----
// f(), 2000 ether -> true
// gas irOptimized: 117623
// gas irOptimized code: 1800
// gas legacy: 117821
// gas legacy code: 4800
// gas legacyOptimized: 117690
// gas legacyOptimized code: 4800
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ contract C {
return true;
}
}
// ====
// bytecodeFormat: legacy
// ----
// f(), 2000 ether -> true
// gas irOptimized: 117623
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ contract C {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ contract C {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ contract C {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ contract C is S {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ contract C {
x < 2 * type(A).creationCode.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ contract C is S {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ contract C is X {
return x < data.length;
}
}
// ====
// bytecodeFormat: legacy
// ----
// test() -> true
Loading
Loading