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 solidity-uint compatibility example, ERC20 #366

Merged
merged 9 commits into from
Oct 22, 2017

Conversation

pdaian
Copy link
Contributor

@pdaian pdaian commented Sep 28, 2017

- What I did

Add well tested Solidity-compatible ERC20 example usable as a base for future tokens, in Viper.

I'm not sure whether the best place for this code is in the Viper repo or in a separate vipererc20 style repository. Arguments for having it in the repo are that I think it's a useful example that people will want to practically use, and I believe test suite 1 is one of the most thorough ERC20 tests I've seen in any language. Arguments against center around the num256 datatype, which was chosen for Solidity interoperability but makes the code slightly less clean than is ideal (with inbuilt num256 functions used, and overflows checked manually).

Arguments against can perhaps be mitigated marginally by #355

- How I did it

A Viper contract was created using the num256 datatype to instantiate a 1:1 Ether-pegged ERC20 token (for compatibility with the ERC20 specification, which specifies uint256 as the datatype for ERC20s). Optional functions are not included. The contract is differentially tested against three ERC20s, two implemented in Solidity and one in Viper, by two programmers other than the original developer of the Viper contract. Two independently developed test suites are used in this differential testing.

It is worth noting that this contract is part of a larger project we are doing, and is structured to be self contained. If Viper contributors feel that this repository is a good place for the code, I will refactor the test scripts into the existing top-level test directory. If consensus is that this would live better in a separate repo, I won't bother putting the effort in.

- How to verify it

See the README for instructions on running tests.

- Description for the changelog

Add Solidity-compatible ERC20 example to examples database.

- Cute Animal Picture


               (
                )
               (
         /\  .-"""-.  /\
        //\\/  ,,,  \//\\
        |/\| ,;;;;;, |/\|
        //\\\;-"""-;///\\
       //  \/   .   \/  \\
      (| ,-_| \ | / |_-, |)
        //`__\.-.-./__`\\
       // /.-(() ())-.\ \\
      (\ |)   '---'   (| /)
       ` (|           |) `
 jgs     \)           (/

@pdaian
Copy link
Contributor Author

pdaian commented Sep 28, 2017

@AlexXiong97 @DavidKnott worth noting since you guys participated in the discussion in #275 that several critical issues were fixed between the last code you guys saw and this code. This includes:

  • Incorrect transferFrom behavior
  • Non-compliance with final ERC20

Also, the tests have been substantially refined and expanded. I recommend any projects or contracts that used the original Viper ERC20 as their base code make sure to upgrade to include these changes.

@pdaian
Copy link
Contributor Author

pdaian commented Sep 28, 2017

(@glambeth you too since you were part of the previous PR discussion)

@DavidKnott
Copy link
Contributor

DavidKnott commented Sep 28, 2017

@pdaian First off thank you so much for doing this! I vote for keeping these contracts here as Viper is young enough that developers need all the resources they can get and it'll be easiest for them if all examples are in one place.

On another note, logging/event functionality has recently been added to Viper and I think it'd be cleaner if it was used here. Would you mind changing raw_log to the newer syntax (see test_logging.py)?

@pdaian
Copy link
Contributor Author

pdaian commented Sep 28, 2017

@DavidKnott excellent! I was not aware of these changes and that scratches off the main Viper wishlist item for this contract :). Will release an update later tonight that uses the native logging functionality and removes the parts of the README that complain about missing ABI events, etc.

@pdaian
Copy link
Contributor Author

pdaian commented Oct 2, 2017

@DavidKnott refactored for log-based events and rebased onto master; now blocked on #373

We are hosting a major event at Cornell Thursday/Friday so I will be able to look into that issue after then if nobody has gotten to it.

@pdaian
Copy link
Contributor Author

pdaian commented Oct 2, 2017

After that is fixed, TODO blockers before merge include:

  • Refactor tests into Viper examples test folder, add to set of automated tests
  • Some stylistic issues in tests (commented code, unclosed files)

@fubuloubu
Copy link
Member

@pdaian Please rebase to master

@pdaian
Copy link
Contributor Author

pdaian commented Oct 5, 2017

@fubuloubu will do, waiting on #373 which I will also take a look at myself early next week if still open

@DavidKnott
Copy link
Contributor

@pdaian Sorry for taking so long to fix the logging issue, #377 should fix it.

@pdaian
Copy link
Contributor Author

pdaian commented Oct 10, 2017

@DavidKnott great, thanks! Going to work on getting everything ready for a merge tonight.

@fubuloubu
Copy link
Member

What's up with this versus #391?

@jacqueswww
Copy link
Contributor

jacqueswww commented Oct 11, 2017

@fubuloubu this is a one-for-one num256 contract (I am guessing the assembly will be much closer to the solidity equivalent). Basically in the #391 we use the more natural looking nums internally (which is what we want in the case of anyone implementing actual tokens in viper in the future). This example uses num256 throughout.

@fubuloubu
Copy link
Member

Oh, I get the difference now. I guess make sure it's obvious in the file structure that one is a solidity replica and the other is only compatible (with different types internally)

@pdaian
Copy link
Contributor Author

pdaian commented Oct 17, 2017

@DavidKnott refactored tests into the appropriate directory; I think everything is ready for review!

Copy link
Contributor

@DavidKnott DavidKnott 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 implementing the logs, it'd be great if you could add in the built in num256 overflow protection (making the viper example cleaner).

# Events are not yet supported in Viper, so events are NOT
# included in this token. This makes this token incompatible
# with some log-only clients.

Copy link
Contributor

Choose a reason for hiding this comment

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

Events are now supported in Viper :)

@constant
def is_overflow_sub(a : num256, b : num256) -> bool:
return num256_lt(a, b)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think is_overflow_add and is_overflow_sub are unnecessary due to pr #385

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Waiting on #411

- Examples of other common token usage patterns (owner-mintable tokens being one
possible example).
- [Wishlist] Addition of logs to Viper to remove ugly raw_log calls and
include events in the automatically generated ABI.
Copy link
Contributor

Choose a reason for hiding this comment

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

This has been done :)

@@ -0,0 +1,100 @@
# Author: Florian Tramer
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we including a Serpent token when the Serpent compiler isn't safe for production?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only there to show compatibility in theory, but I will remove since you are right it's a bit pointless to have people install the dependency.

@pdaian
Copy link
Contributor Author

pdaian commented Oct 18, 2017

Whoops, mangled the commit history a bit; will fix when I get home tonight (that's what I get for pushing from the train)

@pdaian pdaian force-pushed the sol_compat_ERC20 branch 2 times, most recently from 40c8524 to 0ba4ac4 Compare October 19, 2017 16:46
@pdaian
Copy link
Contributor Author

pdaian commented Oct 19, 2017

@DavidKnott addressed all comments

Copy link
Contributor

@DavidKnott DavidKnott left a comment

Choose a reason for hiding this comment

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

Looks great, please remove the last two references of Serpent and I'll merge it in.

- 100% branch and statement coverage (manually verified).
- Independent tests from two test authors.
- Differential testing against two example Solidity and one Serpent tokens, written independently
(available in the ``nonviper`` subfolder and annotated with comments).
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the serpent reference.

def extract_language(sourcefile):
languages = {
'.sol': 'solidity',
'.se': 'serpent',
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the serpent reference here as well.

@pdaian
Copy link
Contributor Author

pdaian commented Oct 22, 2017

Comments addressed, Serpent references removed and minor README wording changes, also rebased onto latest master.

@DavidKnott
Copy link
Contributor

LGTM!

@DavidKnott DavidKnott merged commit 753f043 into vyperlang:master Oct 22, 2017
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.

4 participants