Skip to content

Commit

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

Check failure on line 1 in contracts/helpers/AMBBridgeHelper.sol

View workflow job for this annotation

GitHub Actions / lint

Compiler version 0.7.6 does not satisfy the 0.4.24 semver requirement

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 r, bytes32 s, uint8 v) {
function unpackSignature(bytes memory _signature) internal pure returns (bytes32, bytes32, uint8) {
require(_signature.length == 65);
bytes32 r;
bytes32 s;
uint8 v;

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

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

Check warning on line 28 in contracts/helpers/AMBBridgeHelper.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state
IHomeBridge public AMBcontract;

Check warning on line 29 in contracts/helpers/AMBBridgeHelper.sol

View workflow job for this annotation

GitHub Actions / lint

Variable name must be in mixedCase

constructor(address _homeBridge) public {
constructor(address _homeBridge) {

Check warning on line 31 in contracts/helpers/AMBBridgeHelper.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility in function
owner = msg.sender;
ambBridge = IHomeBridge(_homeBridge);
AMBcontract = IHomeBridge(_homeBridge);
}

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

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

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

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

Check failure on line 6 in contracts/upgradeable_contracts/BridgeValidators.sol

View workflow job for this annotation

GitHub Actions / lint

Replace ⏎········uint256·_requiredSignatures,⏎········address[]·_initialValidators,⏎········address·_owner with uint256·_requiredSignatures,·address[]·_initialValidators,·address·_owner)
uint256 _requiredSignatures,
address[] _initialValidators,
address _owner
) external onlyRelevantSender returns (bool) {

Check failure on line 10 in contracts/upgradeable_contracts/BridgeValidators.sol

View workflow job for this annotation

GitHub Actions / lint

Replace ····)·external·onlyRelevantSender·returns·(bool) with ········external⏎········onlyRelevantSender⏎········returns·(bool)⏎···
require(!isInitialized());
_setOwner(_owner);
require(_owner != address(0));
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 {
_setOwner(newOwner);
require(newOwner != address(0));
setOwner(newOwner);
}

/**
* @dev Sets a new owner address
*/
function _setOwner(address newOwner) internal {
require(newOwner != address(0));
* @dev Sets a new owner address
*/
function setOwner(address newOwner) internal {
emit OwnershipTransferred(owner(), newOwner);
addressStorage[OWNER] = newOwner;
}
Expand Down
36 changes: 36 additions & 0 deletions contracts/upgradeable_contracts/arbitrary_message/HomeAMB.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,40 @@ 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 {

Check warning on line 23 in contracts/upgradeable_contracts/arbitrary_message/HomeAMB.sol

View workflow job for this annotation

GitHub Actions / lint

Function name must be in mixedCase
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 b5bed9b

Please sign in to comment.