-
Notifications
You must be signed in to change notification settings - Fork 241
ACL: remove ACLOracle canPerform() gas limit #565
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c53f160
Remove ACLOracle canPerform() call gas limit. Add test to check ACL c…
willjgriff 74b0c42
Added SafeMath to prevent underflow. Added comment regarding oog iter…
willjgriff 1785c3a
Reduced Error Allowance. Simplified OverGasLimitOracle.
willjgriff 79628be
Revert when detected ACL CheckOracle `staticcall` is OOG.
willjgriff 2771428
Remove SafeMath from ACL. Remove Solidity test for ACL Oracle. Add JS…
willjgriff 38c9e04
Formatting changes.
willjgriff 0606ebe
Added memoryVar setting to OverGasLimitOracle. Stored current gasleft…
willjgriff fed5fac
Moved ACL param creation test util function to a separate file. Updat…
willjgriff a3f94ef
Add JS test for successful ACL oracle.
willjgriff 7169d41
Merge branch 'next' into acl-remove-oracle-limit
sohkai c72b9f9
test: cosmetic updates, more exhaustive oracle test cases
sohkai 7eae34d
ACL: send all gas to oracle
sohkai 18800ad
ACL: add comments for forwarding all gas to oracle
sohkai a18faf1
Added alternative gas amount tests for failing OOG oracle. Disabled b…
willjgriff b11da3c
test: use skipCoverage() in ACLOracle test
sohkai 4d4279a
Added gas checks to ACL params tests. Replaced for loop with `revert`…
willjgriff 70b19fb
test: update ACLOracle tests, fix skipping coverage of entire suite
sohkai 3882538
test: add more comments to ACL oracle gas tests
sohkai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| const { assertRevert } = require('../../helpers/assertThrow') | ||
| const { paramForOracle } = require('../../helpers/permissionParams') | ||
|
|
||
| const ACL = artifacts.require('ACL') | ||
| const Kernel = artifacts.require('Kernel') | ||
| const KernelProxy = artifacts.require('KernelProxy') | ||
| const AcceptOracle = artifacts.require('AcceptOracle') | ||
| const OverGasLimitOracle = artifacts.require('OverGasLimitOracle') | ||
| const StateModifyingOracle = artifacts.require('StateModifyingOracle') | ||
|
|
||
| const ANY_ADDR = '0xffffffffffffffffffffffffffffffffffffffff' | ||
|
|
||
| contract('ACL', ([permissionsRoot, mockAppAddress]) => { | ||
| let aclBase, kernelBase, acl, kernel | ||
| const MOCK_APP_ROLE = "0xAB" | ||
|
|
||
| before(async () => { | ||
| kernelBase = await Kernel.new(true) // petrify immediately | ||
| aclBase = await ACL.new() | ||
| }) | ||
|
|
||
| beforeEach(async () => { | ||
| kernel = Kernel.at((await KernelProxy.new(kernelBase.address)).address) | ||
| await kernel.initialize(aclBase.address, permissionsRoot) | ||
| acl = ACL.at(await kernel.acl()) | ||
| await acl.createPermission(permissionsRoot, mockAppAddress, MOCK_APP_ROLE, permissionsRoot) | ||
| }) | ||
|
|
||
| it('ACLOracle succeeds when oracle canPerform returns true', async () => { | ||
| const acceptOracle = await AcceptOracle.new() | ||
| const param = paramForOracle(acceptOracle.address) | ||
| await acl.grantPermissionP(ANY_ADDR, mockAppAddress, MOCK_APP_ROLE, [param]) | ||
| assert.isTrue(await acl.hasPermission(ANY_ADDR, mockAppAddress, MOCK_APP_ROLE)) | ||
| }) | ||
|
|
||
| it('ACLOracle fails when oracle canPerform modifies state', async () => { | ||
| const stateModifyingOracle = await StateModifyingOracle.new() | ||
| const param = paramForOracle(stateModifyingOracle.address) | ||
| await acl.grantPermissionP(ANY_ADDR, mockAppAddress, MOCK_APP_ROLE, [param]) | ||
| await assertRevert(acl.hasPermission(ANY_ADDR, mockAppAddress, MOCK_APP_ROLE), "ACL_ORACLE_OOG") | ||
| }) | ||
|
|
||
| context('> ACLOracle OverGasLimitOracle', () => { | ||
| let overGasLimitOracle, param | ||
|
|
||
| beforeEach(async () => { | ||
| overGasLimitOracle = await OverGasLimitOracle.new() | ||
| param = paramForOracle(overGasLimitOracle.address) | ||
| }) | ||
|
|
||
| // Note `evalParams()` is called twice when calling `hasPermission` for `ANY_ADDR` | ||
| it('fails when oracle canPerform goes OOG', async () => { | ||
| await acl.grantPermissionP(ANY_ADDR, mockAppAddress, MOCK_APP_ROLE, [param]) | ||
| await assertRevert(acl.hasPermission(ANY_ADDR, mockAppAddress, MOCK_APP_ROLE), "ACL_ORACLE_OOG") | ||
| }) | ||
|
|
||
| // Note `evalParams()` is only called once when calling `hasPermission` for a specific address | ||
| it('fails when oracle canPerform goes OOG with specified permission owner', async () => { | ||
| await acl.grantPermissionP(permissionsRoot, mockAppAddress, MOCK_APP_ROLE, [param]) | ||
| await assertRevert(acl.hasPermission(permissionsRoot, mockAppAddress, MOCK_APP_ROLE), "ACL_ORACLE_OOG") | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
|
|
||
| const paramForOracle = (oracleAddress) => { | ||
| // Set role such that the Oracle canPerform() function is used to determine the permission | ||
| const argId = '0xCB' // arg 203 - Oracle ID | ||
| const op = '01' // equal | ||
| const value = `00000000000000000000${oracleAddress.slice(2)}` | ||
| return new web3.BigNumber(`${argId}${op}${value}`) | ||
| } | ||
|
|
||
| module.exports = { | ||
| paramForOracle | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 would refactor all this as:
And we can get rid of the
maxfunction below. I haven't checked, but as Solidity doesn't have inline functions we may save some gas this way. Also, I think if we split the require in 2 (instead oh using&&inside) it's slightly cheaper.Uh oh!
There was an error while loading. Please reload this page.
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.
If we use all the available gas in the
staticcallis there a chance there won't be enough left over for returning the error (even with the 1/64th rule)? After testing I can't find agaslimit where that's the case (eg just arevertwithout the error message) but it wasn't exhaustive. Also, due to astack too deeperror I can't add any more variables eggasLeftAfterCallunless I remove something egoracleCanPerformGas. So I can do this if you think the secondrequirestatement can always be reached. Eg the answer to my question is no.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.
In that case we could leave the commented
require(gasLeftBeforeCall > ...check, with the proper amount to make sure that 1/64 of that amount is enough.Anyway, even if that happen, what would be the problem? It would just revert, right? So compared to what would happen later in
require(gasLeftAfterCall >...we would just miss the error message? Or am I missing something?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 we would just miss the error message. @sohkai do you have a preference?
I would like to remove the
max()function but I can't unless I remove theoracleCanPerformGasvariable (or some unrelated variable somewhere) which would mean passing all of the gas to the function.