polygon-edge icon indicating copy to clipboard operation
polygon-edge copied to clipboard

Permission smart contract deployment

Open 0xAleksaOpacic opened this issue 3 years ago • 5 comments

Description

This PR implements permission smart contract deployment feature.

How it works: The idea behind this feature is that we want to enable nodes to restrict who can deploy smart contracts. We've decided to add a deployment whitelist and only addresses inside this list can deploy smart contracts. When the deployment whitelist is empty anyone can deploy contracts

To make this easy to use, we've added a few CLI commands:

  1. AddAddress go run main.go whitelist deployment --addAddress 0x5383Cb489FaCa92365Bb6f9f1FB40bD032E6365d --addAddress 0x5383Cb489FaCa92365Bb6f9f1FB40bD032E6365d Screenshot 2022-08-22 at 19 01 35

  2. removeAddress go run main.go whitelist deployment --removeAddress 0x5383Cb489FaCa92365Bb6f9f1FB40bD032E6365d --removeAddress 0x5383Cb489FaCa92365Bb6f9f1FB40bD032E6365d Screenshot 2022-08-22 at 19 03 10

After changing the deployment whitelist, nodes should be restarted to fetch the latest whitelist from genesis config

  1. Show all whitelist go run main.go whitelist show Screenshot 2022-08-22 at 19 05 02 1

Changes include

  • [ ] Bugfix (non-breaking change that solves an issue)
  • [ ] Hotfix (change that solves an urgent issue, and requires immediate attention)
  • [x] New feature (non-breaking change that adds functionality)
  • [ ] Breaking change (change that is not backwards-compatible and/or changes current functionality)

Checklist

  • [x] I have assigned this PR to myself
  • [x] I have added at least 1 reviewer
  • [x] I have added the relevant labels
  • [ ] I have updated the official documentation
  • [x] I have added sufficient documentation in code

Testing

  • [x] I have tested this code with the official test suite
  • [x] I have tested this code manually

Manual tests

Scenarios covered by unit tests:

  1. Deployment whitelist is empty anyone can deploy:

    1. Start a network
    2. Deploy smart contract from any address
  2. Addresses inside the whitelist can deploy smart contract

    1. Start a network
    2. Add the address to the whitelist
    3. Only that address should be able to deploy a smart contract

Other scenarios

  1. User should be able to burn tokens on 0x address
  2. Whitelist should not affect EOA transfers and smart contract interaction

Documentation update

After the first round of reviews, I will write docs

Additional comments

Fixes EDGE-735

0xAleksaOpacic avatar Aug 22 '22 08:08 0xAleksaOpacic

Codecov Report

Merging #692 (da99143) into develop (210de9e) will increase coverage by 0.07%. The diff coverage is 89.65%.

@@             Coverage Diff             @@
##           develop     #692      +/-   ##
===========================================
+ Coverage    48.72%   48.79%   +0.07%     
===========================================
  Files          112      112              
  Lines        15432    15460      +28     
===========================================
+ Hits          7519     7544      +25     
- Misses        7279     7281       +2     
- Partials       634      635       +1     
Impacted Files Coverage Δ
chain/params.go 50.00% <ø> (ø)
types/transaction.go 61.40% <ø> (ø)
txpool/txpool.go 73.33% <89.65%> (+0.92%) :arrow_up:
syncer/client.go 61.79% <0.00%> (-1.42%) :arrow_down:
txpool/account.go 94.94% <0.00%> (+1.68%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Aug 22 '22 16:08 codecov[bot]

Codecov Report

Merging #692 (138f49e) into develop (de62840) will decrease coverage by 0.21%. The diff coverage is 5.26%.

❗ Current head 138f49e differs from pull request most recent head 12ffd1b. Consider uploading reports for the commit 12ffd1b to get more accurate results

@@             Coverage Diff             @@
##           develop     #692      +/-   ##
===========================================
- Coverage    48.77%   48.55%   -0.22%     
===========================================
  Files          112      112              
  Lines        15382    15401      +19     
===========================================
- Hits          7502     7478      -24     
- Misses        7249     7288      +39     
- Partials       631      635       +4     

Impacted Files Coverage Δ chain/params.go 50.00% <ø> (ø) types/transaction.go 53.03% <0.00%> (-8.38%) ⬇️ types/types.go 64.65% <0.00%> (-3.53%) ⬇️ txpool/txpool.go 70.62% <25.00%> (-0.42%) ⬇️ network/server_discovery.go 73.88% <0.00%> (-15.93%) ⬇️ 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Code coverage is affected because we don't have tests for commands 😭

0xAleksaOpacic avatar Aug 22 '22 16:08 0xAleksaOpacic

@Aleksao998

Code coverage is affected because we don't have tests for commands 😭

Save the excuses for the coverage police 👮‍♂️

zivkovicmilos avatar Aug 22 '22 18:08 zivkovicmilos

@Aleksao998

After the first round of reviews, I will write docs

This is a clever way of saying you'll do it later 😄

zivkovicmilos avatar Aug 22 '22 20:08 zivkovicmilos

@Aleksao998

Linter failing after latest pushes

zivkovicmilos avatar Aug 23 '22 11:08 zivkovicmilos