Skip to content
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libsolidity/codegen/ABIFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserDefinedValueType const*>(&_type))
if (valueType->underlyingType().category() == Type::Category::Address)
return abiDecodingFunctionValueType(valueType->underlyingType(), _fromMemory);

Type const* decodingType = _type.decodingType();
solAssert(decodingType, "");
solAssert(decodingType->sizeOnStack() == 1, "");
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions libsolidity/codegen/YulUtilFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserDefinedValueType const*>(&_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"(
Expand Down
34 changes: 34 additions & 0 deletions test/libsolidity/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>();
};
// 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"(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Loading