-
Notifications
You must be signed in to change notification settings - Fork 245
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
base: next
Are you sure you want to change the base?
Conversation
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.
Looking really good! Just thinking we could expose this as its own contract separate from ACLSyntaxSugar
.
contracts/acl/ACLSyntaxSugar.sol
Outdated
@@ -86,6 +86,31 @@ contract ACLSyntaxSugar { | |||
|
|||
|
|||
contract ACLHelpers { | |||
|
|||
enum Op { NONE, EQ, NEQ, GT, LT, GTE, LTE, RET, NOT, AND, OR, XOR, IF_ELSE } // op types |
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.
What do you think about putting this in another contract, e.g. ACLParams
?
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.
Good idea! I agree they fit more inside ACLParams
contracts/acl/ACLSyntaxSugar.sol
Outdated
|
||
function encodeParam(Param param) internal pure returns (uint256) { | ||
return uint256(param.id) << 248 | uint256(param.op) << 240 | param.value; | ||
} |
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.
We could also expose the helpers in ACLHelpers
.
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 exposed all the functions except those having struct
params since they would require the experimental ABI encoder.
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"); | ||
} | ||
|
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.
Let's test encodeOperator
and encodeIfElse
as well :)
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.
Done :)
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 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?
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.
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.
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.
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()
).
Thanks for the review @sohkai ! I applied the changes but somehow the Travis tests seems to fail now. I'm a bit perplexed since everything looks fine when I run the tests locally. |
Allows a frontend to follow all `SetApp()` events emitted from the start of a KernelProxy's lifespan.
@leftab Sorry for the hiatus on this—will get back to looking at this shortly :). I think the CI broken when there was a ganache bug with account values or gas used; if you merge with master it should be fixed now :). |
contracts/acl/ACLSyntaxSugar.sol
Outdated
contract ACLHelpers { | ||
function decodeParamOp(uint256 _x) internal pure returns (uint8 b) { | ||
contract ACLHelpers is ACLParams { | ||
|
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 adding 2 newlines here? Not a big deal, but we don't usually do that.
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.
Oh I didn't know that, sorry. It's fixed.
contracts/acl/ACLSyntaxSugar.sol
Outdated
contract ACLHelpers is ACLParams { | ||
|
||
|
||
function decodeParamOp(uint256 _x) public pure returns (uint8 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.
Why are we converting these 3 functions from internal
to public
?
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.
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
?
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.
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.
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.
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.
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.
What do you think if I move the ACLHelpers
contract into its own ACLHelpers.sol
file? It would be a breaking change however.
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.
Let's mark it as something we should do in the future 👍 .
contracts/test/TestACLHelpers.sol
Outdated
} | ||
|
||
function testEncodeParams() public { | ||
Param[] memory params = new Param[](6); |
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 6? Only 4 are being used, right? (not a big deal)
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.
True! :)
contracts/test/TestACLHelpers.sol
Outdated
|
||
uint256[] memory encodedParam = encodeParams(params); | ||
|
||
(uint32 id0, uint32 op0, uint32 value0) = decodeParamsList(encodedParam[0]); |
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.
Maybe we could use a loop here.
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.
Totally!
* APMRegistry: fix tests checking APMRegistry doesn't init without required permissions * EVMScriptRegistry: add more tests for coverage * ENSSubdomainRegistrary: fix initialization test
As for the gas usage sanity check, since the new functions are not used in aragonOS and are |
@leftab Will check the compiled bytecode of the |
} | ||
} | ||
|
||
|
||
contract AcceptOracle is IACLOracle { |
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.
Could we rename this file, since it only contains test ACLOracle
s now?
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.
Renamed it to ACLOracleHelper
@@ -0,0 +1,15 @@ | |||
pragma solidity ^0.4.24; |
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.
Could we add the MIT header here (e.g. see https://github.com/aragon/aragonOS/blob/dev/contracts/acl/IACL.sol#L1)?
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.
Done! ;) Is there a rule of thumb on which file an MIT header should be added?
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 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).
@leftab I've pushed a commit to split Unfortunately though, it looks like the changes do cause a bytecode difference against the old contracts :(. Going between this PR and Will have to investigate further to see what's exactly causing this, but it does mean it's a bigger change than expected. As far as I can tell it happens immediately as the struct and enum are moved out, which is quite odd behaviour for the compiler. |
@leftab Because this wasn't pulled into some of the minor aragonOS 4.x releases, due to the incompatible bytecode (and because we didn't want to risk re-deploying the ACL for 0.7), we'll roll this into aragonOS 5 :). |
|
Fixes #427
Adds the following functions:
encodeParam(Param param) internal pure returns (uint256)
encodeParams(Param[] params) internal pure returns (uint256[])
I didn't add the
encodeParam(uint8 id, uint8 op, uint240 value)
function since I thinkencodeParam(Param param)
covers pretty much the same use cases and is easier to use.TODO: