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

encodeParam and encodeParams functions #456

Open
wants to merge 53 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
37b2612
Add encodeParam to ACLHelpers
leftab Nov 5, 2018
85dda17
Move Op and Param structs from ACL to ACLHelpers
leftab Nov 6, 2018
e3b49ea
Add encoreParams and encodeParam for Param structs
leftab Nov 6, 2018
bc0e525
Add TestACLHelpers
leftab Nov 6, 2018
a97c86d
Remove encodeParam with uint params
leftab Nov 8, 2018
fee7fc1
Add AclHelpers js launch test
leftab Nov 8, 2018
ecf2f5c
Add encodeParams test
leftab Nov 8, 2018
8542235
Add brackets around for loop
leftab Nov 8, 2018
a85c5aa
Remove ACL import and inheritance
leftab Nov 8, 2018
b3ba05d
Move Op and Param to ACLParams contract
leftab Nov 20, 2018
79100ce
Add encodeOperator and encodeIfElse tests
leftab Nov 20, 2018
9b4f8f3
Compact params
leftab Nov 20, 2018
b056828
Expose ACLHelpers functions
leftab Nov 20, 2018
0aa8d3c
Fix linter issues
leftab Nov 20, 2018
e96f7c0
chore: update license text (#467)
sohkai Dec 12, 2018
1fa2b95
Merge branch 'master' into dev
sohkai Dec 13, 2018
da862e2
KernelProxy: emit SetApp event on construction (#466)
sohkai Dec 14, 2018
480b2f6
Add encodeParam to ACLHelpers
leftab Nov 5, 2018
bdeee78
Move Op and Param structs from ACL to ACLHelpers
leftab Nov 6, 2018
04c2048
Add encoreParams and encodeParam for Param structs
leftab Nov 6, 2018
2530b15
Add TestACLHelpers
leftab Nov 6, 2018
45727e3
Remove encodeParam with uint params
leftab Nov 8, 2018
97327f3
Add AclHelpers js launch test
leftab Nov 8, 2018
c44a025
Add encodeParams test
leftab Nov 8, 2018
b647866
Add brackets around for loop
leftab Nov 8, 2018
aa08e27
Remove ACL import and inheritance
leftab Nov 8, 2018
b05c010
Move Op and Param to ACLParams contract
leftab Nov 20, 2018
9c84dc3
Add encodeOperator and encodeIfElse tests
leftab Nov 20, 2018
dbce97e
Compact params
leftab Nov 20, 2018
dd2f8f2
Expose ACLHelpers functions
leftab Nov 20, 2018
22ec764
Fix linter issues
leftab Nov 20, 2018
93e5ba1
Fix spaces and array size
leftab Feb 3, 2019
ad1b7f7
Use loop for testEncodeParams
leftab Feb 3, 2019
3a8fb64
Merge branch 'dev' of https://github.com/leftab/aragonOS into dev
leftab Feb 3, 2019
c4e0fb1
chore: pin ganache-cli to 6.2.3 (#472)
sohkai Feb 7, 2019
a026e22
feat: Add SafeERC20 (#469)
sohkai Feb 11, 2019
5c61d10
tests: Coverage improvements (#474)
sohkai Feb 11, 2019
c37d4fd
4.1.0-rc.1
sohkai Feb 11, 2019
3d8c54f
chore: upgrade solium (#476)
sohkai Feb 12, 2019
9734f9c
Merge with dev
leftab Feb 13, 2019
8cf6039
Convert back ACLHelpers functions to internal
leftab Feb 13, 2019
3c909ef
Expose encodeOperator and encodeIfElse in ACLHelpers
leftab Feb 14, 2019
584f4bc
Add MIT license to ACLParams
leftab Feb 18, 2019
05d3d26
Rename ACLHelper to ACLOracleHelper
leftab Feb 18, 2019
d2268c8
VaultRecoverable: emit event on successful recovery (#480)
sohkai Feb 22, 2019
722e25e
test: remove accidentally placed .only() in tests (#483)
sohkai Feb 22, 2019
dbb0e06
feat: Add radspec strings to ENSSubdomainRegistrar
usetech-llc Mar 7, 2019
db9342f
fix: update radspec strings (#489)
sohkai Mar 7, 2019
b18c1a5
Create CONTRIBUTING.md
a33bcn Mar 7, 2019
37f8eff
chore: update readme.md
sohkai Mar 7, 2019
9ff0bda
Merge branch 'dev' into leftab-dev
sohkai Mar 7, 2019
032f577
fix: move ACLHelpers to its own file
sohkai Mar 7, 2019
7366642
feat: move ACL param IDs to ACLParams
sohkai Mar 7, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const skipFiles = [
'test',
'acl/ACLSyntaxSugar.sol',
'common/DepositableStorage.sol', // Used in tests that send ETH
'common/SafeERC20.sol', // solidity-coverage fails on assembly if (https://github.com/sc-forks/solidity-coverage/issues/287)
'common/UnstructuredStorage.sol' // Used in tests that send ETH
]

Expand Down
72 changes: 72 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Contributing to aragonOS

:tada: Thank you for being interested in contributing to aragonOS! :tada:

Feel welcome and read the following sections in order to know how to ask questions and how to work on something.

There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or writing code which can be incorporated into the project.

All members of our community are expected to follow our [Code of Conduct](https://wiki.aragon.org/documentation/Code_of_Conduct/). Please make sure you are welcoming and friendly in all of our spaces.

## Your first contribution

Unsure where to begin contributing to aragonOS?

You can start with a [Good First Issue](https://github.com/aragon/aragonOS/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)

> Good first issues are usually for small features, additional tests, spelling / grammar fixes, formatting changes, or other clean up.

Start small, pick a subject you care about, are familiar with, or want to learn.

If you're not already familiar with git or Github, here are a couple of friendly tutorials: [First Contributions](https://github.com/firstcontributions/first-contributions), [Open Source Guide](https://opensource.guide/), and [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).

## How to file an issue or report a bug

If you see a problem, you can report it in our [issue tracker](https://github.com/aragon/aragonOS/issues).

Please take a quick look to see if the issue doesn't already exist before filing yours.

Do your best to include as many details as needed in order for someone else to fix the problem and resolve the issue.

#### If you find a security vulnerability, do NOT open an issue. Email security@aragon.org instead.

In order to determine whether you are dealing with a security issue, ask yourself these two questions:

- Can I access or steal something that's not mine, or access something I shouldn't have access to?
- Can I disable something for other people?

If the answer to either of those two questions are "yes", then you're probably dealing with a security issue. Note that even if you answer "no" to both questions, you may still be dealing with a security issue, so if you're unsure, please send a email.

#### A [bug bounty program](https://wiki.aragon.org/dev/bug_bounty/) is available for rewarding contributors who find security vulnerabilities with payouts up to $50,000.

## Fixing issues

1. [Find an issue](https://github.com/aragon/aragonOS/issues) that you are interested in.
- You may want to ask on the issue or on Aragon Chat's [#dev channel](https://aragon.chat/channel/dev) if anyone has already started working on the issue.
1. Fork and clone a local copy of the repository.
1. Make the appropriate changes for the issue you are trying to address or the feature that you want to add.
- Make sure to add tests!
1. Push the changes to the remote repository.
1. Submit a pull request in Github, explaining any changes and further questions you may have.
1. Wait for the pull request to be reviewed.
1. Make changes to the pull request if the maintainer recommends them.
1. Celebrate your success after your pull request is merged!

It's OK if your pull request is not perfect (no pull request is).
The reviewer will be able to help you fix any problems and improve it!

You can also edit a page directly through your browser by clicking the "EDIT" link in the top-right corner of any page and then clicking the pencil icon in the github copy of the page.

## Styleguide and development processes

We generally follow [Solidity's style guide](https://solidity.readthedocs.io/en/v0.4.24/style-guide.html) and have set up [Ethlint](https://github.com/duaraghav8/Ethlint) to automatically lint the project.

Due to the sensitive nature of Solidity, usually at least two reviewers are required before merging any pull request with code changes.

### Licensing

aragonOS is generally meant to be used as a library by developers but includes core components that are not generally useful to extend. Any interfaces or contracts meant to be used by other developers are licensed as MIT and have their Solidity pragmas left unpinned. All other contracts are licensed as GPL-3 and are pinned to a specific Solidity version.

## Community

If you need help, please reach out to Aragon core contributors and community members in the Aragon Chat [#dev](https://aragon.chat/channel/dev) [#dev-help](https://aragon.chat/channel/dev-help) channels. We'd love to hear from you and know what you're working on!
23 changes: 3 additions & 20 deletions contracts/acl/ACL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,20 @@ pragma solidity 0.4.24;

import "../apps/AragonApp.sol";
import "../common/TimeHelpers.sol";
import "./ACLSyntaxSugar.sol";
import "./ACLHelpers.sol";
import "./ACLParams.sol";
import "./IACL.sol";
import "./IACLOracle.sol";


/* solium-disable function-order */
// Allow public initialize() to be first
contract ACL is IACL, TimeHelpers, AragonApp, ACLHelpers {
contract ACL is IACL, TimeHelpers, AragonApp, ACLParams, ACLHelpers {
/* Hardcoded constants to save gas
bytes32 public constant CREATE_PERMISSIONS_ROLE = keccak256("CREATE_PERMISSIONS_ROLE");
*/
bytes32 public constant CREATE_PERMISSIONS_ROLE = 0x0b719b33c83b8e5d300c521cb8b54ae9bd933996a14bef8c2f4e0285d2d2400a;

enum Op { NONE, EQ, NEQ, GT, LT, GTE, LTE, RET, NOT, AND, OR, XOR, IF_ELSE } // op types

struct Param {
uint8 id;
uint8 op;
uint240 value; // even though value is an uint240 it can store addresses
// in the case of 32 byte hashes losing 2 bytes precision isn't a huge deal
// op and id take less than 1 byte each so it can be kept in 1 sstore
}

uint8 internal constant BLOCK_NUMBER_PARAM_ID = 200;
uint8 internal constant TIMESTAMP_PARAM_ID = 201;
// 202 is unused
uint8 internal constant ORACLE_PARAM_ID = 203;
uint8 internal constant LOGIC_OP_PARAM_ID = 204;
uint8 internal constant PARAM_VALUE_PARAM_ID = 205;
// TODO: Add execution times param type?

/* Hardcoded constant to save gas
bytes32 public constant EMPTY_PARAM_HASH = keccak256(uint256(0));
*/
Expand Down
46 changes: 46 additions & 0 deletions contracts/acl/ACLHelpers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* SPDX-License-Identitifer: MIT
*/

pragma solidity ^0.4.24;

import "./ACLParams.sol";


contract ACLHelpers is ACLParams {
function decodeParamOp(uint256 _x) internal pure returns (uint8 b) {
return uint8(_x >> (8 * 30));
}

function decodeParamId(uint256 _x) internal pure returns (uint8 b) {
return uint8(_x >> (8 * 31));
}

function decodeParamsList(uint256 _x) internal pure returns (uint32 a, uint32 b, uint32 c) {
a = uint32(_x);
b = uint32(_x >> (8 * 4));
c = uint32(_x >> (8 * 8));
}

function encodeParams(Param[] params) internal pure returns (uint256[]) {
uint256[] memory encodedParams = new uint256[](params.length);

for (uint i = 0; i < params.length; i++) {
encodedParams[i] = encodeParam(params[i]);
}

return encodedParams;
}

function encodeParam(Param param) internal pure returns (uint256) {
return uint256(param.id) << 248 | uint256(param.op) << 240 | param.value;
}

function encodeOperator(uint256 param1, uint256 param2) internal pure returns (uint240) {
return uint240(param1 + (param2 << 32) + (0 << 64));
}

function encodeIfElse(uint256 condition, uint256 successParam, uint256 failureParam) internal pure returns (uint240) {
return uint240(condition + (successParam << 32) + (failureParam << 64));
}
}
28 changes: 28 additions & 0 deletions contracts/acl/ACLParams.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identitifer: MIT
*/

pragma solidity ^0.4.24;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Done! ;) Is there a rule of thumb on which file an MIT header should be added?

Copy link
Contributor

Choose a reason for hiding this comment

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

I need to write more documentation on this, but on all the unpinned contracts (since they're the only ones meant to be used by apps, which frees them up to use any licensing model they want).



contract ACLParams {
// Op types
enum Op { NONE, EQ, NEQ, GT, LT, GTE, LTE, RET, NOT, AND, OR, XOR, IF_ELSE }

// Op IDs
uint8 internal constant BLOCK_NUMBER_PARAM_ID = 200;
uint8 internal constant TIMESTAMP_PARAM_ID = 201;
// 202 is unused
uint8 internal constant ORACLE_PARAM_ID = 203;
uint8 internal constant LOGIC_OP_PARAM_ID = 204;
uint8 internal constant PARAM_VALUE_PARAM_ID = 205;
// TODO: Add execution times param type?

struct Param {
uint8 id;
uint8 op;
uint240 value; // even though value is an uint240 it can store addresses
// in the case of 32 byte hashes losing 2 bytes precision isn't a huge deal
// op and id take less than 1 byte each so it can be kept in 1 sstore
}
}
21 changes: 3 additions & 18 deletions contracts/acl/ACLSyntaxSugar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ pragma solidity ^0.4.24;


contract ACLSyntaxSugar {
function arr() internal pure returns (uint256[]) {}
function arr() internal pure returns (uint256[]) {
// solium-disable-previous-line no-empty-blocks
}

function arr(bytes32 _a) internal pure returns (uint256[] r) {
return arr(uint256(_a));
Expand Down Expand Up @@ -83,20 +85,3 @@ contract ACLSyntaxSugar {
r[4] = _e;
}
}


contract ACLHelpers {
function decodeParamOp(uint256 _x) internal pure returns (uint8 b) {
return uint8(_x >> (8 * 30));
}

function decodeParamId(uint256 _x) internal pure returns (uint8 b) {
return uint8(_x >> (8 * 31));
}

function decodeParamsList(uint256 _x) internal pure returns (uint32 a, uint32 b, uint32 c) {
a = uint32(_x);
b = uint32(_x >> (8 * 4));
c = uint32(_x >> (8 * 8));
}
}
2 changes: 2 additions & 0 deletions contracts/apm/APMRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ contract APMRegistry is AragonApp, AppProxyFactory, APMInternalAppNames {

/**
* NEEDS CREATE_NAME_ROLE and POINT_ROOTNODE_ROLE permissions on registrar
* @dev Initialize can only be called once. It saves the block number in which it was initialized
* @notice Initialize this APMRegistry instance and set `_registrar` as the ENS subdomain registrar
* @param _registrar ENSSubdomainRegistrar instance that holds registry root node ownership
*/
function initialize(ENSSubdomainRegistrar _registrar) public onlyInit {
Expand Down
2 changes: 1 addition & 1 deletion contracts/apm/Repo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract Repo is AragonApp {

/**
* @dev Initialize can only be called once. It saves the block number in which it was initialized.
* @notice Initializes a Repo to be usable
* @notice Initialize this Repo
*/
function initialize() public onlyInit {
initialized();
Expand Down
2 changes: 1 addition & 1 deletion contracts/apps/AppProxyUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract AppProxyUpgradeable is AppProxyBase {
AppProxyBase(_kernel, _appId, _initializePayload)
public // solium-disable-line visibility-first
{

// solium-disable-previous-line no-empty-blocks
}

/**
Expand Down
2 changes: 2 additions & 0 deletions contracts/common/IVaultRecoverable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pragma solidity ^0.4.24;


interface IVaultRecoverable {
event RecoverToVault(address indexed vault, address indexed token, uint256 amount);

function transferToVault(address token) external;

function allowRecoverability(address token) external view returns (bool);
Expand Down
Loading