-
Notifications
You must be signed in to change notification settings - Fork 246
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
ACL: remove ACLOracle canPerform() gas limit #565
Changes from 6 commits
c53f160
74b0c42
1785c3a
79628be
2771428
38c9e04
0606ebe
fed5fac
a3f94ef
7169d41
c72b9f9
7eae34d
18800ad
a18faf1
b11da3c
4d4279a
70b19fb
3882538
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,12 @@ contract ACL is IACL, TimeHelpers, AragonApp, ACLHelpers { | |
address public constant ANY_ENTITY = address(-1); | ||
address public constant BURN_ENTITY = address(1); // address(0) is already used as "no permission manager" | ||
|
||
uint256 internal constant ORACLE_CHECK_GAS = 30000; | ||
uint256 internal constant ERROR_GAS_ALLOWANCE = 50000; | ||
|
||
string private constant ERROR_AUTH_INIT_KERNEL = "ACL_AUTH_INIT_KERNEL"; | ||
string private constant ERROR_AUTH_NO_MANAGER = "ACL_AUTH_NO_MANAGER"; | ||
string private constant ERROR_EXISTENT_MANAGER = "ACL_EXISTENT_MANAGER"; | ||
string private constant ERROR_ORACLE_OOG = "ACL_ORACLE_OOG"; | ||
|
||
// Whether someone has a permission | ||
mapping (bytes32 => bytes32) internal permissions; // permissions hash => params hash | ||
|
@@ -421,14 +422,18 @@ contract ACL is IACL, TimeHelpers, AragonApp, ACLHelpers { | |
|
||
// a raw call is required so we can return false if the call reverts, rather than reverting | ||
bytes memory checkCalldata = abi.encodeWithSelector(sig, _who, _where, _what, _how); | ||
uint256 oracleCheckGas = ORACLE_CHECK_GAS; | ||
|
||
bool ok; | ||
assembly { | ||
ok := staticcall(oracleCheckGas, _oracleAddr, add(checkCalldata, 0x20), mload(checkCalldata), 0, 0) | ||
|
||
if (gasleft() > ERROR_GAS_ALLOWANCE) { | ||
uint256 oracleCheckGas = gasleft() - ERROR_GAS_ALLOWANCE; | ||
assembly { | ||
ok := staticcall(oracleCheckGas, _oracleAddr, add(checkCalldata, 0x20), mload(checkCalldata), 0, 0) | ||
} | ||
} | ||
|
||
if (!ok) { | ||
require(gasleft() > ERROR_GAS_ALLOWANCE, ERROR_ORACLE_OOG); | ||
sohkai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use all the available gas in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In that case we could leave the commented There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { assertRevert } = require('../../helpers/assertThrow') | ||
|
||
const ACL = artifacts.require('ACL') | ||
const Kernel = artifacts.require('Kernel') | ||
const KernelProxy = artifacts.require('KernelProxy') | ||
const OverGasLimitOracle = artifacts.require('OverGasLimitOracle') | ||
|
||
const ANY_ADDR = '0xffffffffffffffffffffffffffffffffffffffff' | ||
|
||
contract('ACL', ([permissionsRoot, mockAppAddress]) => { | ||
let aclBase, kernelBase, acl, kernel, overGasLimitOracle | ||
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()) | ||
overGasLimitOracle = await OverGasLimitOracle.new() | ||
}) | ||
|
||
context('> ACLOracle Permission', () => { | ||
|
||
it('fails when oracle canPerform goes OOG', async () => { | ||
// 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${overGasLimitOracle.address.slice(2)}` // oracle address | ||
const param = new web3.BigNumber(`${argId}${op}${value}`) | ||
|
||
await acl.createPermission(permissionsRoot, mockAppAddress, MOCK_APP_ROLE, permissionsRoot) | ||
await acl.grantPermissionP(ANY_ADDR, mockAppAddress, MOCK_APP_ROLE, [param]) | ||
|
||
await assertRevert(acl.hasPermission(ANY_ADDR, mockAppAddress, MOCK_APP_ROLE), "ACL_ORACLE_OOG") | ||
}) | ||
|
||
}) | ||
}) |
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.
As mentioned in the call, we should use
gasleft()
once and then do operations on the same cached value afterwards to avoid any potential underflows.