diff --git a/libsolidity/codegen/ir/Common.cpp b/libsolidity/codegen/ir/Common.cpp index b7b8d092d..d11680f09 100644 --- a/libsolidity/codegen/ir/Common.cpp +++ b/libsolidity/codegen/ir/Common.cpp @@ -80,6 +80,11 @@ string IRNames::implicitConstructor(ContractDefinition const& _contract) return "constructor_" + _contract.name() + "_" + to_string(_contract.id()); } +string IRNames::libraryAddressImmutable() +{ + return "library_deploy_address"; +} + string IRNames::constantValueFunction(VariableDeclaration const& _constant) { solAssert(_constant.isConstant(), ""); diff --git a/libsolidity/codegen/ir/Common.h b/libsolidity/codegen/ir/Common.h index 345eed784..66f09287f 100644 --- a/libsolidity/codegen/ir/Common.h +++ b/libsolidity/codegen/ir/Common.h @@ -55,6 +55,7 @@ struct IRNames static std::string runtimeObject(ContractDefinition const& _contract); static std::string internalDispatch(YulArity const& _arity); static std::string implicitConstructor(ContractDefinition const& _contract); + static std::string libraryAddressImmutable(); static std::string constantValueFunction(VariableDeclaration const& _constant); static std::string localVariable(VariableDeclaration const& _declaration); static std::string localVariable(Expression const& _expression); diff --git a/libsolidity/codegen/ir/IRGenerator.cpp b/libsolidity/codegen/ir/IRGenerator.cpp index c476e7825..743078a3c 100644 --- a/libsolidity/codegen/ir/IRGenerator.cpp +++ b/libsolidity/codegen/ir/IRGenerator.cpp @@ -94,16 +94,20 @@ string IRGenerator::generate( code { - + + let := () () - + } object "" { code { + + let called_via_delegatecall := iszero(eq(loadimmutable(""), address())) + } @@ -118,7 +122,7 @@ string IRGenerator::generate( m_context.registerImmutableVariable(*var); t("CreationObject", IRNames::creationObject(_contract)); - t("notLibrary", !_contract.isLibrary()); + t("library", _contract.isLibrary()); FunctionDefinition const* constructor = _contract.constructor(); t("callValueCheck", !constructor || !constructor->isPayable() ? callValueCheck() : ""); @@ -156,6 +160,7 @@ string IRGenerator::generate( // Do not register immutables to avoid assignment. t("RuntimeObject", IRNames::runtimeObject(_contract)); + t("library_address", IRNames::libraryAddressImmutable()); t("dispatch", dispatchRoutine(_contract)); generateQueuedFunctions(); generateInternalDispatchFunctions(); @@ -747,20 +752,30 @@ string IRGenerator::deployCode(ContractDefinition const& _contract) vector> loadImmutables; vector> storeImmutables; - for (VariableDeclaration const* immutable: ContractType(_contract).immutableVariables()) + if (_contract.isLibrary()) { - solUnimplementedAssert(immutable->type()->isValueType(), ""); - solUnimplementedAssert(immutable->type()->sizeOnStack() == 1, ""); - string yulVar = m_context.newYulVariable(); - loadImmutables.emplace_back(map{ - {"var"s, yulVar}, - {"memoryOffset"s, to_string(m_context.immutableMemoryOffset(*immutable))} - }); + solAssert(ContractType(_contract).immutableVariables().empty(), ""); storeImmutables.emplace_back(map{ - {"var"s, yulVar}, - {"immutableName"s, to_string(immutable->id())} + {"var"s, "address()"}, + {"immutableName"s, IRNames::libraryAddressImmutable()} }); + } + else + for (VariableDeclaration const* immutable: ContractType(_contract).immutableVariables()) + { + solUnimplementedAssert(immutable->type()->isValueType(), ""); + solUnimplementedAssert(immutable->type()->sizeOnStack() == 1, ""); + string yulVar = m_context.newYulVariable(); + loadImmutables.emplace_back(map{ + {"var"s, yulVar}, + {"memoryOffset"s, to_string(m_context.immutableMemoryOffset(*immutable))} + }); + storeImmutables.emplace_back(map{ + {"var"s, yulVar}, + {"immutableName"s, to_string(immutable->id())} + }); + } t("loadImmutables", std::move(loadImmutables)); // reverse order to ease stack strain reverse(storeImmutables.begin(), storeImmutables.end()); @@ -784,6 +799,7 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract) case { // + let := (4, calldatasize()) let := () @@ -806,7 +822,18 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract) templ["functionSelector"] = "0x" + function.first.hex(); FunctionTypePointer const& type = function.second; templ["functionName"] = type->externalSignature(); - templ["callValueCheck"] = type->isPayable() ? "" : callValueCheck(); + string delegatecallCheck; + if (_contract.isLibrary()) + { + solAssert(!type->isPayable(), ""); + if (type->stateMutability() > StateMutability::View) + // If the function is not a view function and is called without DELEGATECALL, + // we revert. + // TODO add revert message. + delegatecallCheck = "if iszero(called_via_delegatecall) { revert(0, 0) }"; + } + templ["delegatecallCheck"] = delegatecallCheck; + templ["callValueCheck"] = (type->isPayable() || _contract.isLibrary()) ? "" : callValueCheck(); unsigned paramVars = make_shared(type->parameterTypes())->sizeOnStack(); unsigned retVars = make_shared(type->returnParameterTypes())->sizeOnStack(); @@ -824,11 +851,19 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract) solAssert(false, "Unexpected declaration for function!"); templ["allocate"] = m_utils.allocationFunction(); - templ["abiEncode"] = abiFunctions.tupleEncoder(type->returnParameterTypes(), type->returnParameterTypes(), false); + templ["abiEncode"] = abiFunctions.tupleEncoder(type->returnParameterTypes(), type->returnParameterTypes(), _contract.isLibrary()); } t("cases", functions); + if (FunctionDefinition const* etherReceiver = _contract.receiveFunction()) + { + solAssert(!_contract.isLibrary(), ""); + t("receiveEther", m_context.enqueueFunctionForCodeGeneration(*etherReceiver) + "() stop()"); + } + else + t("receiveEther", ""); if (FunctionDefinition const* fallback = _contract.fallbackFunction()) { + solAssert(!_contract.isLibrary(), ""); string fallbackCode; if (!fallback->isPayable()) fallbackCode += callValueCheck() + "\n"; @@ -846,10 +881,6 @@ string IRGenerator::dispatchRoutine(ContractDefinition const& _contract) } else t("fallback", "revert(0, 0)"); - if (FunctionDefinition const* etherReceiver = _contract.receiveFunction()) - t("receiveEther", m_context.enqueueFunctionForCodeGeneration(*etherReceiver) + "() stop()"); - else - t("receiveEther", ""); return t.render(); } diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index bf9e8a8e8..300a6ed85 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -1664,7 +1664,10 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess) FunctionType const& functionType = dynamic_cast( *_memberAccess.expression().annotation().type ); - if (functionType.kind() == FunctionType::Kind::External) + if ( + functionType.kind() == FunctionType::Kind::External || + functionType.kind() == FunctionType::Kind::DelegateCall + ) define(IRVariable{_memberAccess}, IRVariable(_memberAccess.expression()).part("functionSelector")); else if (functionType.kind() == FunctionType::Kind::Declaration) { @@ -1672,7 +1675,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess) define(IRVariable{_memberAccess}) << formatNumber(functionType.externalIdentifier() << 224) << "\n"; } else - solAssert(false, "Invalid use of .selector"); + solAssert(false, "Invalid use of .selector: " + functionType.toString(false)); } else if (member == "address") { diff --git a/test/cmdlineTests/exp_base_literal/output b/test/cmdlineTests/exp_base_literal/output index 55c06f769..e2ee326f3 100644 --- a/test/cmdlineTests/exp_base_literal/output +++ b/test/cmdlineTests/exp_base_literal/output @@ -35,6 +35,7 @@ object "C_81" { case 0x70cb9605 { // f(uint256,uint256,uint256,uint256) + if callvalue() { revert(0, 0) } let param_0, param_1, param_2, param_3 := abi_decode_tuple_t_uint256t_uint256t_uint256t_uint256(4, calldatasize()) let ret_0, ret_1, ret_2, ret_3 := fun_f_80(param_0, param_1, param_2, param_3) diff --git a/test/cmdlineTests/standard_ir_requested/output.json b/test/cmdlineTests/standard_ir_requested/output.json index b25430812..31ff3e27d 100644 --- a/test/cmdlineTests/standard_ir_requested/output.json +++ b/test/cmdlineTests/standard_ir_requested/output.json @@ -34,6 +34,7 @@ object \"C_7\" { case 0x26121ff0 { // f() + if callvalue() { revert(0, 0) } abi_decode_tuple_(4, calldatasize()) fun_f_6() diff --git a/test/cmdlineTests/standard_viair_requested/output.json b/test/cmdlineTests/standard_viair_requested/output.json index e46332a28..17add8657 100644 --- a/test/cmdlineTests/standard_viair_requested/output.json +++ b/test/cmdlineTests/standard_viair_requested/output.json @@ -85,6 +85,7 @@ object \"D_16\" { case 0x26121ff0 { // f() + if callvalue() { revert(0, 0) } abi_decode_tuple_(4, calldatasize()) fun_f_15() diff --git a/test/cmdlineTests/viair_abicoder_v1/output b/test/cmdlineTests/viair_abicoder_v1/output index 8810db8a5..f619c5947 100644 --- a/test/cmdlineTests/viair_abicoder_v1/output +++ b/test/cmdlineTests/viair_abicoder_v1/output @@ -35,6 +35,7 @@ object "test_11" { case 0x26121ff0 { // f() + if callvalue() { revert(0, 0) } abi_decode_tuple_(4, calldatasize()) let ret_0 := fun_f_10() diff --git a/test/cmdlineTests/yul_string_format_ascii/output.json b/test/cmdlineTests/yul_string_format_ascii/output.json index 7321150f9..c8c45708b 100644 --- a/test/cmdlineTests/yul_string_format_ascii/output.json +++ b/test/cmdlineTests/yul_string_format_ascii/output.json @@ -34,6 +34,7 @@ object \"C_11\" { case 0x26121ff0 { // f() + if callvalue() { revert(0, 0) } abi_decode_tuple_(4, calldatasize()) let ret_0 := fun_f_10() diff --git a/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json b/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json index 06b71932b..937900126 100644 --- a/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json +++ b/test/cmdlineTests/yul_string_format_ascii_bytes32/output.json @@ -34,6 +34,7 @@ object \"C_11\" { case 0x26121ff0 { // f() + if callvalue() { revert(0, 0) } abi_decode_tuple_(4, calldatasize()) let ret_0 := fun_f_10() diff --git a/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json b/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json index 4e9be627a..8dfad7c49 100644 --- a/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json +++ b/test/cmdlineTests/yul_string_format_ascii_bytes32_from_number/output.json @@ -34,6 +34,7 @@ object \"C_11\" { case 0x26121ff0 { // f() + if callvalue() { revert(0, 0) } abi_decode_tuple_(4, calldatasize()) let ret_0 := fun_f_10() diff --git a/test/cmdlineTests/yul_string_format_ascii_long/output.json b/test/cmdlineTests/yul_string_format_ascii_long/output.json index acfe9089f..118794542 100644 --- a/test/cmdlineTests/yul_string_format_ascii_long/output.json +++ b/test/cmdlineTests/yul_string_format_ascii_long/output.json @@ -34,6 +34,7 @@ object \"C_11\" { case 0x26121ff0 { // f() + if callvalue() { revert(0, 0) } abi_decode_tuple_(4, calldatasize()) let ret_0 := fun_f_10() diff --git a/test/cmdlineTests/yul_string_format_hex/output.json b/test/cmdlineTests/yul_string_format_hex/output.json index 77bfbee09..890a7d858 100644 --- a/test/cmdlineTests/yul_string_format_hex/output.json +++ b/test/cmdlineTests/yul_string_format_hex/output.json @@ -34,6 +34,7 @@ object \"C_11\" { case 0x26121ff0 { // f() + if callvalue() { revert(0, 0) } abi_decode_tuple_(4, calldatasize()) let ret_0 := fun_f_10() diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index b5001a26a..604e83412 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2239,10 +2239,13 @@ BOOST_AUTO_TEST_CASE(library_call_in_homestead) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("f()"), encodeArgs()); - ABI_CHECK(callContractFunction("sender()"), encodeArgs(m_sender)); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs()); + ABI_CHECK(callContractFunction("sender()"), encodeArgs(m_sender)); + ) } BOOST_AUTO_TEST_CASE(library_call_protection) @@ -2266,16 +2269,19 @@ BOOST_AUTO_TEST_CASE(library_call_protection) function pu() public pure returns (uint) { return Lib.pu(); } } )"; - compileAndRun(sourceCode, 0, "Lib"); - ABI_CHECK(callContractFunction("np(Lib.S storage)", 0), encodeArgs()); - ABI_CHECK(callContractFunction("v(Lib.S storage)", 0), encodeArgs(m_sender)); - ABI_CHECK(callContractFunction("pu()"), encodeArgs(2)); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("s()"), encodeArgs(0)); - ABI_CHECK(callContractFunction("np()"), encodeArgs(m_sender)); - ABI_CHECK(callContractFunction("s()"), encodeArgs(3)); - ABI_CHECK(callContractFunction("v()"), encodeArgs(m_sender)); - ABI_CHECK(callContractFunction("pu()"), encodeArgs(2)); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + ABI_CHECK(callContractFunction("np(Lib.S storage)", 0), encodeArgs()); + ABI_CHECK(callContractFunction("v(Lib.S storage)", 0), encodeArgs(m_sender)); + ABI_CHECK(callContractFunction("pu()"), encodeArgs(2)); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("s()"), encodeArgs(0)); + ABI_CHECK(callContractFunction("np()"), encodeArgs(m_sender)); + ABI_CHECK(callContractFunction("s()"), encodeArgs(3)); + ABI_CHECK(callContractFunction("v()"), encodeArgs(m_sender)); + ABI_CHECK(callContractFunction("pu()"), encodeArgs(2)); + ) } BOOST_AUTO_TEST_CASE(library_staticcall_delegatecall) @@ -2537,17 +2543,20 @@ BOOST_AUTO_TEST_CASE(struct_referencing) function a2() public pure returns (uint) { L.S memory s; return L.a(s); } } )"; - compileAndRun(sourceCode, 0, "L"); - ABI_CHECK(callContractFunction("f()"), encodeArgs(0, 3)); - ABI_CHECK(callContractFunction("g()"), encodeArgs(4)); - compileAndRun(sourceCode, 0, "C", bytes(), map{ {"L", m_contractAddress}}); - ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); - ABI_CHECK(callContractFunction("g()"), encodeArgs(2)); - ABI_CHECK(callContractFunction("h()"), encodeArgs(0, 5)); - ABI_CHECK(callContractFunction("x()"), encodeArgs(0, 3)); - ABI_CHECK(callContractFunction("y()"), encodeArgs(4)); - ABI_CHECK(callContractFunction("a1()"), encodeArgs(1)); - ABI_CHECK(callContractFunction("a2()"), encodeArgs(2)); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "L"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(0, 3)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(4)); + compileAndRun(sourceCode, 0, "C", bytes(), map{ {"L", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(2)); + ABI_CHECK(callContractFunction("h()"), encodeArgs(0, 5)); + ABI_CHECK(callContractFunction("x()"), encodeArgs(0, 3)); + ABI_CHECK(callContractFunction("y()"), encodeArgs(4)); + ABI_CHECK(callContractFunction("a1()"), encodeArgs(1)); + ABI_CHECK(callContractFunction("a2()"), encodeArgs(2)); + ) } BOOST_AUTO_TEST_CASE(enum_referencing) @@ -2583,15 +2592,18 @@ BOOST_AUTO_TEST_CASE(enum_referencing) } } )"; - compileAndRun(sourceCode, 0, "L"); - ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); - ABI_CHECK(callContractFunction("g()"), encodeArgs(3)); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); - ABI_CHECK(callContractFunction("f()"), encodeArgs(3)); - ABI_CHECK(callContractFunction("g()"), encodeArgs(3)); - ABI_CHECK(callContractFunction("h()"), encodeArgs(1)); - ABI_CHECK(callContractFunction("x()"), encodeArgs(1)); - ABI_CHECK(callContractFunction("y()"), encodeArgs(3)); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "L"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(1)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(3)); + compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(3)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(3)); + ABI_CHECK(callContractFunction("h()"), encodeArgs(1)); + ABI_CHECK(callContractFunction("x()"), encodeArgs(1)); + ABI_CHECK(callContractFunction("y()"), encodeArgs(3)); + ) } BOOST_AUTO_TEST_CASE(bytes_in_arguments) @@ -3413,9 +3425,12 @@ BOOST_AUTO_TEST_CASE(library_call) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("f(uint256)", u256(33)), encodeArgs(u256(33) * 9)); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f(uint256)", u256(33)), encodeArgs(u256(33) * 9)); + ) } BOOST_AUTO_TEST_CASE(library_function_external) @@ -3428,9 +3443,12 @@ BOOST_AUTO_TEST_CASE(library_function_external) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("f(bytes)", u256(0x20), u256(5), "abcde"), encodeArgs("c")); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f(bytes)", u256(0x20), u256(5), "abcde"), encodeArgs("c")); + ) } BOOST_AUTO_TEST_CASE(library_stray_values) @@ -3445,9 +3463,12 @@ BOOST_AUTO_TEST_CASE(library_stray_values) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("f(uint256)", u256(33)), encodeArgs(u256(42))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f(uint256)", u256(33)), encodeArgs(u256(42))); + ) } BOOST_AUTO_TEST_CASE(internal_types_in_library) @@ -3475,9 +3496,12 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(4), u256(17))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(4), u256(17))); + ) } BOOST_AUTO_TEST_CASE(mapping_arguments_in_library) @@ -3506,22 +3530,25 @@ BOOST_AUTO_TEST_CASE(mapping_arguments_in_library) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(1), u256(42)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(2), u256(84)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(21), u256(7)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get(uint256)", u256(0)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get(uint256)", u256(1)), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("get(uint256)", u256(2)), encodeArgs(u256(84))); - ABI_CHECK(callContractFunction("get(uint256)", u256(21)), encodeArgs(u256(7))); - ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(1), u256(21)), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(2), u256(42)), encodeArgs(u256(84))); - ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(21), u256(14)), encodeArgs(u256(7))); - ABI_CHECK(callContractFunction("get(uint256)", u256(0)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get(uint256)", u256(1)), encodeArgs(u256(21))); - ABI_CHECK(callContractFunction("get(uint256)", u256(2)), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("get(uint256)", u256(21)), encodeArgs(u256(14))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(1), u256(42)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(2), u256(84)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(21), u256(7)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(uint256)", u256(1)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get(uint256)", u256(2)), encodeArgs(u256(84))); + ABI_CHECK(callContractFunction("get(uint256)", u256(21)), encodeArgs(u256(7))); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(1), u256(21)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(2), u256(42)), encodeArgs(u256(84))); + ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(21), u256(14)), encodeArgs(u256(7))); + ABI_CHECK(callContractFunction("get(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(uint256)", u256(1)), encodeArgs(u256(21))); + ABI_CHECK(callContractFunction("get(uint256)", u256(2)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get(uint256)", u256(21)), encodeArgs(u256(14))); + ) } BOOST_AUTO_TEST_CASE(mapping_returns_in_library) @@ -3554,52 +3581,55 @@ BOOST_AUTO_TEST_CASE(mapping_returns_in_library) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(1), u256(42)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(2), u256(84)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(21), u256(7)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(1), u256(10)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(2), u256(11)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(21), u256(12)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(0)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(1)), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(2)), encodeArgs(u256(84))); - ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(21)), encodeArgs(u256(7))); - ABI_CHECK(callContractFunction("get_a(uint256)", u256(0)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get_a(uint256)", u256(1)), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("get_a(uint256)", u256(2)), encodeArgs(u256(84))); - ABI_CHECK(callContractFunction("get_a(uint256)", u256(21)), encodeArgs(u256(7))); - ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(0)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(1)), encodeArgs(u256(10))); - ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(2)), encodeArgs(u256(11))); - ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(21)), encodeArgs(u256(12))); - ABI_CHECK(callContractFunction("get_b(uint256)", u256(0)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get_b(uint256)", u256(1)), encodeArgs(u256(10))); - ABI_CHECK(callContractFunction("get_b(uint256)", u256(2)), encodeArgs(u256(11))); - ABI_CHECK(callContractFunction("get_b(uint256)", u256(21)), encodeArgs(u256(12))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(1), u256(21)), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(2), u256(42)), encodeArgs(u256(84))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(21), u256(14)), encodeArgs(u256(7))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(1), u256(30)), encodeArgs(u256(10))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(2), u256(31)), encodeArgs(u256(11))); - ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(21), u256(32)), encodeArgs(u256(12))); - ABI_CHECK(callContractFunction("get_a(uint256)", u256(0)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get_a(uint256)", u256(1)), encodeArgs(u256(21))); - ABI_CHECK(callContractFunction("get_a(uint256)", u256(2)), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("get_a(uint256)", u256(21)), encodeArgs(u256(14))); - ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(0)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(1)), encodeArgs(u256(21))); - ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(2)), encodeArgs(u256(42))); - ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(21)), encodeArgs(u256(14))); - ABI_CHECK(callContractFunction("get_b(uint256)", u256(0)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get_b(uint256)", u256(1)), encodeArgs(u256(30))); - ABI_CHECK(callContractFunction("get_b(uint256)", u256(2)), encodeArgs(u256(31))); - ABI_CHECK(callContractFunction("get_b(uint256)", u256(21)), encodeArgs(u256(32))); - ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(0)), encodeArgs(u256(0))); - ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(1)), encodeArgs(u256(30))); - ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(2)), encodeArgs(u256(31))); - ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(21)), encodeArgs(u256(32))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(1), u256(42)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(2), u256(84)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(21), u256(7)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(1), u256(10)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(2), u256(11)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(21), u256(12)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(1)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(2)), encodeArgs(u256(84))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(21)), encodeArgs(u256(7))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(1)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(2)), encodeArgs(u256(84))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(21)), encodeArgs(u256(7))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(1)), encodeArgs(u256(10))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(2)), encodeArgs(u256(11))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(21)), encodeArgs(u256(12))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(1)), encodeArgs(u256(10))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(2)), encodeArgs(u256(11))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(21)), encodeArgs(u256(12))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(1), u256(21)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(2), u256(42)), encodeArgs(u256(84))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(21), u256(14)), encodeArgs(u256(7))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(1), u256(30)), encodeArgs(u256(10))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(2), u256(31)), encodeArgs(u256(11))); + ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(21), u256(32)), encodeArgs(u256(12))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(1)), encodeArgs(u256(21))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(2)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get_a(uint256)", u256(21)), encodeArgs(u256(14))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(1)), encodeArgs(u256(21))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(2)), encodeArgs(u256(42))); + ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(21)), encodeArgs(u256(14))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(1)), encodeArgs(u256(30))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(2)), encodeArgs(u256(31))); + ABI_CHECK(callContractFunction("get_b(uint256)", u256(21)), encodeArgs(u256(32))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(0)), encodeArgs(u256(0))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(1)), encodeArgs(u256(30))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(2)), encodeArgs(u256(31))); + ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(21)), encodeArgs(u256(32))); + ) } BOOST_AUTO_TEST_CASE(mapping_returns_in_library_named) @@ -3630,10 +3660,13 @@ BOOST_AUTO_TEST_CASE(mapping_returns_in_library_named) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(84))); - ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(17))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(84))); + ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(17))); + ) } BOOST_AUTO_TEST_CASE(using_library_mappings_public) @@ -3658,9 +3691,12 @@ BOOST_AUTO_TEST_CASE(using_library_mappings_public) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1), u256(0), u256(42), u256(23), u256(0), u256(99))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1), u256(0), u256(42), u256(23), u256(0), u256(99))); + ) } BOOST_AUTO_TEST_CASE(using_library_mappings_external) @@ -3719,9 +3755,12 @@ BOOST_AUTO_TEST_CASE(using_library_mappings_return) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1), u256(0), u256(42), u256(23), u256(0), u256(99))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1), u256(0), u256(42), u256(23), u256(0), u256(99))); + ) } BOOST_AUTO_TEST_CASE(using_library_structs) @@ -3747,9 +3786,12 @@ BOOST_AUTO_TEST_CASE(using_library_structs) } } )"; - compileAndRun(sourceCode, 0, "Lib"); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(7), u256(8))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "Lib"); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"Lib", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(7), u256(8))); + ) } BOOST_AUTO_TEST_CASE(short_strings) @@ -3860,14 +3902,17 @@ BOOST_AUTO_TEST_CASE(short_strings) } } )"; - compileAndRun(sourceCode, 0, "A"); - ABI_CHECK(callContractFunction("data1()"), encodeDyn(string("123"))); - ABI_CHECK(callContractFunction("lengthChange()"), encodeArgs(u256(0))); - BOOST_CHECK(storageEmpty(m_contractAddress)); - ABI_CHECK(callContractFunction("deleteElements()"), encodeArgs(u256(0))); - BOOST_CHECK(storageEmpty(m_contractAddress)); - ABI_CHECK(callContractFunction("copy()"), encodeArgs(u256(0))); - BOOST_CHECK(storageEmpty(m_contractAddress)); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "A"); + ABI_CHECK(callContractFunction("data1()"), encodeDyn(string("123"))); + ABI_CHECK(callContractFunction("lengthChange()"), encodeArgs(u256(0))); + BOOST_CHECK(storageEmpty(m_contractAddress)); + ABI_CHECK(callContractFunction("deleteElements()"), encodeArgs(u256(0))); + BOOST_CHECK(storageEmpty(m_contractAddress)); + ABI_CHECK(callContractFunction("copy()"), encodeArgs(u256(0))); + BOOST_CHECK(storageEmpty(m_contractAddress)); + ) } BOOST_AUTO_TEST_CASE(calldata_offset) @@ -3901,17 +3946,20 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library) receive () external payable {} } )"; - compileAndRun(sourceCode, 0, "lib"); - Address libraryAddress = m_contractAddress; - compileAndRun(sourceCode, 10, "c"); - BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); - BOOST_CHECK_EQUAL(balanceAt(libraryAddress), 0); - ABI_CHECK(callContractFunction("f(address)", encodeArgs(libraryAddress)), encodeArgs(false)); - BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); - BOOST_CHECK_EQUAL(balanceAt(libraryAddress), 0); - ABI_CHECK(callContractFunction("f(address)", encodeArgs(m_contractAddress)), encodeArgs(true)); - BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); - BOOST_CHECK_EQUAL(balanceAt(libraryAddress), 0); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "lib"); + Address libraryAddress = m_contractAddress; + compileAndRun(sourceCode, 10, "c"); + BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); + BOOST_CHECK_EQUAL(balanceAt(libraryAddress), 0); + ABI_CHECK(callContractFunction("f(address)", encodeArgs(libraryAddress)), encodeArgs(false)); + BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); + BOOST_CHECK_EQUAL(balanceAt(libraryAddress), 0); + ABI_CHECK(callContractFunction("f(address)", encodeArgs(m_contractAddress)), encodeArgs(true)); + BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); + BOOST_CHECK_EQUAL(balanceAt(libraryAddress), 0); + ) } BOOST_AUTO_TEST_CASE(create_memory_array_allocation_size) @@ -3970,10 +4018,13 @@ BOOST_AUTO_TEST_CASE(using_for_function_on_struct) } } )"; - compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); - ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(3 * 7))); - ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(3 * 7))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "D"); + compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(3 * 7))); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(3 * 7))); + ) } BOOST_AUTO_TEST_CASE(using_for_overload) @@ -3993,10 +4044,13 @@ BOOST_AUTO_TEST_CASE(using_for_overload) } } )"; - compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); - ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(6 * 7))); - ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "D"); + compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(6 * 7))); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7))); + ) } BOOST_AUTO_TEST_CASE(using_for_by_name) @@ -4012,10 +4066,13 @@ BOOST_AUTO_TEST_CASE(using_for_by_name) } } )"; - compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); - ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(6 * 7))); - ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "D"); + compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(6 * 7))); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7))); + ) } BOOST_AUTO_TEST_CASE(bound_function_in_function) @@ -4032,9 +4089,12 @@ BOOST_AUTO_TEST_CASE(bound_function_in_function) function t() public pure returns (uint) { return 7; } } )"; - compileAndRun(sourceCode, 0, "L"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(7))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "L"); + compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(7))); + ) } BOOST_AUTO_TEST_CASE(bound_function_in_var) @@ -4050,10 +4110,13 @@ BOOST_AUTO_TEST_CASE(bound_function_in_var) } } )"; - compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); - ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(6 * 7))); - ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "D"); + compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + ABI_CHECK(callContractFunction("f(uint256)", u256(7)), encodeArgs(u256(6 * 7))); + ABI_CHECK(callContractFunction("x()"), encodeArgs(u256(6 * 7))); + ) } BOOST_AUTO_TEST_CASE(bound_function_to_string) @@ -4073,10 +4136,13 @@ BOOST_AUTO_TEST_CASE(bound_function_to_string) } } )"; - compileAndRun(sourceCode, 0, "D"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); - ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(3))); - ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(3))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "D"); + compileAndRun(sourceCode, 0, "C", bytes(), map{{"D", m_contractAddress}}); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(3))); + ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(3))); + ) } BOOST_AUTO_TEST_CASE(inline_long_string_return) @@ -4271,9 +4337,12 @@ BOOST_AUTO_TEST_CASE(payable_function_calls_library) } } )"; - compileAndRun(sourceCode, 0, "L"); - compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); - ABI_CHECK(callContractFunctionWithValue("f()", 27), encodeArgs(u256(7))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "L"); + compileAndRun(sourceCode, 0, "C", bytes(), map{{"L", m_contractAddress}}); + ABI_CHECK(callContractFunctionWithValue("f()", 27), encodeArgs(u256(7))); + ) } BOOST_AUTO_TEST_CASE(non_payable_throw) @@ -4296,16 +4365,19 @@ BOOST_AUTO_TEST_CASE(non_payable_throw) } )"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunctionWithValue("f()", 27), encodeArgs()); - BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 0); - ABI_CHECK(callContractFunction(""), encodeArgs()); - ABI_CHECK(callContractFunction("a()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunctionWithValue("", 27), encodeArgs()); - BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 0); - ABI_CHECK(callContractFunction("a()"), encodeArgs(u256(1))); - ABI_CHECK(callContractFunctionWithValue("a()", 27), encodeArgs()); - BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 0); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunctionWithValue("f()", 27), encodeArgs()); + BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 0); + ABI_CHECK(callContractFunction(""), encodeArgs()); + ABI_CHECK(callContractFunction("a()"), encodeArgs(u256(1))); + ABI_CHECK(callContractFunctionWithValue("", 27), encodeArgs()); + BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 0); + ABI_CHECK(callContractFunction("a()"), encodeArgs(u256(1))); + ABI_CHECK(callContractFunctionWithValue("a()", 27), encodeArgs()); + BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 0); + ) } BOOST_AUTO_TEST_CASE(mem_resize_is_not_paid_at_call) @@ -4340,11 +4412,14 @@ BOOST_AUTO_TEST_CASE(receive_external_function_type) } )"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction( - "f(function)", - m_contractAddress.asBytes() + FixedHash<4>(util::keccak256("g()")).asBytes() + bytes(32 - 4 - 20, 0) - ), encodeArgs(u256(7))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction( + "f(function)", + m_contractAddress.asBytes() + FixedHash<4>(util::keccak256("g()")).asBytes() + bytes(32 - 4 - 20, 0) + ), encodeArgs(u256(7))); + ) } BOOST_AUTO_TEST_CASE(return_external_function_type) @@ -5266,9 +5341,12 @@ BOOST_AUTO_TEST_CASE(event_signature_in_library) } } )"; - compileAndRun(sourceCode, 0, "C"); - BOOST_REQUIRE_EQUAL(numLogTopics(0), 2); - BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E((uint8,int16),(uint8,int16))"))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "C"); + BOOST_REQUIRE_EQUAL(numLogTopics(0), 2); + BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E((uint8,int16),(uint8,int16))"))); + ) } BOOST_AUTO_TEST_CASE(abi_encode_with_selector) @@ -5556,14 +5634,17 @@ BOOST_AUTO_TEST_CASE(event_wrong_abi_name) } } )"; - compileAndRun(sourceCode, 0, "ClientReceipt", bytes()); - compileAndRun(sourceCode, 0, "Test", bytes(), map{{"ClientReceipt", m_contractAddress}}); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "ClientReceipt", bytes()); + compileAndRun(sourceCode, 0, "Test", bytes(), map{{"ClientReceipt", m_contractAddress}}); - callContractFunction("f()"); - BOOST_REQUIRE_EQUAL(numLogs(), 1); - BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress); - BOOST_REQUIRE_EQUAL(numLogTopics(0), 3); - BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("Deposit(address,bytes32,uint256)"))); + callContractFunction("f()"); + BOOST_REQUIRE_EQUAL(numLogs(), 1); + BOOST_CHECK_EQUAL(logAddress(0), m_contractAddress); + BOOST_REQUIRE_EQUAL(numLogTopics(0), 3); + BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("Deposit(address,bytes32,uint256)"))); + ) } BOOST_AUTO_TEST_CASE(uninitialized_internal_storage_function) diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_array_named_pop_push.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_array_named_pop_push.sol index cd19d66f4..c684cc77f 100644 --- a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_array_named_pop_push.sol +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_array_named_pop_push.sol @@ -15,6 +15,5 @@ contract C { } // ==== // compileViaYul: also -// compileToEwasm: also // ---- // test() -> diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_bool.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_bool.sol index a21b8550c..33f5535ce 100644 --- a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_bool.sol +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_bool.sol @@ -13,7 +13,6 @@ contract C { } // ==== // compileViaYul: also -// compileToEwasm: also // ---- // foo(bool,bool): true, true -> false // foo(bool,bool): true, false -> true diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_contract.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_contract.sol index b7aaacb9d..a9566ca59 100644 --- a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_contract.sol +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_contract.sol @@ -17,6 +17,5 @@ contract C { // ==== // compileViaYul: also -// compileToEwasm: also // ---- // test() -> 42 diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_fixed_array.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_fixed_array.sol index 79c8826a6..842911079 100644 --- a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_fixed_array.sol +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_fixed_array.sol @@ -17,6 +17,5 @@ contract C { } // ==== // compileViaYul: also -// compileToEwasm: also // ---- // secondItem() -> 0x22 diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_fixed_bytes.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_fixed_bytes.sol index ea8ae12a1..02db54572 100644 --- a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_fixed_bytes.sol +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_fixed_bytes.sol @@ -13,6 +13,5 @@ contract C { } // ==== // compileViaYul: also -// compileToEwasm: also // ---- // sum(bytes2,bytes2): left(0x1100), left(0x0022) -> left(0x1122) diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_function_named_selector.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_function_named_selector.sol index 18dadbc87..75c4e4cb8 100644 --- a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_function_named_selector.sol +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_function_named_selector.sol @@ -18,6 +18,5 @@ contract C { // ==== // compileViaYul: also -// compileToEwasm: also // ---- // test(uint256): 5 -> 10 diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_integer.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_integer.sol index 47f8af110..258e4940c 100644 --- a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_integer.sol +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_integer.sol @@ -13,6 +13,5 @@ contract C { } // ==== // compileViaYul: also -// compileToEwasm: also // ---- // foo(uint256,uint256): 8, 42 -> 50 diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_interface.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_interface.sol index f7939b83e..47e58bb32 100644 --- a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_interface.sol +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_interface.sol @@ -18,6 +18,5 @@ contract C { // ==== // compileViaYul: also -// compileToEwasm: also // ---- // test() -> 42 diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_internal_function.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_internal_function.sol index dec984601..519eafddd 100644 --- a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_internal_function.sol +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_internal_function.sol @@ -18,6 +18,5 @@ contract C { // ==== // compileViaYul: also -// compileToEwasm: also // ---- // test(uint256): 5 -> 10 diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_string.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_string.sol index 90e41e956..d8d420512 100644 --- a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_string.sol +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_string.sol @@ -14,6 +14,5 @@ contract C { } // ==== // compileViaYul: also -// compileToEwasm: also // ---- // secondChar() -> 98 diff --git a/test/libsolidity/semanticTests/libraries/library_address.sol b/test/libsolidity/semanticTests/libraries/library_address.sol index 6ca064445..b3ce25f9e 100644 --- a/test/libsolidity/semanticTests/libraries/library_address.sol +++ b/test/libsolidity/semanticTests/libraries/library_address.sol @@ -35,6 +35,7 @@ contract C { } } // ==== +// compileViaYul: also // EVMVersion: >=byzantium // ---- // library: L diff --git a/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_pure.sol b/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_pure.sol index b540e9a63..1df8aa300 100644 --- a/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_pure.sol +++ b/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_pure.sol @@ -24,6 +24,7 @@ contract C { } } // ==== +// compileViaYul: also // EVMVersion: >homestead // ---- // library: L diff --git a/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_needed.sol b/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_needed.sol index 3c5274990..3d1356b1e 100644 --- a/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_needed.sol +++ b/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_needed.sol @@ -24,6 +24,7 @@ contract C { } } // ==== +// compileViaYul: also // EVMVersion: >homestead // ---- // library: L diff --git a/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_not_needed.sol b/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_not_needed.sol index 2d4e6468e..2928af0a9 100644 --- a/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_not_needed.sol +++ b/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_not_needed.sol @@ -23,6 +23,7 @@ contract C { } } // ==== +// compileViaYul: also // EVMVersion: >homestead // ---- // library: L diff --git a/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_staticcall.sol b/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_staticcall.sol index d8cdb9a4d..7f6fdfe92 100644 --- a/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_staticcall.sol +++ b/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_staticcall.sol @@ -23,6 +23,7 @@ contract C { } } // ==== +// compileViaYul: also // EVMVersion: >homestead // ---- // library: L diff --git a/test/libsolidity/semanticTests/libraries/library_function_selectors.sol b/test/libsolidity/semanticTests/libraries/library_function_selectors.sol index baeb5cedd..c1a89f252 100644 --- a/test/libsolidity/semanticTests/libraries/library_function_selectors.sol +++ b/test/libsolidity/semanticTests/libraries/library_function_selectors.sol @@ -22,6 +22,7 @@ contract C { } } // ==== +// compileViaYul: also // EVMVersion: >homestead // ---- // library: L diff --git a/test/libsolidity/semanticTests/libraries/library_function_selectors_struct.sol b/test/libsolidity/semanticTests/libraries/library_function_selectors_struct.sol index 186fad7db..c3c25f304 100644 --- a/test/libsolidity/semanticTests/libraries/library_function_selectors_struct.sol +++ b/test/libsolidity/semanticTests/libraries/library_function_selectors_struct.sol @@ -20,6 +20,7 @@ contract C { } } // ==== +// compileViaYul: also // EVMVersion: >homestead // ---- // library: L diff --git a/test/libsolidity/semanticTests/libraries/library_return_struct_with_mapping.sol b/test/libsolidity/semanticTests/libraries/library_return_struct_with_mapping.sol index 00001a2f8..bb3c26f8c 100644 --- a/test/libsolidity/semanticTests/libraries/library_return_struct_with_mapping.sol +++ b/test/libsolidity/semanticTests/libraries/library_return_struct_with_mapping.sol @@ -16,6 +16,8 @@ contract C { assembly { slot := ptr.slot } } } +// ==== +// compileViaYul: also // ---- // library: Lib // f() -> 123 diff --git a/test/libsolidity/semanticTests/libraries/using_for_storage_structs.sol b/test/libsolidity/semanticTests/libraries/using_for_storage_structs.sol index 086ab8a84..2749fb444 100644 --- a/test/libsolidity/semanticTests/libraries/using_for_storage_structs.sol +++ b/test/libsolidity/semanticTests/libraries/using_for_storage_structs.sol @@ -23,6 +23,5 @@ contract C { } // ==== // compileViaYul: also -// compileToEwasm: also // ---- // g() -> 7, 7