Skip to content

Commit

Permalink
evm: remove comments; remove irrelevant error
Browse files Browse the repository at this point in the history
  • Loading branch information
a5-pickle committed Dec 21, 2023
1 parent 90bcbce commit 8095770
Showing 1 changed file with 0 additions and 26 deletions.
26 changes: 0 additions & 26 deletions evm/src/contracts/CircleIntegration/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
abstract contract Governance is IGovernance, State, ERC1967Upgrade {
using BytesParsing for bytes;

error UnsupportedGovernanceAction();

uint16 constant GOVERNANCE_CHAIN = 1;
bytes32 constant GOVERNANCE_EMITTER =
0x0000000000000000000000000000000000000000000000000000000000000004;
Expand All @@ -42,32 +40,23 @@ abstract contract Governance is IGovernance, State, ERC1967Upgrade {
// unless the target chain is 0 (which means all chains).
uint16 targetChain;
(targetChain, offset) = vaa.payload.asUint16Unchecked(offset);

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(targetChain == 0 || targetChain == _chainId, "invalid target chain");

uint16 foreignChain;
(foreignChain, offset) = vaa.payload.asUint16Unchecked(offset);

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(foreignChain != 0 && foreignChain != _chainId, "invalid chain");

mapping(uint16 => bytes32) storage registeredEmitters = getRegisteredEmitters();

// For now, ensure that we cannot register the same foreign chain again.
// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(registeredEmitters[foreignChain] == 0, "chain already registered");

bytes32 foreignAddress;
(foreignAddress, offset) = vaa.payload.asBytes32Unchecked(offset);

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(foreignAddress != 0, "emitter cannot be zero address");

uint32 cctpDomain;
(cctpDomain, offset) = vaa.payload.asUint32Unchecked(offset);

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(cctpDomain != _localCctpDomain, "domain == localDomain()");

_checkLength(vaa.payload, offset);
Expand Down Expand Up @@ -102,14 +91,10 @@ abstract contract Governance is IGovernance, State, ERC1967Upgrade {
// contract upgrades should only be relevant for this contract's chain ID
uint16 targetChain;
(targetChain, offset) = vaa.payload.asUint16Unchecked(offset);

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(targetChain == _chainId, "invalid target chain");

bytes32 encodedImplementation;
(encodedImplementation, offset) = vaa.payload.asBytes32Unchecked(offset);

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(bytes12(encodedImplementation) == 0, "invalid address");

_checkLength(vaa.payload, offset);
Expand All @@ -125,7 +110,6 @@ abstract contract Governance is IGovernance, State, ERC1967Upgrade {
abi.encodeWithSignature("circleIntegrationImplementation()")
);

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(queried.length == 32, "invalid implementation");
require(
abi.decode(queried, (bytes32)) == keccak256("circleIntegrationImplementation()"),
Expand All @@ -141,8 +125,6 @@ abstract contract Governance is IGovernance, State, ERC1967Upgrade {
// call initialize function of the new implementation
(bool success, bytes memory reason) =
newImplementation.delegatecall(abi.encodeWithSignature("initialize()"));

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(success, string(reason));

emit ContractUpgraded(currentImplementation, newImplementation);
Expand Down Expand Up @@ -180,41 +162,33 @@ abstract contract Governance is IGovernance, State, ERC1967Upgrade {
uint8 action
) private view returns (IWormhole.VM memory vaa, uint256 offset) {
// Make sure the blockchain has not forked.
// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(block.chainid == _evmChain, "invalid evm chain");

// verify the governance message
bool valid;
string memory reason;
(vaa, valid, reason) = _wormhole.parseAndVerifyVM(encodedVaa);

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(valid, reason);

// Confirm that the governance message was sent from the governance contract.
// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(vaa.emitterChainId == GOVERNANCE_CHAIN, "invalid governance chain");
require(vaa.emitterAddress == GOVERNANCE_EMITTER, "invalid governance contract");

// Confirm that this governance action has not been consumed already.
// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(!consumedVaas[vaa.hash], "governance action already consumed");

bytes32 govModule;
(govModule, offset) = vaa.payload.asBytes32Unchecked(offset);

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(govModule == GOVERNANCE_MODULE, "invalid governance module");

uint8 govAction;
(govAction, offset) = vaa.payload.asUint8Unchecked(offset);

// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(govAction == action, "invalid governance action");
}

function _checkLength(bytes memory encoded, uint256 expected) private pure {
// NOTE: Reverting with Error(string) comes from the old implementation, so we preserve it.
require(encoded.length == expected, "invalid governance payload length");
}

Expand Down

0 comments on commit 8095770

Please sign in to comment.