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

feat: optimistic timelock #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

alcueca
Copy link
Contributor

@alcueca alcueca commented Sep 10, 2021

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.

@alcueca alcueca requested a review from iamsahu September 21, 2021 11:32
Copy link
Contributor

@sblOWPCKCR sblOWPCKCR 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, only 1 minor comment

function deny(bytes32 txHash)
external override auth
{
Proposal memory proposal = proposals[txHash];
Copy link
Contributor

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

Copy link
Contributor Author

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  ·          -  │
·············|···················|·············|·············|···············|··············|··············

Copy link
Contributor

@devtooligan devtooligan 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, clean. I looked it over twice and couldn't find anything to improve on

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.

3 participants