Etica: How Etica smart contract upgrades will work

Kevin Wad
4 min readFeb 7, 2023

Hi,
I’m proud to announce we have a way to make the Etica smart contract upgradable through hardforks like EIPs.

A major step for Etica, since the immutalbility of the smart contract was the main challenge for the one smart contract model (Etica aims to have only one main Smart contract).

This is a short explanation without getting too much into technical details of how Etica blockchain will make its core smart contract upgradable.

I. Ethereum blockchain. Are smart contracts truly not upgradable?

Etica being a fork of Ethereum, over the past few days I’ve been diving into Ethereum source code and it appears the immutability of smart contracts is more a social design than a technical design. Meaning there is no technical system to make smart contracts code immutable.
In facy every smart contract has a clear separation between its data and its code. On ethereum, accounts are defined by 4 fields:
Nonce, Balance, Storage and Code.

Ethereum accounts

Smart contract accounts store their code (ByteCode) in the Code field while externally owned accounts (user accounts) have the Code field set to empty.

Let’s focus on Smart contracts accounts:

The Storage is the data of the smart contract. The storage contains all the variables that can change value (Arrays, Maps, Uints…), it’s like a dedicated database of the smart contract.

The Code field contains the ByteCode. The Bytecode is a constant and it also contains all the Constants of the smart contract. The ByteCode is the code that is executed when a user sends a transaction to the smart contract address. When we interact with a smart contract we simply send inputs to the ByteCode of a smart contract that will run its ByteCode and update its storage data based on its previous state.

This clear separtion between Storage and Code is what will make it possible for Etica to implement a system to Upgrade the Etica smart contract.

II. Etica smart contract upgrades process

The updates of Etica smart contract should be extremely rare. Nonetheless it is important we can update the smart contract when necessary at least for security.

Etica smart contract upgrades will work almost exaclty like EIPs. Once community agrees on a change there will be a block height chosen to acitvate the new smart contract changes.

Upgrade Process, example:

Etica mainnet smart contract address is and will remain: 0x34c61EA91bAcdA647269d4e310A86b875c09946f

Let’s call current version of Etica smart contract V1 and let’s see how Etica could upgrade to a V2 while keeping its address (0x34c…946f) and its storage.

a) Deploy new ByteCode
First we deploy the new smart contract Code V2 (ByteCode) on the Etica mainnet. Now there is a new smart contract (at a random address, for instance: 0x39c…729e) that has the new ByteCode on its Code field. But remember the ByteCode is a constant and after compilation, there is clear separation between what is constant (ByteCode) and the Data (Storage). So the new smart contract will have its own Storage clearly separated from its ByteCode.

b) Update Etica ByteCode
Now, it is possible for the Network to agree to take the ByteCode of new smart contract (0x39c…729) and to put it in the Etica Smart contract’s Code field. After this, Etica smart contract will keep same address and same storage but the ByteCode that will run when will call 0x34c…946f address will correspond to the new bytecode.

c) Config file on every node
On the blockchain source code there will be a config file that every node will use to keep track of such Etica Smart contract upgrades.

Example:
EticaV2Block: 3 000 000
EticaV2ReferenceAddress: 0x39c…729

For instance in this example every node will know that at block 3 000 000 they have to update Etica smart contract with Bytecode stored at address 0x39c…729.

d) That’s it. Now Etica smart contract code would be upgraded while preserving its address and storage.

Potential Limits?
Let me know if you see potential limits with this system, so far it appears to be a great system to upgrade the smart contract and everything works as expected after tests

The good news is now it will be possible to update the Etica Smart Contract providing the community votes for an upadte or if a security issue is found.

--

--