-
Notifications
You must be signed in to change notification settings - Fork 51
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
feat: optimistic timelock #25
base: main
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.
looks good to me, only 1 minor comment
function deny(bytes32 txHash) | ||
external override auth | ||
{ | ||
Proposal memory proposal = proposals[txHash]; |
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.
nit: I think you can save a tiny bit of gas with this:
Proposal storage proposal = proposals[txHash];
require(proposal.state == STATE.SCHEDULED);
proposal.state = STATE.DENIED;
^ won't need to copy storage to memory, won't need to look up storage twice
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 I'm doing something wrong, but using the pattern proposed in Timelock (for which I have tests) I get these gas costs:
·--------------------------------|---------------------------|---------------|----------------------------·
| Solc version: 0.8.6 · Optimizer enabled: true · Runs: 20000 · Block limit: 9500000 gas │
·································|···························|···············|·····························
| Methods │
·············|···················|·············|·············|···············|··············|··············
| Contract · Method · Min · Max · Avg · # calls · eur (avg) │
·············|···················|·············|·············|···············|··············|··············
| Timelock · approve · 36252 · 36264 · 36263 · 32 · - │
·············|···················|·············|·············|···············|··············|··············
| Timelock · execute · 46473 · 95392 · 56780 · 19 · - │
·············|···················|·············|·············|···············|··············|··············
While copying to memory is cheaper:
·--------------------------------|---------------------------|---------------|----------------------------·
| Solc version: 0.8.6 · Optimizer enabled: true · Runs: 20000 · Block limit: 9500000 gas │
·································|···························|···············|·····························
| Methods │
·············|···················|·············|·············|···············|··············|··············
| Contract · Method · Min · Max · Avg · # calls · eur (avg) │
·············|···················|·············|·············|···············|··············|··············
| Timelock · approve · 34793 · 34805 · 34804 · 32 · - │
·············|···················|·············|·············|···············|··············|··············
| Timelock · execute · 45794 · 94713 · 56101 · 19 · - │
·············|···················|·············|·············|···············|··············|··············
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.
Looks good to me, clean. I looked it over twice and couldn't find anything to improve on
With the OptimisticTimelock, all proposals are automatically approved, but an account with
deny
permissions can take them off the queue.In the event of a DoS attack, simply take the
schedule
permissions from the atacker.