2023-05-21 13:21:59 -04:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2023-05-21 15:51:14 -04:00
|
|
|
pragma solidity ^0.6.12;
|
2023-05-21 13:21:59 -04:00
|
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
|
|
|
|
import "../v1/Governance.sol";
|
|
|
|
import "../v3-relayer-registry/GovernanceStakingUpgrade.sol";
|
|
|
|
|
2023-05-21 15:51:14 -04:00
|
|
|
contract GovernancePatchUpgrade is GovernanceStakingUpgrade {
|
|
|
|
mapping(uint256 => bytes32) public proposalCodehashes;
|
2023-05-21 13:21:59 -04:00
|
|
|
|
2023-05-21 15:51:14 -04:00
|
|
|
constructor(
|
|
|
|
address stakingRewardsAddress,
|
|
|
|
address gasCompLogic,
|
|
|
|
address userVaultAddress
|
|
|
|
) public GovernanceStakingUpgrade(stakingRewardsAddress, gasCompLogic, userVaultAddress) {}
|
|
|
|
|
2023-05-23 17:41:03 -04:00
|
|
|
/// @notice Return the version of the contract
|
2023-05-22 17:58:31 -04:00
|
|
|
function version() external pure virtual override returns (string memory) {
|
|
|
|
return "4.patch-exploit";
|
|
|
|
}
|
|
|
|
|
2023-05-23 17:41:03 -04:00
|
|
|
/**
|
|
|
|
* @notice Execute a proposal
|
|
|
|
* @dev This upgrade should protect against Metamorphic contracts by comparing the proposal's extcodehash with a stored one
|
|
|
|
* @param proposalId The proposal's ID
|
|
|
|
*/
|
2023-05-21 15:51:14 -04:00
|
|
|
function execute(uint256 proposalId) public payable virtual override(Governance) {
|
2023-05-23 17:41:03 -04:00
|
|
|
require(msg.sender != address(this), "Governance::propose: pseudo-external function");
|
2023-05-21 13:21:59 -04:00
|
|
|
|
|
|
|
Proposal storage proposal = proposals[proposalId];
|
|
|
|
|
2023-05-21 15:51:14 -04:00
|
|
|
address target = proposal.target;
|
|
|
|
|
|
|
|
bytes32 proposalCodehash;
|
|
|
|
|
|
|
|
assembly {
|
|
|
|
proposalCodehash := extcodehash(target)
|
|
|
|
}
|
|
|
|
|
2023-05-22 16:25:59 -04:00
|
|
|
require(proposalCodehash == proposalCodehashes[proposalId], "Governance::propose: metamorphic contracts not allowed");
|
2023-05-21 21:44:30 -04:00
|
|
|
|
2023-05-22 16:25:59 -04:00
|
|
|
super.execute(proposalId);
|
2023-05-21 13:21:59 -04:00
|
|
|
}
|
|
|
|
|
2023-05-23 17:41:03 -04:00
|
|
|
/**
|
|
|
|
* @notice Internal function called from propoese
|
|
|
|
* @dev This should store the extcodehash of the proposal contract
|
|
|
|
* @param proposer proposer address
|
|
|
|
* @param target smart contact address that will be executed as result of voting
|
|
|
|
* @param description description of the proposal
|
|
|
|
* @return proposalId new proposal id
|
|
|
|
*/
|
2023-05-21 13:21:59 -04:00
|
|
|
function _propose(
|
|
|
|
address proposer,
|
|
|
|
address target,
|
|
|
|
string memory description
|
2023-05-21 15:51:14 -04:00
|
|
|
) internal virtual override(Governance) returns (uint256 proposalId) {
|
|
|
|
// Implies all former predicates were valid
|
|
|
|
proposalId = super._propose(proposer, target, description);
|
|
|
|
|
|
|
|
bytes32 proposalCodehash;
|
|
|
|
|
|
|
|
assembly {
|
|
|
|
proposalCodehash := extcodehash(target)
|
|
|
|
}
|
|
|
|
|
|
|
|
proposalCodehashes[proposalId] = proposalCodehash;
|
2023-05-21 13:21:59 -04:00
|
|
|
}
|
|
|
|
}
|