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

Call For Action: standard library for Solidity #228

Open
axic opened this issue Nov 18, 2015 · 12 comments
Open

Call For Action: standard library for Solidity #228

axic opened this issue Nov 18, 2015 · 12 comments
Labels
high effort A lot to implement but still doable by a single person. The task is large or difficult. high impact Changes are very prominent and affect users or the project in a major way. selected for development It's on our short-term development stdlib

Comments

@axic
Copy link
Member

axic commented Nov 18, 2015

Call For Action: "Standard Solidity Library"

Solidity is quickly improving thanks to the work of everyone involved. The compiler is getting in a better shape every day and providing the low level features nicely, however support for higher level features still needs to improve. Many have created helper functions, but all these efforts are scattered around in different places.

I have created a tree called density as a start to this effort. So far it contains a very limited set of features:

  • the two missing bitwise operators (shl, shr)
  • the basic design patterns (owned, mortal and interface)
  • interfaces for the standard contract APIs (so far, token only)

I've did the above a week ago, but only pushed it now. I have also some string utilities, such as conversion of address to string, which I haven't committed yet.

I wasn't able to find everything via Google before, but now more and more such snippets have surfaced. Either I'm getting bad at using Google or it is harder to get meaningful results out of it. The following "libraries" already exists out there:

  • dapp-bin/library has a few utilities already (strings, linked list, and recently two pull requests for maths)
  • the oraclize.it API has a few string related functions
  • the ether.camp IDE has a snippet called std.sol

I think the standard library should contain:

  • the basic design patterns (owner only, mortal, etc.)
  • interfaces for the Standardized Contract APIs
  • useful string helpers
  • support for bitwise operators until EVM and Solidity supports it natively
  • have a basic math library (which also supports ‘floating points’ to at least 2 decimal places) (also, FIXME: define "basic")
  • has other basic helpers in place for conversion between types (those which aren’t natively supported)

I don’t think it should go into dapp-bin, but a separate tree for the library only. And that tree probably should belong to an org on github as opposed to a person.

The questions are:

  • what structure should it have (a lot of questions here)?
  • what should be included?
  • what should be the goal for the code (readability/understandability, effectiveness i.e. gas cost, ..)?
  • what license should it be under (safe to assume MIT, as every piece of code involved is already under it)?
  • what should it be named?
  • where should such a library be placed?
  • anything else?

Based on git history, the following users have contributed to the libraries: @chriseth, @fivedogit, @obscuren, @bertani, @pipermerriam. Calling all you guys for input.

Appendix A. - List of useful helpers

@chriseth
Copy link
Contributor

In my opinion, the library should be extremely well documented using natspec and if possible, it should be formally verified.
It should also be semantically versioned, potentially providing a "staging area" with proposed updates which can be discussed and then accepted or rejected/amended.

Are there any opinions against putting it inside the solidity repository?

@pipermerriam
Copy link
Member

the library should be extremely well documented using natspec and if possible

+1. I'm in favor of requiring inclusion of proper natspec as well as documentation.

it should be formally verified.

Future requirement? This isn't currently doable correct?

It should also be semantically versioned

+1 but we should be sure to declare what semantic versioning means.

Are there any opinions against putting it inside the solidity repository?

I would like to be able to have the documentation live alongside the code. Readthedocs is an easy to configure resource for this sort of thing, so if it goes in the solidity library, I'd like for the docs to be able to live in the same branch as the code (as opposed to the ghpages branch that the current docs have to live in. If they aren't side-by-side, it's hard to enforce documentation with code modifications and additions.

I'm advocating a hard requirement of documentation because a culture of good documentation will pay us back 10 fold in making it easier for new devs to get up to speed.

@simondlr
Copy link

