add a pluginInstanceWhitelist to register proxied plugins

This commit is contained in:
perissology 2018-02-24 07:36:09 -08:00
parent ab0f8aa62f
commit 0f5c9738ed
7 changed files with 5855 additions and 32 deletions

View File

@ -34,6 +34,9 @@ contract LPFactory is DAOFactory {
v.initialize(address(lp), _escapeHatchDestination);
lp.initialize(address(v), _escapeHatchDestination);
// register the lp instance w/ the kernel
kernel.setApp(kernel.APP_ADDR_NAMESPACE(), LP_APP_ID, address(lp));
_setPermissions(_root, acl, kernel, v, lp);
}

View File

@ -155,7 +155,7 @@ contract LiquidPledgingBase is EscapableApp, LiquidPledgingStorage, PledgeAdmins
/// plugin contract for a specific Admin
/// @param idAdmin The id of the admin being checked
function checkAdminOwner(uint64 idAdmin) internal constant {
PledgeAdmin a = _findAdmin(idAdmin);
PledgeAdmin storage a = _findAdmin(idAdmin);
require(msg.sender == address(a.plugin) || msg.sender == a.addr);
}
@ -302,7 +302,7 @@ contract LiquidPledgingBase is EscapableApp, LiquidPledgingStorage, PledgeAdmins
// Ensure that the pledge is not already at max pledge depth
// and the project has not been canceled
require(_getPledgeLevel(p) < MAX_INTERPROJECT_LEVEL);
require(!_isProjectCanceled(idReceiver));
require(!isProjectCanceled(idReceiver));
uint64 oldPledge = _findOrCreatePledge(
p.owner,
@ -436,7 +436,7 @@ contract LiquidPledgingBase is EscapableApp, LiquidPledgingStorage, PledgeAdmins
Pledge storage p = _findPledge(idPledge);
require(_getPledgeLevel(p) < MAX_INTERPROJECT_LEVEL);
require(!_isProjectCanceled(idReceiver));
require(!isProjectCanceled(idReceiver));
uint64 toPledge = _findOrCreatePledge(
p.owner,
@ -452,9 +452,9 @@ contract LiquidPledgingBase is EscapableApp, LiquidPledgingStorage, PledgeAdmins
/// @notice `doTransfer` is designed to allow for pledge amounts to be
/// shifted around internally.
/// @param from This is the id of the pledge from which value will be transfered.
/// @param to This is the id of the pledge that value will be transfered to.
/// @param _amount The amount of value that will be transfered.
/// @param from This is the id of the pledge from which value will be transferred.
/// @param to This is the id of the pledge that value will be transferred to.
/// @param _amount The amount of value that will be transferred.
function _doTransfer(uint64 from, uint64 to, uint _amount) internal {
uint amount = _callPlugins(true, from, to, _amount);
if (from == to) {
@ -512,7 +512,7 @@ contract LiquidPledgingBase is EscapableApp, LiquidPledgingStorage, PledgeAdmins
}
assert(admin.adminType == PledgeAdminType.Project);
if (!_isProjectCanceled(p.owner)) {
if (!isProjectCanceled(p.owner)) {
return idPledge;
}

View File

@ -27,18 +27,26 @@ contract LiquidPledgingPlugins is AragonApp, LiquidPledgingStorage, LiquidPledgi
bytes32 constant public PLUGIN_MANAGER_ROLE = keccak256("PLUGIN_MANAGER_ROLE");
function addValidPlugin(bytes32 contractHash) auth(PLUGIN_MANAGER_ROLE) public {
pluginWhitelist[contractHash] = true;
function addValidPluginInstance(address addr) auth(PLUGIN_MANAGER_ROLE) public {
pluginInstanceWhitelist[addr] = true;
}
function addValidPlugins(bytes32[] contractHashes) external auth(PLUGIN_MANAGER_ROLE) {
function addValidPluginContract(bytes32 contractHash) auth(PLUGIN_MANAGER_ROLE) public {
pluginContractWhitelist[contractHash] = true;
}
function addValidPluginContracts(bytes32[] contractHashes) external auth(PLUGIN_MANAGER_ROLE) {
for (uint8 i = 0; i < contractHashes.length; i++) {
addValidPlugin(contractHashes[i]);
addValidPluginContract(contractHashes[i]);
}
}
function removeValidPlugin(bytes32 contractHash) external authP(PLUGIN_MANAGER_ROLE, arr(contractHash)) {
pluginWhitelist[contractHash] = false;
function removeValidPluginContract(bytes32 contractHash) external authP(PLUGIN_MANAGER_ROLE, arr(contractHash)) {
pluginContractWhitelist[contractHash] = false;
}
function removeValidPluginInstance(address addr) external auth(PLUGIN_MANAGER_ROLE) {
pluginInstanceWhitelist[addr] = false;
}
function useWhitelist(bool useWhitelist) external auth(PLUGIN_MANAGER_ROLE) {
@ -50,9 +58,15 @@ contract LiquidPledgingPlugins is AragonApp, LiquidPledgingStorage, LiquidPledgi
return true;
}
// first check pluginInstances
if (pluginInstanceWhitelist[addr]) {
return true;
}
// if the addr isn't a valid instance, check the contract code
bytes32 contractHash = getCodeHash(addr);
return pluginWhitelist[contractHash];
return pluginContractWhitelist[contractHash];
}
function getCodeHash(address addr) public view returns(bytes32) {

View File

@ -50,7 +50,10 @@ contract LiquidPledgingStorage {
/// index number by the hash of that pledge
mapping (bytes32 => uint64) hPledge2idx;
mapping (bytes32 => bool) pluginWhitelist;
// this whitelist is for non-proxied plugins
mapping (bytes32 => bool) pluginContractWhitelist;
// this whitelist is for proxied plugins
mapping (address => bool) pluginInstanceWhitelist;
bool public whitelistDisabled = false;
ILPVault public vault;

View File

@ -307,24 +307,11 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
plugin = address(a.plugin);
}
///////////////////
// Internal methods
///////////////////
/// @notice A getter to look up a Admin's details
/// @param idAdmin The id for the Admin to lookup
/// @return The PledgeAdmin struct for the specified Admin
function _findAdmin(uint64 idAdmin) internal view returns (PledgeAdmin storage) {
require(idAdmin < admins.length);
return admins[idAdmin];
}
/// @notice A getter to find if a specified Project has been canceled
/// @param projectId The Admin id number used to specify the Project
/// @return True if the Project has been canceled
function _isProjectCanceled(uint64 projectId)
internal constant returns (bool)
function isProjectCanceled(uint64 projectId)
public constant returns (bool)
{
PledgeAdmin storage a = _findAdmin(projectId);
@ -341,7 +328,19 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
return false;
}
return _isProjectCanceled(a.parentProject);
return isProjectCanceled(a.parentProject);
}
///////////////////
// Internal methods
///////////////////
/// @notice A getter to look up a Admin's details
/// @param idAdmin The id for the Admin to lookup
/// @return The PledgeAdmin struct for the specified Admin
function _findAdmin(uint64 idAdmin) internal view returns (PledgeAdmin storage) {
require(idAdmin < admins.length);
return admins[idAdmin];
}
/// @notice Find the level of authority a specific Project has

View File

@ -99,7 +99,7 @@ describe('LiquidPledging plugins test', function () {
it('Should deploy TestSimpleProjectPlugin and add project', async function () {
// add plugin as valid plugin
const codeHash = web3.utils.soliditySha3(simpleProjectPluginRuntimeByteCode);
await liquidPledging.addValidPlugin(codeHash, { $extraGas: 200000 });
await liquidPledging.addValidPluginContract(codeHash, { $extraGas: 200000 });
// deploy new plugin
const factoryContract = await new web3.eth.Contract(simpleProjectPluginFactoryAbi)

5804
yarn.lock Normal file

File diff suppressed because it is too large Load Diff