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

Add ability to enable / disable depositable functionality #401

Merged
merged 13 commits into from
Sep 4, 2018

Conversation

sohkai
Copy link
Contributor

@sohkai sohkai commented Aug 27, 2018

Before, only the App and Kernel proxies were able to receive ETH through generic send() or transfer()s. There was no way to control whether this was desired functionality, or a way to turn it off after a certain condition (e.g. ending a token sale).

This PR adds depositable functionality to the App and Kernel base contracts, as well as a way for Apps to turn off the ability to receive ETH.

  • 816e166 and 01821c6: cleans up a bit of test code
  • fec0a9a adds DepositableStorage
  • 3d48720 uses DepositableStorage to control depositing functionality in the App and Kernel
  • 027c522 and 1baa570 fix some "surprising" test changes due to the changes.
    • Notably, the recent changes have forced APMRegistryFactory.newAPM() to go over 6.9m gas again
    • Kernels now have a fallback, so unregistered functions won't automatically revert

@sohkai sohkai requested review from izqui and bingen August 27, 2018 13:27
@@ -28,6 +29,10 @@ contract Kernel is IKernel, KernelStorage, Petrifiable, IsContract, VaultRecover
}
}

function () external payable {
require(isDepositable());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To work around the changes in https://github.com/aragon/aragonOS/pull/401/files#diff-61de883632b625f81d4e28af414a9c90R64, we could also require that the value must be greater than 0 here and in AragonApp.

@coveralls
Copy link

coveralls commented Aug 27, 2018

Coverage Status

Coverage decreased (-0.003%) to 99.063% when pulling 5b76372 on depositable-check into 5b880fc on dev.

@@ -44,6 +49,7 @@ contract Kernel is IKernel, KernelStorage, Petrifiable, IsContract, VaultRecover

acl.initialize(_permissionsCreator);

setDepositable(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think depositing to the kernel should be disabled by default, given that there is no reason to send funds to the kernel for now. I think it is good that the KernelProxy keeps the functionality (in case the Kernel having ETH makes sense at some point), but it should be disabled IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My main reason for enabling it was because Kernels are assigned ENS names through our initial templates, and so I could see users sending ETH directly to that name.

However, thinking about it, it's less confusing if the kernel reverts on receiving ETH directly than requiring a user to manually use the escape hatch functionality to transfer the funds to the vault. In the future, a different ENS name could be used for a finance or funding app, e.g. finance.<dao name>.aragonid.eth.

@@ -27,6 +28,10 @@ contract AragonApp is AppStorage, Autopetrified, VaultRecoverable, EVMScriptRunn
_;
}

function () external payable {
require(isDepositable());
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason behind adding a fallback by default to all apps? IMO apps should define their own fallback function if they want to receive ETH. It may seem weird that depending on the gas value, a deposit can happen or not, but I'd say deposits and recovers should be used as the last resort and when a call is already forwarded to app, its own logic should be responsible for deciding on what to do.

In case we decide to keep this, we should definitely check for data being empty and value being greater than 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Now that DepositableDelegateProxys also need their depositing functionality explicitly enabled, I agree that apps should define their own fallback if they want to receive ETH.

@sohkai sohkai added this to the sprint: 1.1 milestone Aug 29, 2018
@sohkai sohkai self-assigned this Aug 30, 2018
@sohkai
Copy link
Contributor Author

sohkai commented Sep 3, 2018

Updated to disable depositable functionality by default.

Copy link
Contributor

@bingen bingen left a comment

Choose a reason for hiding this comment

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

Looks good to me, letting aside some minor comments I left (plus the well-known fact that I'm not a big fan of allowing our apps to work without a proxy ;-P)

'test',
'acl/ACLSyntaxSugar.sol',
'common/DepositableStorage.sol', // Used in tests that send ETH
'common/UnstructuredStorage.sol' // Used in tests that send ETH
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 skipping those files? The last 2 ones at least do have tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking to see if we can remove those from the ignored list... Originally the problem was that instrumentation in those files meant using unstructured storage in a fallback was more expensive than 2.3k gas (the instrumentation emits two events before and after each line of code in those files).

Copy link
Contributor Author

@sohkai sohkai Sep 4, 2018

Choose a reason for hiding this comment

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

Tried removing either one... and unfortunately coverage fails :(. I think they're not too important to get coverage stats on anyway, since they're just one-liners.

await kernel.setApp(APP_ADDR_NAMESPACE, vaultId, vault.address)
await kernel.setRecoveryVaultAppId(vaultId)
})

onlyBaseKernel(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

onlyBaseKernel and onlyKernelProxy are not used anymore, right? Then we can remove above (lines 81, 82)

@@ -0,0 +1,17 @@
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.

I'm not sure that we really need this test, as we are testing something that our codebase doesn't offer, right? Besides I don't think I like the idea of a depositable kernel, but maybe it's because I'm missing some possible use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to keep it, as it's functionality that could be enabled, even if it's not directly offered.

@@ -129,47 +130,26 @@ contract('Proxy funds', accounts => {
const vaultProxyAddress = getEvent(receipt, 'NewAppProxy', 'proxy')
vault = VaultMock.at(vaultProxyAddress)
}
await vault.initialize()
Copy link
Contributor

Choose a reason for hiding this comment

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

(I'm putting this comment here because the proper line has not been changed, which probably means that this comment actually belongs to a previous PR, haha)
If I'm not wrong, with these 2 nested for's for Kernel and Vault, we are testing 4 possibilities. I don't see the point of testing proxied Kernel with a proxy-less Vault, or proxy-less Kernel with a proxied Vault. It's giving me hard time to think about these tests, haha ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's a matrix of all the combinations.

I'd like to keep it, again to ensure that behaviour across all the combinations is the same. Even if it's rare, it simplifies the mental model–regardless of using a base or proxy, they should act the same. This PR moves even closer to that ideal, now that we can remove the onlyIf targeted tests.

@sohkai sohkai merged commit a56234e into dev Sep 4, 2018
@sohkai sohkai deleted the depositable-check branch September 4, 2018 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants