Search code examples
nearprotocol

Why would you delete the access keys to your NEAR account containing a smart contract?


This answer about upgradability suggests that at some point you should delete access keys to the account containing a smart contract: How do you upgrade NEAR smart contracts?.

It makes sense that a smart contract should be "frozen" at some point, and you want to give its users confidence that it will not be changed. But what about contract rewards and other funds belonging to the contract account? How would the original owner get access to that if keys are deleted?


Solution

  • But what about contract rewards and other funds belonging to the contract account? How would the original owner get access to that if keys are deleted?

    The contract should be implemented in such a way that would allow certain operations.

    Let's take a lockup contract as an example. This contract has a single owner, and the funds are locked for a certain amount of time, and the contract only provides certain methods to be called and guarded with the specific logic:

    • As an owner, I can delegate (stake) my tokens to staking pools while I still cannot arbitrary transfer the tokens
    • As an owner, I can withdraw the rewards from the staking pool through the lockup contract, and transfer those to an arbitrary account
    • Once the lockup time is over, as an owner, I can call add_full_access_key function, and thus gain full access over the account, and even delete it after that (transferring all the tokens to some other account).

    All that is explicitly implemented on the contract level, and easy to review, and given there is no other AccessKey on the lockup contract, we can be sure that there is no other way to interfere with the contract logic.