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 14 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
10 changes: 0 additions & 10 deletions contracts/acl/ACL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ contract ACL is IACL, TimeHelpers, AragonApp, ACLHelpers {
*/
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
Expand Down
15 changes: 15 additions & 0 deletions contracts/acl/ACLParams.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 {

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
}
}
26 changes: 22 additions & 4 deletions contracts/acl/ACLSyntaxSugar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

pragma solidity ^0.4.24;

import "./ACLParams.sol";


contract ACLSyntaxSugar {
function arr() internal pure returns (uint256[]) {}
Expand Down Expand Up @@ -85,18 +87,34 @@ contract ACLSyntaxSugar {
}


contract ACLHelpers {
function decodeParamOp(uint256 _x) internal pure returns (uint8 b) {
contract ACLHelpers is ACLParams {

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 adding 2 newlines here? Not a big deal, but we don't usually do that.

Copy link
Author

Choose a reason for hiding this comment

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

Oh I didn't know that, sorry. It's fixed.


function decodeParamOp(uint256 _x) public pure returns (uint8 b) {
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 converting these 3 functions from internal to public?

Copy link
Author

Choose a reason for hiding this comment

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

So it can be used by composition instead of only by inheritance. Do you think it would impact gaz usage and we should keep them internal?

Copy link
Contributor

Choose a reason for hiding this comment

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

Most likely wouldn't impact gas by very much (more or less only on deployment), but wondering how useful this would be. Do you think outside contracts might want access to this functionality, which is only accessible on the ACL?

We should also make sure encodeParams() and encodeParam() are the same visibility as their decode counterparts.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry for the delay. hmm.. it’s been so long that I don’t even remember haha! I guess I wanted the encodeParam and encodeParams functions public, but it’s not supported yet anyway. I converted them back to internal and exposed the encodeOperator and encodeIfElse functions. The two functions are used in the ACL Interpreter tests and I made encodeOperator a little bit more explicit.

Copy link
Author

Choose a reason for hiding this comment

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

What do you think if I move the ACLHelpers contract into its own ACLHelpers.sol file? It would be a breaking change however.

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 mark it as something we should do in the future 👍 .

return uint8(_x >> (8 * 30));
}

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

function decodeParamsList(uint256 _x) internal pure returns (uint32 a, uint32 b, uint32 c) {
function decodeParamsList(uint256 _x) public 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;
}
}
60 changes: 60 additions & 0 deletions contracts/test/TestACLHelpers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
pragma solidity 0.4.24;

import "./helpers/Assert.sol";
import "./helpers/ACLHelper.sol";
import "../acl/ACLSyntaxSugar.sol";
import "../acl/ACL.sol";


contract TestACLHelpers is ACL, ACLHelper {

function testEncodeParam() public {
Param memory param = Param(2, uint8(Op.EQ), 5294967297);

uint256 encodedParam = encodeParam(param);

(uint32 id, uint32 op, uint32 value) = decodeParamsList(encodedParam);

Assert.equal(uint256(param.id), uint256(id), "Encoded id is not equal");
Assert.equal(uint256(param.op), uint256(op), "Encoded op is not equal");
Assert.equal(uint256(param.value), uint256(value), "Encoded value is not equal");
}

function testEncodeParams() public {
Param[] memory params = new Param[](6);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 6? Only 4 are being used, right? (not a big deal)

Copy link
Author

Choose a reason for hiding this comment

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

True! :)


params[0] = Param(LOGIC_OP_PARAM_ID, uint8(Op.IF_ELSE), encodeIfElse(1, 2, 3));
params[1] = Param(LOGIC_OP_PARAM_ID, uint8(Op.AND), encodeOperator(2, 3));
params[2] = Param(2, uint8(Op.EQ), 1);
params[3] = Param(3, uint8(Op.NEQ), 2);


uint256[] memory encodedParam = encodeParams(params);

(uint32 id0, uint32 op0, uint32 value0) = decodeParamsList(encodedParam[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could use a loop here.

Copy link
Author

Choose a reason for hiding this comment

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

Totally!


Assert.equal(uint256(params[0].id), uint256(id0), "Encoded id is not equal");
Assert.equal(uint256(params[0].op), uint256(op0), "Encoded op is not equal");
Assert.equal(uint256(params[0].value), uint256(value0), "Encoded value is not equal");

(uint32 id1, uint32 op1, uint32 value1) = decodeParamsList(encodedParam[1]);

Assert.equal(uint256(params[1].id), uint256(id1), "Encoded id is not equal");
Assert.equal(uint256(params[1].op), uint256(op1), "Encoded op is not equal");
Assert.equal(uint256(params[1].value), uint256(value1), "Encoded value is not equal");

(uint32 id2, uint32 op2, uint32 value2) = decodeParamsList(encodedParam[2]);

Assert.equal(uint256(params[2].id), uint256(id2), "Encoded id is not equal");
Assert.equal(uint256(params[2].op), uint256(op2), "Encoded op is not equal");
Assert.equal(uint256(params[2].value), uint256(value2), "Encoded value is not equal");

(uint32 id3, uint32 op3, uint32 value3) = decodeParamsList(encodedParam[3]);

Assert.equal(uint256(params[3].id), uint256(id3), "Encoded id is not equal");
Assert.equal(uint256(params[3].op), uint256(op3), "Encoded op is not equal");
Assert.equal(uint256(params[3].value), uint256(value3), "Encoded value is not equal");

}

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 test encodeOperator and encodeIfElse as well :)

Copy link
Author

Choose a reason for hiding this comment

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

Done :)

Copy link
Author

Choose a reason for hiding this comment

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

I noticed that the encodeOperator and encodeIfElse functions are in a separate file in the test folder. Do you think it would be a good idea if I move them to the ACLHelpers contract?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think it's a good idea, but let's wait for @sohkai opinion, maybe there is a reason I don't know for them to be there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I didn't notice they were only in the tests.

I think moving them could be helpful; AFAIK they're not simply because we only used them in test functionality. We should either add comments to explain how they work or make encodeOperator() more explicit (it's a bit confusing at first why it builds off of encodeIfElse()).

}
3 changes: 3 additions & 0 deletions test/acl_helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const runSolidityTest = require('./helpers/runSolidityTest')

runSolidityTest('TestACLHelpers')