I ran into the eip-170 contract code size limitation. I need to trim it down. Do comments affect the size of the contract as I have a lot of them and don't mind getting rid of them.
1 Answer
No, they affect only the contents of the hashed-metadata part in the bytecode, which is the 32 bytes (64 hexadecimal characters) which appear right before the last 2 bytes (4 hexadecimal characters).
The compiler appends a hash of the file's metadata (which includes your comments) at the end of the bytecode, so that you can retrieve this file in an authenticated manner.
UPDATE:
As of solc 0.5.x, those last 2 bytes have changed to 11 bytes (22 hexadecimal characters).
-
What do you recommend to reduce contract size? Is there a way to import Github files? I do not want to deploy it over the solidity compiler, I'd rather use remix. Oct 22, 2019 at 8:55
-
1@NikLoladze: That would yield the exact same code, hence the exact same code size. You can try to reduce your actual code. Since you haven't posted it in a convenient manner (copyable plain text), the community here (with me included) will be kinda reluctant to help you with that. Oct 22, 2019 at 8:58
-
Note to future readers: the metadata is in fact the 32 bytes (64 hexadecimal characters) which appear right before the last 2 bytes (4 hexadecimal characters). Also, starting from solc 0.5.x, those 2 bytes have changed to 11 bytes (22 hexadecimal characters). Nov 3, 2020 at 14:19