Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Token and vouching mechanics #115

Merged
merged 26 commits into from
Sep 27, 2018
Merged

Token and vouching mechanics #115

merged 26 commits into from
Sep 27, 2018

Conversation

fiiiu
Copy link
Contributor

@fiiiu fiiiu commented Sep 21, 2018

This PR adds a new package implementing the ZEP token and the Vouching mechanics, closing #101 and #108.

Pending Work:

We are opening this as is so as to get a first round of review on the vouching mechanics, which are independent of the above.

Notes:

  • Right now, an attacker can register a new dependency with a fresh name, but with an address already listed in the system. This does not open any obvious vulnerability, but might cause confusion with respect to who the owner of a dependency is. Ultimately, this stems from the fact that the indexing is done with dependency names instead of their addresses.

(Opening on master since that's where we started from.. Cannot automatically merge on next :-/ )

Copy link
Contributor

@spalladino spalladino left a comment

Choose a reason for hiding this comment

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

Awesome work! I added a few minor comments (mostly cleanup), and a few questions we may want to consider, mainly whether we want to accept vouching from non-owner addresses (for simplicity, in case the dev is not the one holding the tokens).

@@ -0,0 +1 @@
*.sol linguist-language=Solidity
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move this to the root of the repo?

@@ -0,0 +1,23 @@
pragma solidity ^0.4.23;

contract Migrations {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove this contract altogether



import "./ZepToken.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok for now, but keep in mind that we'll need to use oz-zos and not oz-sol when tackling #116

contract Vouching {
using SafeMath for uint256;

struct Dependency {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a fan of the name. Dependency makes sense in a context where it is a dependency of something else. I'd prefer PackageEntry or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also don't like Dependency, but PackageEntry is somewhat confusing.. I don't have a better proposal though, any other ideas? Entry on its own is too dry?

Copy link
Contributor

Choose a reason for hiding this comment

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

I find Entry a bit generic.
We're kinda indexing packages by their name in the registry mapping, so how about PackageIndexEntry ?

Copy link
Contributor

Choose a reason for hiding this comment

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

How about Vouchable? And I'd change dependencyAddress to packageAddress.


mapping (string => Dependency) private _registry;
uint256 private _minimumStake;
ZepToken private _token;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use a generic ERC20 here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do, but may I ask why though? It's not like we will use Vouching with other tokens..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In particular, we might need to call other specific ZEP methods when doing the TPL integration..

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed offline, we'll move to use a generic ERC20 here to keep things decoupled.

},
"keywords": [],
"author": "",
"license": "ISC",
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't we using MIT so far in the other packages?

@@ -0,0 +1,24 @@
{
"name": "zos-vouching",
"version": "1.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's follow the same version as the other packages.

event DependencyRemoved(string name);

constructor(uint256 minimumStake, ZepToken token) public {
require(token != address(0));
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if they are not yet supported by truffle, let's add revert reasons to all requires.

packages/vouching/contracts/Vouching.sol Show resolved Hide resolved
packages/vouching/test/Vouching.test.js Show resolved Hide resolved
@tinchoabbate
Copy link
Contributor

Already pushed some updates. Now waiting for the opened discussions to be settled to make the final changes.

Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

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

Awesome work guys! 😄 👏

string public constant symbol = "ZEP";
uint8 public constant decimals = 18;

uint256 public constant TOTAL_SUPPLY = 100000000 * (10 ** uint256(decimals));
Copy link
Contributor

Choose a reason for hiding this comment

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

we can use 1e8 instead of 100000000 to be clearer

module.exports = {
inLogs,
inTransaction,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

nice! we can move this ones to lib

packages/vouching/test/helpers/assertRevert.js Outdated Show resolved Hide resolved
packages/vouching/test/ZepToken.test.js Show resolved Hide resolved
require(initialStake >= _minimumStake, "Initial stake must be equal or greater than minimum stake");
require(owner != address(0), "Owner address cannot be zero");
require(dependencyAddress != address(0), "Dependency address cannot be zero");
// name should not be already registered
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment is redundant considering the error message

event DependencyCreated(string name, address indexed owner, address indexed dependencyAddress, uint256 initialStake);
event Vouched(string name, uint256 amount);
event Unvouched(string name, uint256 amount);
event DependencyRemoved(string name);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if indexing strings is still being not simple, here is some research I did for the previous release (see zeppelinos/zos-lib#199)

packages/vouching/contracts/Vouching.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

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

Looking good! Left some comments, we do need to fix some issues on the vouching contract related to the ERC20 standard before merging, sorry that I didn't see that before 🙏

ERC20 private _token;

modifier onlyDependencyOwner(string name) {
require(msg.sender == _registry[name].owner, "Not allowed");
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use a more descriptive error message here, sth like "Sender must be the dependency owner"


function remove(string name) external onlyDependencyOwner(name) {
// Owner surrenders _minimumStake to the system
_token.transfer(msg.sender, _registry[name].stake.sub(_minimumStake));
Copy link
Contributor

Choose a reason for hiding this comment

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

same here... remember that all the methods of the ERC20 interface are supposed to return a boolean value in order to tell whether the call was successful or not

require(dependencyAddress != address(0), "Dependency address cannot be zero");
require(_registry[name].dependencyAddress == address(0), "The name has already been registered");

_token.transferFrom(owner, this, initialStake);
Copy link
Contributor

Choose a reason for hiding this comment

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

This transfer should be wrapped within a require statement

Copy link
Contributor

Choose a reason for hiding this comment

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

I tackled all instances of this issue using SafeERC20 methods.

require(initialStake >= _minimumStake, "Initial stake must be equal or greater than minimum stake");
require(owner != address(0), "Owner address cannot be zero");
require(dependencyAddress != address(0), "Dependency address cannot be zero");
require(_registry[name].dependencyAddress == address(0), "The name has already been registered");
Copy link
Contributor

Choose a reason for hiding this comment

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

What about "Given dependency name was already registererd"?

}

function vouch(string name, uint256 amount) external onlyDependencyOwner(name) {
_token.transferFrom(msg.sender, this, amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

require(remainingStake >= _minimumStake, "Remaining stake must be equal or greater than minimum stake");

_registry[name].stake = remainingStake;
_token.transfer(msg.sender, amount);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

"devDependencies": {
"chai": "^4.1.2",
"chai-bignumber": "^2.0.2",
"ganache-cli": "6.1.0",
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 we are not using this one right?

packages/vouching/test/helpers/assertRevert.js Outdated Show resolved Hide resolved
packages/vouching/test/helpers/expectEvent.js Show resolved Hide resolved
* Make Vouching upgradeable

* Updated Vouching tests

* Updated package dependencies to include zos-lib and openzeppelin-zos

* Fix CI

* Replace let with const in Vouching test
@tinchoabbate
Copy link
Contributor

tinchoabbate commented Sep 25, 2018

I'm coming up with a possible implementation for indexing dependency names. Still testing locally. When it's ready, I'll branch out from vouching and then create a PR to merge again.

EDIT: already opened PR (#133)

@@ -55,9 +57,9 @@ contract Vouching is Initializable {
require(initialStake >= _minimumStake, "Initial stake must be equal or greater than minimum stake");
require(owner != address(0), "Owner address cannot be zero");
require(dependencyAddress != address(0), "Dependency address cannot be zero");
require(_registry[name].dependencyAddress == address(0), "The name has already been registered");
require(_registry[name].dependencyAddress == address(0), "Given dependency name was already registererd");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NIT: reads strangely, I propose "The provided name is already registered".

Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

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

Left some other comments. I think we can merge it after fixing those and keep working the pending issues against master, otherwise this PR will grow a lot

packages/vouching/contracts/Vouching.sol Show resolved Hide resolved
packages/vouching/contracts/Vouching.sol Show resolved Hide resolved
packages/vouching/contracts/Vouching.sol Show resolved Hide resolved
packages/vouching/contracts/Vouching.sol Show resolved Hide resolved
* @dev Constructor that gives msg.sender all of existing tokens, and sets it as the owner
*/
constructor() public {
owner = msg.sender;
Copy link
Contributor

Choose a reason for hiding this comment

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

you shouldn't do this manually since the Ownable constructor is taking care of it


module.exports = {
assertRevert,
};
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 this one since you're already using the one in zos-lib

@tinchoabbate
Copy link
Contributor

Already fixed latest issues, should be ready now.

contract Vouching {
using SafeMath for uint256;

struct Dependency {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about Vouchable? And I'd change dependencyAddress to packageAddress.

@spalladino
Copy link
Contributor

@facuspagnuolo do you want to update your review, as it is blocking the merge?

Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

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

LGTM!

@spalladino spalladino merged commit c068387 into master Sep 27, 2018
@spalladino spalladino deleted the vouching branch October 25, 2018 09:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants