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

Strings library #1746

Merged
merged 21 commits into from
May 27, 2019
Merged

Strings library #1746

merged 21 commits into from
May 27, 2019

Conversation

abcoathup
Copy link
Contributor

WIP for #1745

Add basic Strings library with Concatenate and UintToString functions to start things off.

Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @abcoathup, thank you very much! I left a couple comments on both the contracts and the test structure.

contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
contracts/drafts/Strings.sol Show resolved Hide resolved
contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
test/drafts/Strings.test.js Outdated Show resolved Hide resolved
abcoathup and others added 5 commits May 13, 2019 17:29
Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com>
Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com>
Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com>
Copy link
Contributor Author

@abcoathup abcoathup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outstanding is the inner working of the functions. All the other changes requested should be updated.

You had asked about bytes memory bytesA = bytes(a); whether this creates a new array or is an alias. Unfortunately I don't know

contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
test/drafts/Strings.test.js Outdated Show resolved Hide resolved
@nventuro
Copy link
Contributor

Awesome @abcoathup, thanks!

This is all I've found regarding copy operations: https://solidity.readthedocs.io/en/v0.5.8/control-structures.html?highlight=copy#complications-for-arrays-and-structs

It's sadly incomplete and not very clear, I've asked in the Solidity gitter channel about this: https://gitter.im/ethereum/solidity?at=5cd9bb7c0f381d0a76add441

@frangio frangio changed the title Feature/issue #1745 Strings library (with concatenation) May 14, 2019
@frangio frangio changed the title Strings library (with concatenation) Strings library May 14, 2019
@nventuro
Copy link
Contributor

Apparently those assignments won't create actual copies of the data (as you've assumed), but I'm not yet 100% sure that's the case. I created ethereum/solidity#6763 asking for the official documentation to be update, we should be on the lookout for replies to it.

Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work @abcoathup! I left a couple comments about the tests and implementation.

contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
test/drafts/Strings.test.js Outdated Show resolved Hide resolved
@nventuro
Copy link
Contributor

So, after looking around for a bit for the word-copying thing I mentioned, I came across https://github.com/Arachnid/solidity-stringutils, which is rather complete and well-made, albeit unmaintained (it targets Solidity ^0.4.14, and there's been a PR adding 0.5 support open for over two months with no replies). It also lacks distribution and versioning (the readme suggests importing from the GitHub master branch). It's Apache v2 licensed.

@frangio what do you think we should do in this scenario? I wouldn't mind having it as a dependency, if it weren't for the lack of versioning, distribution, and support for v0.5.x. Bringing (a subset) of it into OpenZeppelin also sounds like a good idea (it'd be adding what this very PR adds), but I'm not sure how licensing would play into that.

@frangio
Copy link
Contributor

frangio commented May 14, 2019

Having it as a dependency is not a possibility, because smart contract development tools AFAIK don't support "transitive" dependencies.

Bringing some of that project's code into OpenZeppelin would be interesting but I also don't know how licensing plays into it. I would prefer to just implement ourselves the little functionality needed for this PR.

@nventuro
Copy link
Contributor

We could extend our prepack script to bundle those dependencies, as a workaround.

Implementing this ourselves is not a bad plan, but I worry there may be tricky bits we haven't considered (like my comment about UTF-8 strings) that have been already tackled by that library.

@abcoathup
Copy link
Contributor Author

I mentioned Nick's string library in the issue #1745 as I had only just come across it. Sorry if that wasn't clearer.

Though may want to consider the strings library by Nick Johnson https://github.com/Arachnid/solidity-stringutils/blob/master/src/strings.sol

I have changed the concatenate implementation as I just came across a different solution which looks ok using abi.encodePacked

https://ethereum.stackexchange.com/a/56337/53724
ethereum/solidity#4704

What do you think for concatenation?

For the use case of returning a token URI we only need concatenation and conversion of a uint256 to a string.

@frangio
Copy link
Contributor

frangio commented May 17, 2019

Ohh that is very cool! I personally would consider removing concatenate altogether then. abi.encodePacked is superior in that it can receive a variable number of arguments.

contracts/mocks/StringsMock.sol Outdated Show resolved Hide resolved
test/drafts/Strings.test.js Outdated Show resolved Hide resolved
contracts/drafts/Strings.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks a lot for your work @abcoathup!

@nventuro nventuro merged commit fbbff53 into OpenZeppelin:master May 27, 2019
@abcoathup abcoathup deleted the feature/issue-#1745 branch June 4, 2019 05:55
@nventuro nventuro mentioned this pull request Jun 13, 2019
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

3 participants