Intelligent Contracts
Feature List
Upgradability

Upgradability

During deployment contract may freeze certain storage slots. Frozen slots can be modified only if sender of the transaction is in upgraders list. Therefore, an empty locked upgraders list with a frozen code slot makes the contract non-upgradable.

See GenVM specification (opens in a new tab) for more details.

Example

class Proxy(gl.Contract):
    def __init__(self, upgrader: Address):
        root = gl.storage.Root.get()
        root.upgraders.append(upgrader)
        # default bootloader freezes relevant slots
        # so we need to modify only upgraders
 
    @gl.public.write
    def update_code(self, new_code: bytes):
        root = gl.storage.Root.get()
        code_vla = root.code.get()
 
        # If gl.message.sender_address is not in upgraders, below will issue a VMError
        code_vla.truncate() # Clear existing code
        code_vla.extend(new_code) # Put the new code