Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trailing zeros padding to _toString #415

Merged
merged 1 commit into from
Aug 26, 2022

Conversation

Vectorized
Copy link
Collaborator

@Vectorized Vectorized commented Aug 25, 2022

When assembly is used to directly return the string (i.e. using return(offset, length) in Yul), it skips the built-in Solidity bookkeeping to copy and pad the string with zeros to the next word.

This can cause some issues with Etherscan decoding, like the name() function on Seaport.

Credits to @hrkrshnn for highlighting this obscure behavior.

This PR allocates an extra zeroed word to pad the string at the end, at the cost of a little additional gas. This is in case someone tries to use Yul to return strings.

Currently, using the unpadded _toString in plain Solidity, or in abi.encodePacked, or in string.concat will not cause any frontend issue. As long as devs don't use assembly to directly return the result of the unpadded _toString, the frontends will decode fine (probably near 100% of devs -- even I don't do manual assembly returns for strings).

@Vectorized Vectorized requested a review from cygaar August 25, 2022 04:35
@Vectorized Vectorized merged commit 8827b5f into chiru-labs:main Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants