Skip to content

Commit

Permalink
feat: bump to gmp sdk v5.5 (#255)
Browse files Browse the repository at this point in the history
* feat: bump to gmp sdk v5.5

* lint and tests

* fix flatten script
  • Loading branch information
milapsheth authored Oct 19, 2023
1 parent 6c8816b commit 78fde45
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 77 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"tabWidth": 4,
"useTabs": false,
"bracketSpacing": true,
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
Expand Down
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"no-inline-assembly": "off",
"no-empty-blocks": "off",
"avoid-low-level-calls": "off",
"not-rely-on-time": "off"
"not-rely-on-time": "off",
"immutable-vars-naming": "off"
}
}
2 changes: 2 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
contracts/ERC20Permit.sol
contracts/interfaces/IERC20Permit.sol
contracts/BurnableMintableCappedERC20.sol
contracts/gas-service/AxelarGasServiceProxy.sol
43 changes: 6 additions & 37 deletions contracts/AxelarGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
pragma solidity ^0.8.0;

import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';
import { IImplementation } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IImplementation.sol';
import { IContractIdentifier } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IContractIdentifier.sol';
import { IGovernable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IGovernable.sol';
import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';
import { SafeTokenCall, SafeTokenTransfer, SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/SafeTransfer.sol';
import { ContractAddress } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/ContractAddress.sol';
import { Implementation } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Implementation.sol';

import { IAxelarGateway } from './interfaces/IAxelarGateway.sol';
import { IAxelarAuth } from './interfaces/IAxelarAuth.sol';
import { IBurnableMintableCappedERC20 } from './interfaces/IBurnableMintableCappedERC20.sol';
import { ITokenDeployer } from './interfaces/ITokenDeployer.sol';
Expand All @@ -25,16 +26,14 @@ import { EternalStorage } from './EternalStorage.sol';
* The contract is managed via the decentralized governance mechanism on the Axelar network.
* @dev EternalStorage is used to simplify storage for upgradability, and InterchainGovernance module is used for governance.
*/
contract AxelarGateway is IAxelarGateway, IGovernable, IContractIdentifier, EternalStorage {
contract AxelarGateway is IAxelarGateway, Implementation, EternalStorage {
using SafeTokenCall for IERC20;
using SafeTokenTransfer for IERC20;
using SafeTokenTransferFrom for IERC20;
using ContractAddress for address;

error InvalidImplementation();

event ContractCallExecuted(bytes32 indexed commandId);

enum TokenType {
InternalBurnable,
InternalBurnableFrom,
Expand Down Expand Up @@ -79,7 +78,6 @@ contract AxelarGateway is IAxelarGateway, IGovernable, IContractIdentifier, Eter

address public immutable authModule;
address public immutable tokenDeployer;
address internal immutable implementationAddress = address(this);

/**
* @notice Constructs the AxelarGateway contract.
Expand Down Expand Up @@ -121,14 +119,6 @@ contract AxelarGateway is IAxelarGateway, IGovernable, IContractIdentifier, Eter
_;
}

/**
* @notice Modifier to ensure that a function can only be called by the proxy
*/
modifier onlyProxy() {
if (address(this) == implementationAddress) revert NotProxy();
_;
}

/******************\
|* Public Methods *|
\******************/
Expand Down Expand Up @@ -333,27 +323,6 @@ contract AxelarGateway is IAxelarGateway, IGovernable, IContractIdentifier, Eter
return false;
}

/**
* @dev Deprecated.
*/
function adminEpoch() external pure override returns (uint256) {
return 0;
}

/**
* @dev Deprecated.
*/
function adminThreshold(uint256) external pure override returns (uint256) {
return 0;
}

/**
* @dev Deprecated.
*/
function admins(uint256) external pure override returns (address[] memory) {
return new address[](0);
}

/**
* @notice Gets the address of the gateway implementation contract.
* @return address The address of the gateway implementation.
Expand Down Expand Up @@ -463,7 +432,7 @@ contract AxelarGateway is IAxelarGateway, IGovernable, IContractIdentifier, Eter

if (setupParams.length != 0) {
// slither-disable-next-line controlled-delegatecall
(bool success, ) = newImplementation.delegatecall(abi.encodeWithSelector(IAxelarGateway.setup.selector, setupParams));
(bool success, ) = newImplementation.delegatecall(abi.encodeWithSelector(IImplementation.setup.selector, setupParams));

if (!success) revert SetupFailed();
}
Expand All @@ -479,7 +448,7 @@ contract AxelarGateway is IAxelarGateway, IGovernable, IContractIdentifier, Eter
* @param params The encoded parameters containing the governance and mint limiter addresses, as well as the new operator data.
* @dev Not publicly accessible as it's overshadowed in the proxy.
*/
function setup(bytes calldata params) external override onlyProxy {
function setup(bytes calldata params) external override(IImplementation, Implementation) onlyProxy {
(address governance_, address mintLimiter_, bytes memory newOperatorsData) = abi.decode(params, (address, address, bytes));

if (governance_ != address(0)) _transferGovernance(governance_);
Expand Down
10 changes: 7 additions & 3 deletions contracts/test/TestAxelarGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ pragma solidity ^0.8.0;
import { AxelarGateway } from '../AxelarGateway.sol';

contract TestAxelarGateway is AxelarGateway {
string public name = 'Test Axelar Gateway'; // Dummy var for a different bytecode

error Invalid();

constructor(address authModule_, address tokenDeployer_) AxelarGateway(authModule_, tokenDeployer_) {
require(KEY_IMPLEMENTATION == bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1), 'invalid constant');
require(KEY_GOVERNANCE == bytes32(uint256(keccak256('governance')) - 1), 'invalid constant');
require(KEY_MINT_LIMITER == bytes32(uint256(keccak256('mint-limiter')) - 1), 'invalid constant');
if (KEY_IMPLEMENTATION != bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)) revert Invalid();
if (KEY_GOVERNANCE != bytes32(uint256(keccak256('governance')) - 1)) revert Invalid();
if (KEY_MINT_LIMITER != bytes32(uint256(keccak256('mint-limiter')) - 1)) revert Invalid();
}
}
4 changes: 3 additions & 1 deletion contracts/test/TestNonStandardERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { MintableCappedERC20 } from '../MintableCappedERC20.sol';
contract TestNonStandardERC20 is MintableCappedERC20 {
bool public shouldFailTransfer;

error Invalid();

constructor(
string memory name,
string memory symbol,
Expand All @@ -26,6 +28,6 @@ contract TestNonStandardERC20 is MintableCappedERC20 {
if (shouldFailTransfer) {
return false;
}
revert('Transfer not supported');
revert Invalid();
}
}
4 changes: 3 additions & 1 deletion contracts/test/TestWeth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { MintableCappedERC20 } from '../MintableCappedERC20.sol';
import { IWETH9 } from '../interfaces/IWETH9.sol';

contract TestWeth is MintableCappedERC20, IWETH9 {
error Invalid();

constructor(
string memory name,
string memory symbol,
Expand All @@ -18,7 +20,7 @@ contract TestWeth is MintableCappedERC20, IWETH9 {
}

function withdraw(uint256 amount) external {
require(balanceOf[msg.sender] >= amount, 'Insufficient balance');
if (balanceOf[msg.sender] < amount) revert Invalid();
balanceOf[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"homepage": "https://github.com/axelarnetwork/axelar-cgp-solidity#readme",
"dependencies": {
"@axelar-network/axelar-gmp-sdk-solidity": "^5.4.0"
"@axelar-network/axelar-gmp-sdk-solidity": "5.5.2"
},
"devDependencies": {
"@axelar-network/axelar-chains-config": "^0.1.2",
Expand Down
18 changes: 12 additions & 6 deletions scripts/flatten-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rm -rf "$OUTPUT"
mkdir -p "$OUTPUT"

# Get compiler version, expected format ".*version: 'x.y.z',"
version=$(grep 'version' ./hardhat.config.js | sed "s/version: '//" | sed "s/',$//g")
version=$(grep 'version' ./hardhat.config.js | sed "s/ *version: '//" | sed "s/',$//g")

# Flatten files
find "$SOURCE" -name '*.sol' -print | while read -r file; do
Expand All @@ -28,21 +28,27 @@ find "$SOURCE" -name '*.sol' -print | while read -r file; do
path="${file#${SOURCE}/}"
mkdir -p "$OUTPUT"/"$(dirname "${path}")"

# Flatten contract, and remove hardhat comment at the top
hardhat flatten "$file" | tail -n +2 >"$OUTPUT/$path"
# Flatten contract
hardhat flatten "$file" > flat.sol

# Remove duplicate SPDX identifiers and pragmas that the explorers don't like
text=$(grep -vE "// SPDX.*" "$OUTPUT/$path" | grep -vE "pragma solidity .*")
# Remove hardhat comment at the top
tail -n+3 flat.sol > "$OUTPUT/$path"

# # Remove duplicate SPDX identifiers and pragmas that the explorers don't like
# text=$(grep -vE "// SPDX.*" "$OUTPUT/$path" | grep -vE "pragma solidity .*")
text=$(grep -vE "pragma solidity .*" "$OUTPUT/$path" | grep -vE "// Original license:.*")

echo "// Source: $SOURCE/$path\n\n" > "$OUTPUT/$path"
echo "// SPDX-License-Identifier: MIT\n\n" >> "$OUTPUT/$path"
echo "pragma solidity $version;\n\n" >> "$OUTPUT/$path"
printf "%s" "$text" >> "$OUTPUT/$path"

# Prettify source (in particular, remove extra newlines)
prettier --write "$OUTPUT/$path"
done

# Delete temp file
rm -f flat.sol

if [ -z "$(ls -A $OUTPUT)" ]; then
echo "No contracts from source $SOURCE/ were found at $OUTPUT"
exit 1
Expand Down
26 changes: 3 additions & 23 deletions test/AxelarGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ describe('AxelarGateway', () => {
const implementationBytecodeHash = keccak256(implementationBytecode);

const expected = {
istanbul: '0xc3c80d3edf4cf7d0d94f6b0b2fa75f4f670ef96031438185f63d55da2c86cdea',
berlin: '0x0b693fc1a0da717457cfd5169bc869348da3e81f246246ae53dd073ff23fa9cd',
london: '0x695238dc27d58213d8bd8bc8afaac66debd26076f8ef2846e31fbd5d664e4e11',
istanbul: '0xb95e207998541b443f7653b3fb7158b4fdd04308343381e56f824668323029a8',
berlin: '0x527ccc01bb1072d7af437ae3ed50e6e5d47d347181e8ff51b49ee3199d052dce',
london: '0xcc7160c968bc78c8be295b69fce8725ca9813669fc96bf460c5c5c1e13b2bf3d',
}[getEVMVersion()];

expect(implementationBytecodeHash).to.be.equal(expected);
Expand Down Expand Up @@ -2216,26 +2216,6 @@ describe('AxelarGateway', () => {
expect(await gateway.allTokensFrozen()).to.be.false;
});

it('should return correct value for adminEpoch', async () => {
expect(await gateway.adminEpoch()).to.eq(0);
});

it('should return correct value for adminThreshold', async () => {
let epoch = 1;
expect(await gateway.adminThreshold(epoch)).to.eq(0);

epoch = getRandomInt(Number.MAX_SAFE_INTEGER);
expect(await gateway.adminThreshold(epoch)).to.eq(0);
});

it('should return correct value for admins', async () => {
let epoch = 1;
expect(await gateway.admins(epoch)).to.deep.equal([]);

epoch = getRandomInt(Number.MAX_SAFE_INTEGER);
expect(await gateway.admins(epoch)).to.deep.equal([]);
});

it('should return correct value for tokenFrozen', async () => {
const token = 'Token';
expect(await gateway.tokenFrozen(token)).to.be.false;
Expand Down

0 comments on commit 78fde45

Please sign in to comment.