Skip to content

Commit

Permalink
Merge pull request #3 from gnosischain/revert-2-fix/mismatch_contract
Browse files Browse the repository at this point in the history
Revert "update contracts with deployed code "
  • Loading branch information
zengzengzenghuy authored Apr 17, 2024
2 parents b5bed9b + 21456de commit e672562
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 77 deletions.
25 changes: 10 additions & 15 deletions contracts/helpers/AMBBridgeHelper.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
pragma solidity 0.7.6;
pragma solidity 0.4.24;

interface IHomeBridge {
function numMessagesSigned(bytes32 _message) external view returns (uint256);

function isAlreadyProcessed(uint256 _number) external pure returns (bool);

function signature(bytes32 _hash, uint256 _index) external view returns (bytes memory);
}

contract Helper {
function unpackSignature(bytes memory _signature) internal pure returns (bytes32, bytes32, uint8) {
function unpackSignature(bytes memory _signature) internal pure returns (bytes32 r, bytes32 s, uint8 v) {
require(_signature.length == 65);
bytes32 r;
bytes32 s;
uint8 v;

assembly {
r := mload(add(_signature, 0x20))
Expand All @@ -25,19 +20,19 @@ contract Helper {
}

contract AMBBridgeHelper is Helper {
address payable owner;
IHomeBridge public AMBcontract;
address public owner;
IHomeBridge public ambBridge;

constructor(address _homeBridge) {
constructor(address _homeBridge) public {
owner = msg.sender;
AMBcontract = IHomeBridge(_homeBridge);
ambBridge = IHomeBridge(_homeBridge);
}

function getSignatures(bytes calldata _message) external view returns (bytes memory) {
function getSignatures(bytes _message) external view returns (bytes memory) {
bytes32 msgHash = keccak256(abi.encodePacked(_message));
uint256 signed = AMBcontract.numMessagesSigned(msgHash);
uint256 signed = ambBridge.numMessagesSigned(msgHash);

require(AMBcontract.isAlreadyProcessed(signed), "message hasn't been confirmed");
require(ambBridge.isAlreadyProcessed(signed), "message hasn't been confirmed");

// recover number of confirmations sent by oracles
signed = signed & 0x8fffffffffffffffffffffffffffffffffffffffffff;
Expand All @@ -51,7 +46,7 @@ contract AMBBridgeHelper is Helper {
}

for (uint256 i = 0; i < signed; i++) {
bytes memory sig = AMBcontract.signature(msgHash, i);
bytes memory sig = ambBridge.signature(msgHash, i);
(bytes32 r, bytes32 s, uint8 v) = unpackSignature(sig);
assembly {
mstore8(add(add(signatures, 33), i), v)
Expand Down
13 changes: 6 additions & 7 deletions contracts/upgradeable_contracts/BridgeValidators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ pragma solidity 0.4.24;
import "./BaseBridgeValidators.sol";

contract BridgeValidators is BaseBridgeValidators {
function initialize(
uint256 _requiredSignatures,
address[] _initialValidators,
address _owner
) external onlyRelevantSender returns (bool) {
function initialize(uint256 _requiredSignatures, address[] _initialValidators, address _owner)
external
onlyRelevantSender
returns (bool)
{
require(!isInitialized());
require(_owner != address(0));
setOwner(_owner);
_setOwner(_owner);
require(_requiredSignatures != 0);
require(_initialValidators.length >= _requiredSignatures);

Expand Down
38 changes: 19 additions & 19 deletions contracts/upgradeable_contracts/Ownable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ contract Ownable is EternalStorage {
bytes4 internal constant UPGRADEABILITY_OWNER = 0x6fde8202; // upgradeabilityOwner()

/**
* @dev Event to show ownership has been transferred
* @param previousOwner representing the address of the previous owner
* @param newOwner representing the address of the new owner
*/
* @dev Event to show ownership has been transferred
* @param previousOwner representing the address of the previous owner
* @param newOwner representing the address of the new owner
*/
event OwnershipTransferred(address previousOwner, address newOwner);

/**
* @dev Throws if called by any account other than the owner.
*/
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner());
/* solcov ignore next */
_;
}

/**
* @dev Throws if called by any account other than contract itself or owner.
*/
* @dev Throws if called by any account other than contract itself or owner.
*/
modifier onlyRelevantSender() {
// proxy owner if used through proxy, address(0) otherwise
require(
Expand All @@ -43,26 +43,26 @@ contract Ownable is EternalStorage {
bytes32 internal constant OWNER = 0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0; // keccak256(abi.encodePacked("owner"))

/**
* @dev Tells the address of the owner
* @return the address of the owner
*/
* @dev Tells the address of the owner
* @return the address of the owner
*/
function owner() public view returns (address) {
return addressStorage[OWNER];
}

/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner the address to transfer ownership to.
*/
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner the address to transfer ownership to.
*/
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0));
setOwner(newOwner);
_setOwner(newOwner);
}

/**
* @dev Sets a new owner address
*/
function setOwner(address newOwner) internal {
* @dev Sets a new owner address
*/
function _setOwner(address newOwner) internal {
require(newOwner != address(0));
emit OwnershipTransferred(owner(), newOwner);
addressStorage[OWNER] = newOwner;
}
Expand Down
36 changes: 0 additions & 36 deletions contracts/upgradeable_contracts/arbitrary_message/HomeAMB.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,4 @@ contract HomeAMB is AsyncInformationProcessor {
function emitEventOnMessageProcessed(address sender, address executor, bytes32 messageId, bool status) internal {
emit AffirmationCompleted(sender, executor, messageId, status);
}

// selector 88414e32
function migrateTo_6_2_0() public {
bytes32 upgradeStorage = 0x88414e324531481ad93973c16b3c225896f52a671f48e02a8d180df7c05108c1; // keccak256(abi.encodePacked('migrateTo_6_2_0()'))
require(!boolStorage[upgradeStorage]);

bytes32 sel = keccak256(abi.encodePacked("eth_call(address,bytes)"));
boolStorage[keccak256(abi.encodePacked("enableRequestSelector", sel))] = true;
emit EnabledAsyncRequestSelector(sel, true);

sel = keccak256(abi.encodePacked("eth_getBalance(address)"));
boolStorage[keccak256(abi.encodePacked("enableRequestSelector", sel))] = true;
emit EnabledAsyncRequestSelector(sel, true);

sel = keccak256(abi.encodePacked("eth_getBlockByNumber(uint256)"));
boolStorage[keccak256(abi.encodePacked("enableRequestSelector", sel))] = true;
emit EnabledAsyncRequestSelector(sel, true);

sel = keccak256(abi.encodePacked("eth_getBlockByHash(bytes32)"));
boolStorage[keccak256(abi.encodePacked("enableRequestSelector", sel))] = true;
emit EnabledAsyncRequestSelector(sel, true);

sel = keccak256(abi.encodePacked("eth_getStorageAt(address,bytes32)"));
boolStorage[keccak256(abi.encodePacked("enableRequestSelector", sel))] = true;
emit EnabledAsyncRequestSelector(sel, true);

sel = keccak256(abi.encodePacked("eth_getTransactionByHash(bytes32)"));
boolStorage[keccak256(abi.encodePacked("enableRequestSelector", sel))] = true;
emit EnabledAsyncRequestSelector(sel, true);

sel = keccak256(abi.encodePacked("eth_getTransactionReceipt(bytes32)"));
boolStorage[keccak256(abi.encodePacked("enableRequestSelector", sel))] = true;
emit EnabledAsyncRequestSelector(sel, true);

boolStorage[upgradeStorage] = true;
}
}

0 comments on commit e672562

Please sign in to comment.