0

I was able to declare this constant as a bytes object, but am trying to compress it for efficiency, and I'm getting this error message:

Only constants of value type and byte array type are implemented.

I don't understand, is this not a byte array? why is this error happening? is there a way to convert such a number to a fixed size byte array?

bytes32[8] public constant N = [bytes32(hex'c7970ceedcc3b0754490201a7aa613cd73911081c790f5f1a8726f463550bb5b'), 
bytes32(hex'7ff0db8e1ea1189ec72f93d1650011bd721aeeacc2acde32a04107f0648c2813'), 
bytes32(hex'a31f5b0b7765ff8b44b4b6ffc93384b646eb09c7cf5e8592d40ea33c80039f35'), 
bytes32(hex'b4f14a04b51f7bfd781be4d1673164ba8eb991c2c4d730bbbe35f592bdef524a'), 
bytes32(hex'f7e8daefd26c66fc02c479af89d64d373f442709439de66ceb955f3ea37d5159'), 
bytes32(hex'f6135809f85334b5cb1813addc80cd05609f10ac6a95ad65872c909525bdad32'), 
bytes32(hex'bc729592642920f24c61dc5b3c3b7923e56b16a4d9d373d8721f24a3fc0f1b31'),
bytes32(hex'31f55615172866bccc30f95054c824e733a5eb6817f7bc16399d48c6361cc7e5')];

1 Answer 1

0

What "byte array type" means is the bytes type in Solidity. You cannot use any other array type for constant declarations as the time of writing.

The way you would declare a constant of the type bytes is as follows:

bytes public constant BYTE_ARRAY = hex'abcd';

For your example above, the correct way to do it would be as follows:

bytes public constant N = abi.encodePacked([
        bytes32(hex'c7970ceedcc3b0754490201a7aa613cd73911081c790f5f1a8726f463550bb5b'), 
        bytes32(hex'7ff0db8e1ea1189ec72f93d1650011bd721aeeacc2acde32a04107f0648c2813'), 
        bytes32(hex'a31f5b0b7765ff8b44b4b6ffc93384b646eb09c7cf5e8592d40ea33c80039f35'), 
        bytes32(hex'b4f14a04b51f7bfd781be4d1673164ba8eb991c2c4d730bbbe35f592bdef524a'), 
        bytes32(hex'f7e8daefd26c66fc02c479af89d64d373f442709439de66ceb955f3ea37d5159'), 
        bytes32(hex'f6135809f85334b5cb1813addc80cd05609f10ac6a95ad65872c909525bdad32'), 
        bytes32(hex'bc729592642920f24c61dc5b3c3b7923e56b16a4d9d373d8721f24a3fc0f1b31'),
        bytes32(hex'31f55615172866bccc30f95054c824e733a5eb6817f7bc16399d48c6361cc7e5')
]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.