My gut feel is that although it would be nice to have standard APIs in the standard libraries, it's a bit too early to start pushing them in there. We don't quite know where these standards will go. Even now, we are changing it (https://gist.github.com/frozeman/090ae32041bcfe120824).

@anthony-cros
Copy link

are functions a first-class citizen in solidity? if so, it would be great to have the map(), flatMap(), filter() and reduce() constructs at the very least!

and if they're not, then maybe using an "functional interface" equivalent as java 8 does...

@chriseth
Copy link
Contributor

chriseth pushed a commit to chriseth/solidity that referenced this issue Dec 7, 2015
d5d2115 example contract using array, fixed ethereum#185
21ed235 removed connection keep-alive
c44fe01 version 0.7.1
d9b785e fixed ethereum#248
490dde5 fixed encoding/decoding strings, ethereum#249
b3f5d09 fixed long bytes dynamic decoding/encoding, ethereum#249
d097821 small filter improvement
d59b1cd removed xhr from browser
42b6e9d version 0.7.0
fe6defd gulp
44dcd24 set connection keepalive
2b17c0f gulpfile changes
4a46c73 Merge pull request ethereum#228 from ethereum/strings
93c8006 tests for encoding and decoding prematurely terminated strings and strings containing internal zeros
7dd44e7 Merge branch 'strings' of https://github.com/ethereum/ethereum.js into strings
390a9ff Merge branch 'develop' into strings
bcd9cfb updated deps, removed unused karma
ef15fc1 Merge pull request ethereum#244 from ethereum/allevents
6f74d57 Merge branch 'develop' into allevents
7aca17e Merge branch 'develop' into allevents
c5ee34d fix for optional event parameters
8170a0a Merge pull request ethereum#245 from ethereum/filterInstantWatch
76a094c fixed all issues noted by marek
d78b512 add possible callback to filters
e1b17a9 re-build develop
af9c027 all events filter
b270616 version 0.6.1
c47d6a8 gulp
7cf7cf3 map file
6da1d3e gulp
450042e Update eth.js
3951286 Added sendRawTransaction
323b529 merged develop
16ffdf6 merged master
ecf0a2c changed | to Math.floor
d2b5ba2 Merge pull request ethereum#239 from ethereum/mistFixes
9e6bf9d removed browser XHR
9061116 fixed build issues in formatInputDynamicBytes
0e3b29c fixed coverage issue
d51e9a2 merged latest develop
f0247aa made meteor package available on the server side as well
e97c5f5 fixed and tested meteor package init
3e49f56 add currentProvidor and mist fixes
bd6d9ba merged develop
7b730b1 Merge branch 'strings' of github.com:ethereum/web3.js into strings
cc533d9 fixed bytes wrong encoding
8c6f976 Merge branch 'develop' into strings
7c970e3 add bytes32 test with leading 0
9c7f7bb re-add .map files
189484f add extra int tests
73cc711 Merge branch 'develop' into strings
fa3239f abi string type, fixes ethereum#216, ethereum#218, ethereum#219

git-subtree-dir: libjsqrc/ethereumjs
git-subtree-split: d5d2115bf9ad07a736a189e1022b7d3a549e4006
@androlo
Copy link
Contributor

androlo commented Mar 20, 2016

Not sure if it's been fixed, but last time I documented with natspec it was not possible to document multiple return-values (like you do multiple params). It works, but it isn't formatted properly in devdoc. Natspec in general feels a bit under-developed, Perhaps start in that end?

I would be happy to contribute to this in any way I can, code, documentation, tests. Especially tests. I can probably put in as much as 20-25% time.

I think it is essential to have some way to run code directly through the EVM for testing. If the standard library is put in the Solidity rep like suggested, it would be simple to write either a separate suite or maybe include it in the regular library tests, depending on what's best.

@redsquirrel
Copy link
Contributor

Any updates on this project/issue?

@androlo
Copy link
Contributor

androlo commented Apr 26, 2016

I'm doing some contract that might make it in at some point (in fact I do them on chriseth's request), including a secp256k1 implementation, some string stuff etc. Gonna have RLP encoding/decoding and other Ethereum related functionality as well.

There is still the issue of how tests will be carried out and such, which is why i work in a separate repo. There's a new issue on how to do it from RPC (#516), and when that's been settled maybe they will be accepted into official Solidity stl. In that case I will port the tests to that system.

Link: https://github.com/androlo/solidity-contracts

@androlo
Copy link
Contributor

androlo commented Jun 19, 2016

Standard library!

(Made by a group of people that checks each-others code etc.)

@redsquirrel
Copy link
Contributor

See also @vbuterin's post: https://blog.ethereum.org/2016/06/19/thinking-smart-contract-security/

take common patterns and hardcode them ... create as many standardized mid-level components as possible

@chriseth
Copy link
Contributor

chriseth commented Aug 5, 2016

This is an ongoing process and will never be "closed", although we need a kind of "registry" of library contracts. I hope that tools like dapphub and live-libs can fill this gap soon.

@chriseth chriseth added this to the 99-nice-but-how milestone Aug 5, 2016
@axic
Copy link
Member Author

axic commented Aug 15, 2016

support for bitwise operators until EVM and Solidity supports it natively

This from the original discussion is not a concern anymore after #527 is done.

@axic axic added feature and removed enhancement labels Oct 6, 2017
@cameel cameel added selected for development It's on our short-term development high effort A lot to implement but still doable by a single person. The task is large or difficult. high impact Changes are very prominent and affect users or the project in a major way. labels Sep 27, 2022
@cameel cameel added the stdlib label Apr 4, 2023
@NunoFilipeSantos NunoFilipeSantos removed this from the 99-nice-but-how milestone Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high effort A lot to implement but still doable by a single person. The task is large or difficult. high impact Changes are very prominent and affect users or the project in a major way. selected for development It's on our short-term development stdlib
Projects
None yet
Development

No branches or pull requests

10 participants