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

revoke deployer key from timelock admin #15710

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions deployment/common/changeset/transfer_to_mcms_with_timelock.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,34 @@ func TransferToDeployer(e deployment.Environment, cfg TransferToDeployerConfig)
e.Logger.Infof("deployer key accepted ownership tx %s", tx.Hash().Hex())
return deployment.ChangesetOutput{}, nil
}

var _ deployment.ChangeSet[RenounceTimelockDeployerConfig] = RenounceTimelockDeployer

type RenounceTimelockDeployerConfig struct {
ChainSel uint64
}

// RenounceTimelockDeployer revokes the deployer key from administering the contract.
func RenounceTimelockDeployer(e deployment.Environment, cfg RenounceTimelockDeployerConfig) (deployment.ChangesetOutput, error) {
contracts, err := MaybeLoadMCMSWithTimelockState(e, []uint64{cfg.ChainSel})
if err != nil {
return deployment.ChangesetOutput{}, err
}
tl := contracts[cfg.ChainSel].Timelock
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth changing to the tl, ok := contracts[cfg.ChainSel] otherwise if nil it can throw a nil pointer panic

if tl == nil {
return deployment.ChangesetOutput{}, fmt.Errorf("timelock not found on chain %d", cfg.ChainSel)
}
admin, err := tl.ADMINROLE(&bind.CallOpts{})
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to get admin role: %w", err)
}
tx, err := tl.RenounceRole(e.Chains[cfg.ChainSel].DeployerKey, admin, e.Chains[cfg.ChainSel].DeployerKey.From)
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to revoke deployer key: %w", err)
}
if _, err := deployment.ConfirmIfNoError(e.Chains[cfg.ChainSel], tx, err); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to allow this to happen also via an mcms proposal? if so maybe we'll need to add conditional logic depending on the config similar to this one:

so users can decide if they want to execute right away or via an mcms proposal

Copy link
Contributor

Choose a reason for hiding this comment

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

this is not an MCMS proposal, this is done from an EOA since the deployer key has admin role and it renounces its own role

return deployment.ChangesetOutput{}, err
}
e.Logger.Infof("revoked deployer key from owning contract %s", tl.Address().Hex())
return deployment.ChangesetOutput{}, nil
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package changeset

import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -78,3 +80,59 @@ func TestTransferToMCMSWithTimelock(t *testing.T) {
require.NoError(t, err)
require.Equal(t, e.Chains[chain1].DeployerKey.From, o)
}

func TestRenounceTimelockDeployer(t *testing.T) {
lggr := logger.TestLogger(t)
e := memory.NewMemoryEnvironment(t, lggr, 0, memory.MemoryEnvironmentConfig{
Chains: 1,
Nodes: 1,
})
chain1 := e.AllChainSelectors()[0]
e, err := ApplyChangesets(t, e, nil, []ChangesetApplication{
{
Changeset: WrapChangeSet(DeployMCMSWithTimelock),
Config: map[uint64]types.MCMSWithTimelockConfig{
chain1: proposalutils.SingleGroupTimelockConfig(t),
},
},
})
require.NoError(t, err)
addrs, err := e.ExistingAddresses.AddressesForChain(chain1)
require.NoError(t, err)

state, err := MaybeLoadMCMSWithTimelockChainState(e.Chains[chain1], addrs)
require.NoError(t, err)

tl := state.Timelock
require.NotNil(t, tl)

adminRole, err := tl.ADMINROLE(nil)
require.NoError(t, err)

r, err := tl.GetRoleMemberCount(&bind.CallOpts{}, adminRole)
require.NoError(t, err)
require.Equal(t, int64(2), r.Int64())

// Revoke Deployer
e, err = ApplyChangesets(t, e, nil, []ChangesetApplication{
{
Changeset: WrapChangeSet(RenounceTimelockDeployer),
Config: RenounceTimelockDeployerConfig{
ChainSel: chain1,
},
},
})
require.NoError(t, err)

// Check that the deployer is no longer an admin
r, err = tl.GetRoleMemberCount(&bind.CallOpts{}, adminRole)
require.NoError(t, err)
require.Equal(t, int64(1), r.Int64())

// Retrieve the admin address
admin, err := tl.GetRoleMember(&bind.CallOpts{}, adminRole, big.NewInt(0))
require.NoError(t, err)

// Check that the admin is the timelock
require.Equal(t, tl.Address(), admin)
}
Loading