ethereum: Added isFork() method

This commit is contained in:
Kevin Peters 2022-09-09 13:06:04 +00:00 committed by kev1n-peters
parent b1081d7d93
commit b7535a8e5b
8 changed files with 27 additions and 23 deletions

View File

@ -34,6 +34,10 @@ contract Getters is State {
return _state.evmChainId;
}
function isFork() public view returns (bool) {
return evmChainId() != block.chainid;
}
function governanceChainId() public view returns (uint16){
return _state.provider.governanceChainId;
}

View File

@ -25,7 +25,7 @@ abstract contract Governance is GovernanceStructs, Messages, Setters, ERC1967Upg
* @dev Upgrades a contract via Governance VAA/VM
*/
function submitContractUpgrade(bytes memory _vm) public {
require(evmChainId() == block.chainid, "bad fork");
require(!isFork(), "bad fork");
Structs.VM memory vm = parseVM(_vm);
@ -64,7 +64,7 @@ abstract contract Governance is GovernanceStructs, Messages, Setters, ERC1967Upg
require(upgrade.module == module, "Invalid Module");
// Verify the VAA is for this chain
require(upgrade.chain == chainId() && evmChainId() == block.chainid, "Invalid Chain");
require(upgrade.chain == chainId() && !isFork(), "Invalid Chain");
// Record the governance action as consumed to prevent reentry
setGovernanceActionConsumed(vm.hash);
@ -89,7 +89,7 @@ abstract contract Governance is GovernanceStructs, Messages, Setters, ERC1967Upg
require(upgrade.module == module, "invalid Module");
// Verify the VAA is for this chain
require((upgrade.chain == chainId() && evmChainId() == block.chainid) || upgrade.chain == 0, "invalid Chain");
require((upgrade.chain == chainId() && !isFork()) || upgrade.chain == 0, "invalid Chain");
// Verify the Guardian Set keys are not empty, this guards
// against the accidential upgrade to an empty GuardianSet
@ -128,7 +128,7 @@ abstract contract Governance is GovernanceStructs, Messages, Setters, ERC1967Upg
require(transfer.module == module, "invalid Module");
// Verify the VAA is for this chain
require((transfer.chain == chainId() && evmChainId() == block.chainid) || transfer.chain == 0, "invalid Chain");
require((transfer.chain == chainId() && !isFork()) || transfer.chain == 0, "invalid Chain");
// Record the governance action as consumed to prevent reentry
setGovernanceActionConsumed(vm.hash);
@ -144,7 +144,7 @@ abstract contract Governance is GovernanceStructs, Messages, Setters, ERC1967Upg
* @dev Updates the `chainId` and `evmChainId` on a forked chain via Governance VAA/VM
*/
function submitRecoverChainId(bytes memory _vm) public {
require(evmChainId() != block.chainid, "not a fork");
require(isFork(), "not a fork");
Structs.VM memory vm = parseVM(_vm);

View File

@ -20,11 +20,6 @@ import "./token/TokenImplementation.sol";
contract Bridge is BridgeGovernance, ReentrancyGuard {
using BytesLib for bytes;
modifier noFork() {
require(evmChainId() == block.chainid, "bad fork");
_;
}
/*
* @dev Produce a AssetMeta message for a given token
*/
@ -581,7 +576,8 @@ contract Bridge is BridgeGovernance, ReentrancyGuard {
setOutstandingBridged(token, outstandingBridged(token) - normalizedAmount);
}
function verifyBridgeVM(IWormhole.VM memory vm) internal view noFork returns (bool){
function verifyBridgeVM(IWormhole.VM memory vm) internal view returns (bool){
require(!isFork(), "bad fork");
if (bridgeContracts(vm.emitterChainId) == vm.emitterAddress) {
return true;
}

View File

@ -34,6 +34,10 @@ contract BridgeGetters is BridgeState {
return _state.evmChainId;
}
function isFork() public view returns (bool) {
return evmChainId() != block.chainid;
}
function governanceChainId() public view returns (uint16){
return _state.provider.governanceChainId;
}

View File

@ -33,7 +33,7 @@ contract BridgeGovernance is BridgeGetters, BridgeSetters, ERC1967Upgrade {
BridgeStructs.RegisterChain memory chain = parseRegisterChain(vm.payload);
require((chain.chainId == chainId() && evmChainId() == block.chainid) || chain.chainId == 0, "invalid chain id");
require((chain.chainId == chainId() && !isFork()) || chain.chainId == 0, "invalid chain id");
require(bridgeContracts(chain.emitterChainID) == bytes32(0), "chain already registered");
setBridgeImplementation(chain.emitterChainID, chain.emitterAddress);
@ -41,7 +41,7 @@ contract BridgeGovernance is BridgeGetters, BridgeSetters, ERC1967Upgrade {
// Execute a UpgradeContract governance message
function upgrade(bytes memory encodedVM) public {
require(evmChainId() == block.chainid, "bad fork");
require(!isFork(), "bad fork");
(IWormhole.VM memory vm, bool valid, string memory reason) = verifyGovernanceVM(encodedVM);
require(valid, reason);
@ -59,7 +59,7 @@ contract BridgeGovernance is BridgeGetters, BridgeSetters, ERC1967Upgrade {
* @dev Updates the `chainId` and `evmChainId` on a forked chain via Governance VAA/VM
*/
function submitRecoverChainId(bytes memory encodedVM) public {
require(evmChainId() != block.chainid, "not a fork");
require(isFork(), "not a fork");
(IWormhole.VM memory vm, bool valid, string memory reason) = verifyGovernanceVM(encodedVM);
require(valid, reason);

View File

@ -19,11 +19,6 @@ import "./token/NFTImplementation.sol";
contract NFTBridge is NFTBridgeGovernance {
using BytesLib for bytes;
modifier noFork() {
require(evmChainId() == block.chainid, "bad fork");
_;
}
// Initiate a Transfer
function transferNFT(address token, uint256 tokenID, uint16 recipientChain, bytes32 recipient, uint32 nonce) public payable returns (uint64 sequence) {
// determine token parameters
@ -197,7 +192,8 @@ contract NFTBridge is NFTBridgeGovernance {
setWrappedAsset(tokenChain, tokenAddress, token);
}
function verifyBridgeVM(IWormhole.VM memory vm) internal view noFork returns (bool){
function verifyBridgeVM(IWormhole.VM memory vm) internal view returns (bool){
require(!isFork(), "bad fork");
if (bridgeContracts(vm.emitterChainId) == vm.emitterAddress) {
return true;
}

View File

@ -34,6 +34,10 @@ contract NFTBridgeGetters is NFTBridgeState {
return _state.evmChainId;
}
function isFork() public view returns (bool) {
return evmChainId() != block.chainid;
}
function governanceChainId() public view returns (uint16){
return _state.provider.governanceChainId;
}

View File

@ -32,14 +32,14 @@ contract NFTBridgeGovernance is NFTBridgeGetters, NFTBridgeSetters, ERC1967Upgra
NFTBridgeStructs.RegisterChain memory chain = parseRegisterChain(vm.payload);
require((chain.chainId == chainId() && evmChainId() == block.chainid) || chain.chainId == 0, "invalid chain id");
require((chain.chainId == chainId() && !isFork()) || chain.chainId == 0, "invalid chain id");
setBridgeImplementation(chain.emitterChainID, chain.emitterAddress);
}
// Execute a UpgradeContract governance message
function upgrade(bytes memory encodedVM) public {
require(evmChainId() == block.chainid, "bad fork");
require(!isFork(), "bad fork");
(IWormhole.VM memory vm, bool valid, string memory reason) = verifyGovernanceVM(encodedVM);
require(valid, reason);
@ -57,7 +57,7 @@ contract NFTBridgeGovernance is NFTBridgeGetters, NFTBridgeSetters, ERC1967Upgra
* @dev Updates the `chainId` and `evmChainId` on a forked chain via Governance VAA/VM
*/
function submitRecoverChainId(bytes memory encodedVM) public {
require(evmChainId() != block.chainid, "not a fork");
require(isFork(), "not a fork");
(IWormhole.VM memory vm, bool valid, string memory reason) = verifyGovernanceVM(encodedVM);
require(valid, reason);