Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Upgradable): improved contract id verification
Browse files Browse the repository at this point in the history
re1ro committed Nov 17, 2023
1 parent f6ecc77 commit 8fb6d07
Showing 5 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion contracts/test/utils/TestInterchainAddressTracker.sol
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ contract TestInterchainAddressTracker is InterchainAddressTracker, Ownable {
string[] memory trustedAddresses
) Ownable(msg.sender) {
_setChainName(chainName_);

if (_CHAIN_NAME_SLOT != bytes32(uint256(keccak256('interchain-address-tracker-chain-name')) - 1))
revert Invalid();

8 changes: 2 additions & 6 deletions contracts/upgradable/Implementation.sol
Original file line number Diff line number Diff line change
@@ -10,14 +10,10 @@ import { IImplementation } from '../interfaces/IImplementation.sol';
* @dev Derived contracts must implement the setup function.
*/
abstract contract Implementation is IImplementation {
address private immutable implementationAddress;

/**
* @dev Contract constructor that sets the implementation address to the address of this contract.
* @dev Sets the implementation address to the address of this contract.
*/
constructor() {
implementationAddress = address(this);
}
address private immutable implementationAddress = address(this);

/**
* @dev Modifier to require the caller to be the proxy contract.
2 changes: 1 addition & 1 deletion contracts/upgradable/Upgradable.sol
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ abstract contract Upgradable is Ownable, Implementation, IUpgradable {
bytes32 newImplementationCodeHash,
bytes calldata params
) external override onlyOwner {
if (IUpgradable(newImplementation).contractId() != IUpgradable(this).contractId())
if (IUpgradable(newImplementation).contractId() != IUpgradable(implementation()).contractId())
revert InvalidImplementation();

if (newImplementationCodeHash != newImplementation.codehash) revert InvalidCodeHash();
2 changes: 1 addition & 1 deletion contracts/utils/InterchainAddressTracker.sol
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ contract InterchainAddressTracker is IInterchainAddressTracker {

function _setChainName(string memory chainName_) internal {
StringStorage.set(_CHAIN_NAME_SLOT, chainName_);
}
}

/**
* @dev Gets the name of the chain this is deployed at
4 changes: 1 addition & 3 deletions test/utils/InterchainAddressTracker.js
Original file line number Diff line number Diff line change
@@ -6,9 +6,7 @@ const { expect } = chai;
const { deployContract } = require('../utils.js');

describe('InterchainAddressTracker', () => {
let ownerWallet,
otherWallet,
interchainAddressTracker;
let ownerWallet, otherWallet, interchainAddressTracker;

const otherRemoteAddress = 'any string as an address';
const otherChain = 'Other Name';

0 comments on commit 8fb6d07

Please sign in to comment.