anoma / namada

Rust implementation of Namada, a Proof-of-Stake L1 for interchain asset-agnostic privacy
https://namada.net
GNU General Public License v3.0
2.38k stars 950 forks source link

Get Ethereum smart contract version from Storage #249

Open sug0 opened 1 year ago

sug0 commented 1 year ago

The Bridge.sol smart contract contains a version field, which is updated with every contract upgrade. Validator set updates are signed together with the version of the contract. Therefore, in the ledger, we should keep track of this value, probably in Storage, which will be fetched at the end of an epoch to sign the new validator set.

Additionally, the Governance.sol smart contract has a version field of its own, separate from the one present in Bridge.sol. Thus, in our code, we would need, e.g. some Storage::get_bridge_contract_version and Storage::get_governance_contract_version methods.

As for the mechanism to synchronize these version values with the smart contracts, there are two ways to go about it:

  1. We can have a getter field in the smart contract that returns its version.
  2. We can gossip an Ethereum event after a version update, and modify our local version value at the FinalizeBlock stage, after a vote extension has been decided with the given event.

Getter fields in smart contracts don't spend gas, so option 1) is probably the best method to follow. However, we need a certain number of blocks as confirmation before we can use this value.

sug0 commented 1 year ago

We will not need this after all. The version of the smart contract was only being signed together with the vote extension to guarantee monotonicity of sequence numbers across contract upgrades. The contract is now being initialized with a sequence number (the epoch), so it's not required to sign over version fields.

sug0 commented 1 year ago

We're using version fields in Ethereum signed messages. They're currently hardcoded to 1, but we should look them up from storage. Upgrades to contracts can be delivered via governance proposals, updating the appropriate storage keys (contract address + version).