ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
22.76k stars 5.64k forks source link

`bytes.concat` is not allowed in constant initializers #14509

Open ItsNickBarry opened 11 months ago

ItsNickBarry commented 11 months ago

Description

bytes.concat does not work when defining constants.

Environment

Steps to Reproduce

This code compiles:

contract Test {
    bytes32 internal constant A = bytes32('a');
    bytes32 internal constant B = bytes32('b');
    bytes internal constant AB = abi.encodePacked(A, B);
}

This does not:

contract Test {
    bytes32 internal constant A = bytes32('a');
    bytes32 internal constant B = bytes32('b');
    bytes internal constant AB = bytes.concat(A, B);
}
ekpyron commented 11 months ago

Solidity currently generally doesn't have compile-time constant expression evaluation - we plan to change that in the future and this will extend to bytes.concat as well, so I'm closing this issue as covered by https://github.com/ethereum/solidity/issues/3157

EDIT: actually, looking at it again, the divergence between abi.encodePacked and bytes.concat is inconsistent - sorry, I didn't look properly earlier. There is no compile-time constant evaluation happening for abi.encodePacked, but the expression is allowed as constant and inlined - we can look into doing the same for bytes.concat for consistency, even though ideally this would be covered by proper compile-time constant expression evaluation a la https://github.com/ethereum/solidity/issues/3157

gerceboss commented 2 months ago

I am new to this repository , can someone guide me about how can I help in solving this issue? Do we need to implement the concat function taking inputs as const initializers as well? And if yes, where can I find its implementation? @ekpyron