diff --git a/CMakeLists.txt b/CMakeLists.txt index f4d67e243bab..5792563eb3c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ include(EthPolicy) eth_policy() # project name and version should be set after cmake_policy CMP0048 -set(PROJECT_VERSION "0.8.32") +set(PROJECT_VERSION "0.8.33") # OSX target needed in order to support std::visit set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14") project(solidity VERSION ${PROJECT_VERSION} LANGUAGES C CXX) diff --git a/Changelog.md b/Changelog.md index 93edad52899a..f556c98d2125 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,9 @@ +### 0.8.33 (2025-12-18) + +Bugfixes: +* TypeChecker: Fix internal error when accessing getters of constant variables. + + ### 0.8.32 (2025-12-18) Important Bugfixes: diff --git a/docs/bugs_by_version.json b/docs/bugs_by_version.json index 5282948776c2..d185171ec576 100644 --- a/docs/bugs_by_version.json +++ b/docs/bugs_by_version.json @@ -2081,6 +2081,10 @@ "bugs": [], "released": "2025-12-18" }, + "0.8.33": { + "bugs": [], + "released": "2025-12-18" + }, "0.8.4": { "bugs": [ "UnsoundSpillInMutualRecursion", diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 656f7514a409..4d8967aae859 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -3456,16 +3456,6 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) if (!annotation.isPure.set()) annotation.isPure = false; - if ( - auto const* funcType = dynamic_cast(annotation.type); - funcType && - funcType->kind() != FunctionType::Kind::Declaration && - funcType->kind() != FunctionType::Kind::Internal && - funcType->kind() != FunctionType::Kind::Error && - funcType->kind() != FunctionType::Kind::Event - ) - solAssert(funcType->isPure() == *annotation.isPure); - return false; } diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index fd18ac44b363..722a9fb6b32b 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -1105,6 +1105,10 @@ std::string ABIFunctions::abiDecodingFunction(Type const& _type, bool _fromMemor std::string ABIFunctions::abiDecodingFunctionValueType(Type const& _type, bool _fromMemory) { + if (auto const* valueType = dynamic_cast(&_type)) + if (valueType->underlyingType().category() == Type::Category::Address) + return abiDecodingFunctionValueType(valueType->underlyingType(), _fromMemory); + Type const* decodingType = _type.decodingType(); solAssert(decodingType, ""); solAssert(decodingType->sizeOnStack() == 1, ""); diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index c3dcf3647c80..ebd91d14c6b5 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -890,7 +890,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) // gas <- gas * !value m_context << Instruction::SWAP1 << Instruction::DUP2; m_context << Instruction::ISZERO << Instruction::MUL << Instruction::SWAP1; - arguments[1]->accept(*this); + acceptAndConvert(*arguments[1], *function.parameterTypes()[1], true); // will be removed in next release m_context << Instruction::DUP1 << Instruction::ISZERO; diff --git a/libsolidity/codegen/YulUtilFunctions.cpp b/libsolidity/codegen/YulUtilFunctions.cpp index 4c3cd8c0fc69..28f87bd78251 100644 --- a/libsolidity/codegen/YulUtilFunctions.cpp +++ b/libsolidity/codegen/YulUtilFunctions.cpp @@ -4041,6 +4041,10 @@ std::string YulUtilFunctions::cleanupFunction(Type const& _type) std::string YulUtilFunctions::validatorFunction(Type const& _type, bool _revertOnFailure) { + if (auto const* valueType = dynamic_cast(&_type)) + if (valueType->underlyingType().category() == Type::Category::Address) + return validatorFunction(valueType->underlyingType(), _revertOnFailure); + std::string functionName = std::string("validator_") + (_revertOnFailure ? "revert_" : "assert_") + _type.identifier(); return m_functionCollector.createFunction(functionName, [&]() { Whiskers templ(R"( diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index eced46153cad..7f48d1d6674c 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -735,6 +735,40 @@ contract C { BOOST_TEST(ir.find("if mod(returndatasize(), 0x20) { revert(0, 0) }") != std::string::npos); } +BOOST_AUTO_TEST_CASE(tron_transfer_token_narrowed_id) +{ + for (bool optimize: {false, true}) + { + auto runtimeFor = [&](std::string const& _tokenId) { + std::string sourceCode = R"( +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.0; +contract C { + function transfer(address payable recipient, uint256 x) external { + recipient.transferToken(100, TOKEN_ID); + } + function transferConstant(address payable recipient) external { + uint256 x = (1 << 64) + 1000001; + recipient.transferToken(100, TOKEN_ID); + } +} +)"; + boost::replace_all(sourceCode, "TOKEN_ID", _tokenId); + Json input = createLanguageAndSourcesSection("Solidity", {{"A.sol", sourceCode}}); + input["settings"]["optimizer"]["enabled"] = optimize; + input["settings"]["metadata"]["appendCBOR"] = false; + input["settings"]["outputSelection"]["*"]["*"] = Json::array({"evm.deployedBytecode.object"}); + Json const output = compile(input.dump()); + BOOST_REQUIRE(containsAtMostWarnings(output)); + return output["contracts"]["A.sol"]["C"]["evm"]["deployedBytecode"]["object"].get(); + }; + // Implicit widening to trcToken must consume the same value as explicit widening. + std::string const cleaned = runtimeFor("uint256(uint24(x))"); + BOOST_CHECK_EQUAL(runtimeFor("uint24(x)"), cleaned); + BOOST_CHECK(runtimeFor("x") != cleaned); + } +} + BOOST_AUTO_TEST_CASE(compilation_error) { char const* input = R"( diff --git a/test/libsolidity/semanticTests/userDefinedValueType/tron_address_abi.sol b/test/libsolidity/semanticTests/userDefinedValueType/tron_address_abi.sol new file mode 100644 index 000000000000..78625da7b130 --- /dev/null +++ b/test/libsolidity/semanticTests/userDefinedValueType/tron_address_abi.sol @@ -0,0 +1,56 @@ +pragma abicoder v2; +type MyAddress is address; +type MyPayableAddress is address payable; +type MyUint24 is uint24; +type MyBool is bool; +type MyBytes2 is bytes2; + +contract C { + // Payable entry points let the generic EVM test host exercise the ABI decoder + // without the TRON-specific non-payable CALLTOKENID/CALLTOKENVALUE checks. + constructor() payable {} + + function plain(address a) external payable returns (address) { return a; } + function wrapped(MyAddress a) external payable returns (MyAddress) { return a; } + function raw(MyAddress a) external payable returns (uint256 value) { + assembly { value := a } + } + function wrappedPayable(MyPayableAddress a) external payable returns (MyPayableAddress) { return a; } + function decode(bytes memory data) external payable returns (MyAddress) { + return abi.decode(data, (MyAddress)); + } + function calldataArray(MyAddress[] calldata data) external payable returns (MyAddress) { return data[0]; } + function memoryArray(MyAddress[] memory data) external payable returns (MyAddress) { return data[0]; } + + function integer(MyUint24 value) external payable returns (MyUint24) { return value; } + function boolean(MyBool value) external payable returns (MyBool) { return value; } + function fixedBytes(MyBytes2 value) external payable returns (MyBytes2) { return value; } +} +// ==== +// EVMVersion: >=byzantium +// compileViaYul: also +// ---- +// plain(address): 0x1234 -> 0x1234 +// plain(address): 0x410000000000000000000000000000000000001234 -> 0x1234 +// plain(address): 0x01410000000000000000000000000000000000001234 -> FAILURE +// wrapped(address): 0x1234 -> 0x1234 +// wrapped(address): 0x410000000000000000000000000000000000001234 -> 0x1234 +// wrapped(address): 0xff0000000000000000000000000000000000001234 -> 0x1234 +// wrapped(address): 0x01410000000000000000000000000000000000001234 -> FAILURE +// raw(address): 0x410000000000000000000000000000000000001234 -> 0x1234 +// wrappedPayable(address): 0x410000000000000000000000000000000000001234 -> 0x1234 +// decode(bytes): 0x20, 0x20, 0x1234 -> 0x1234 +// decode(bytes): 0x20, 0x20, 0x410000000000000000000000000000000000001234 -> 0x1234 +// decode(bytes): 0x20, 0x20, 0x01410000000000000000000000000000000000001234 -> FAILURE +// calldataArray(address[]): 0x20, 1, 0x1234 -> 0x1234 +// calldataArray(address[]): 0x20, 1, 0x410000000000000000000000000000000000001234 -> 0x1234 +// calldataArray(address[]): 0x20, 1, 0x01410000000000000000000000000000000000001234 -> FAILURE +// memoryArray(address[]): 0x20, 1, 0x1234 -> 0x1234 +// memoryArray(address[]): 0x20, 1, 0x410000000000000000000000000000000000001234 -> 0x1234 +// memoryArray(address[]): 0x20, 1, 0x01410000000000000000000000000000000000001234 -> FAILURE +// integer(uint24): 0xffffff -> 0xffffff +// integer(uint24): 0x1000000 -> FAILURE +// boolean(bool): 1 -> true +// boolean(bool): 2 -> FAILURE +// fixedBytes(bytes2): 0x1234000000000000000000000000000000000000000000000000000000000000 -> 0x1234000000000000000000000000000000000000000000000000000000000000 +// fixedBytes(bytes2): 0x1234000000000000000000000000000000000000000000000000000000000001 -> FAILURE diff --git a/test/libsolidity/syntaxTests/constants/access_via_getter.sol b/test/libsolidity/syntaxTests/constants/access_via_getter.sol new file mode 100644 index 000000000000..686c5a03927e --- /dev/null +++ b/test/libsolidity/syntaxTests/constants/access_via_getter.sol @@ -0,0 +1,8 @@ +contract Counter { + uint256 public constant MIN_LIQUIDITY = 1000; + + function run() view public { + this.MIN_LIQUIDITY(); + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/immutable/access_via_getter.sol b/test/libsolidity/syntaxTests/immutable/access_via_getter.sol new file mode 100644 index 000000000000..6ce9e42c4301 --- /dev/null +++ b/test/libsolidity/syntaxTests/immutable/access_via_getter.sol @@ -0,0 +1,8 @@ +contract Counter { + uint256 public immutable MIN_LIQUIDITY = 1000; + + function run() view public { + this.MIN_LIQUIDITY(); + } +} +// ----