-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
Conversation
@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:
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. |
d3299dc
to
2e22576
Compare
(@glambeth you too since you were part of the previous PR discussion) |
@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 |
@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. |
2e22576
to
22301cd
Compare
@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. |
After that is fixed, TODO blockers before merge include:
|
@pdaian Please rebase to master |
@fubuloubu will do, waiting on #373 which I will also take a look at myself early next week if still open |
@DavidKnott great, thanks! Going to work on getting everything ready for a merge tonight. |
What's up with this versus #391? |
@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. |
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) |
22301cd
to
32a0370
Compare
@DavidKnott refactored tests into the appropriate directory; I think everything is ready for review! |
There was a problem hiding this 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. | ||
|
There was a problem hiding this comment.
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) | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Whoops, mangled the commit history a bit; will fix when I get home tonight (that's what I get for pushing from the train) |
40c8524
to
0ba4ac4
Compare
@DavidKnott addressed all comments |
There was a problem hiding this 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). |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
5065c46
to
c193d34
Compare
Comments addressed, Serpent references removed and minor README wording changes, also rebased onto latest master. |
LGTM! |
- 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