Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: code4rena gas opts #105

Merged
merged 66 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
fbaded0
renamed folder and changed version
Foivos Jul 6, 2023
8a6d845
npmignore
Foivos Jul 6, 2023
607de5c
npmignore
Foivos Jul 6, 2023
52fc054
Merge remote-tracking branch 'origin/main' into feat/dist
Foivos Jul 6, 2023
f5b5f56
change version
Foivos Jul 6, 2023
4c5738d
using include pattern instead.
Foivos Jul 6, 2023
15e606b
Merge remote-tracking branch 'origin/main' into feat/dist0-1-1
Foivos Jul 6, 2023
d998f1b
Merge branch 'main' into feat/dist0-1-1
Foivos Jul 11, 2023
0548a6e
Fixed most of the things least auhority suggested.
Foivos Jul 11, 2023
8397b07
made lint happy
Foivos Jul 11, 2023
f2e5ea8
Apply suggestions from code review
milapsheth Jul 12, 2023
32ce490
fixed some bugs
Foivos Jul 19, 2023
80616c5
Merge remote-tracking branch 'origin/main' into feat/least-autority-f…
Foivos Jul 19, 2023
dc516fe
added events
Foivos Jul 19, 2023
d6fa384
rename set to transfer for distributor and operator
Foivos Jul 24, 2023
5cc8fbb
changed standardized token to always allow token managers to mint/bur…
Foivos Jul 24, 2023
ea255e0
using immutable storage for remoteAddressValidator address to save gas
Foivos Jul 24, 2023
09bf99a
Merge remote-tracking branch 'origin/main' into feat/gas-optimizations
Foivos Jul 24, 2023
650ca71
Added some recommended changes
Foivos Jul 26, 2023
c69e0a4
added milap's suggested changes
Foivos Jul 26, 2023
63a18e4
Merge remote-tracking branch 'origin/main' into feat/gas-optimizations
Foivos Jul 26, 2023
2993930
Fixed some names and some minor gas optimizations
Foivos Jul 26, 2023
9074ed1
prettier and lint
Foivos Jul 26, 2023
d3cb150
stash
Foivos Jul 27, 2023
53fe6fe
import .env in hardhat.config
Foivos Jul 27, 2023
7eb5207
trying to fix .env.example
Foivos Jul 27, 2023
bf603eb
Added some getters in IRemoteAddressValidator and removed useless che…
Foivos Jul 27, 2023
f1723c3
removed ternary operators
Foivos Jul 27, 2023
bc8ed59
made lint happy
Foivos Jul 27, 2023
7661e1f
Merge branch 'feat/gas-optimizations' into feat/use-create3-lib
Foivos Jul 27, 2023
4bf89db
made lint happy
Foivos Jul 27, 2023
512d126
Added a new token manager to handle fee on transfer and added some te…
Foivos Jul 27, 2023
9e43b1c
fixed the liquidity pool check.
Foivos Jul 28, 2023
ba29a2a
Merge remote-tracking branch 'origin/main' into feat/use-create3-lib
Foivos Jul 28, 2023
1e2aeb3
fix a duplication bug
Foivos Jul 28, 2023
6c62270
lint
Foivos Jul 28, 2023
30c1e53
added some more tests
Foivos Jul 28, 2023
51b70c1
Added more tests
Foivos Jul 28, 2023
6b3f5ed
Merge branch 'feat/use-create3-lib' into feat/fee-on-transfer-separate
Foivos Jul 28, 2023
3e6d85f
Added proper re-entrancy protection for fee on transfer token managers.
Foivos Jul 28, 2023
d4075b8
change to tx.origin for refunds
Foivos Jul 28, 2023
5d9d8ce
Added support for more kinds of addresses.
Foivos Jul 28, 2023
1b35cbf
some minor gas opts
Foivos Jul 28, 2023
412dce9
some more gas optimizations.
Foivos Jul 28, 2023
0a8519f
Added a getter for chain name to the remote address validator.
Foivos Jul 28, 2023
959e495
moved the tokenManager getter functionality to a separate contract wh…
Foivos Jul 28, 2023
0d09703
made lint happy
Foivos Jul 28, 2023
2e44518
Removed tokenManagerGetter and put params into tokenManagers
Foivos Jul 28, 2023
6027ffe
Added separate tokenManager interfaces
Foivos Jul 28, 2023
04041d1
addressed ackeeblockchains's 3.0 report
Foivos Aug 23, 2023
6ee5d06
prettier
Foivos Aug 23, 2023
5acf4a8
added interchain transfer methods to the service and unified receivin…
Foivos Aug 28, 2023
244ff61
made lint happy
Foivos Aug 28, 2023
4e56576
rename sendToken to interchainTransfer
Foivos Aug 29, 2023
a8dc8a4
changed sendToken everywhere
Foivos Aug 29, 2023
b210316
changed from uint256.max to a const
Foivos Aug 30, 2023
2f5adac
change setting to zero to delete for storage slots.
Foivos Sep 4, 2023
af4766a
rearange storage variables to save a bit of gas.
Foivos Sep 4, 2023
634581c
Removed unecesairy casts
Foivos Sep 4, 2023
141648b
made as many event params inexed as possible
Foivos Sep 4, 2023
602d531
Removed unused imports
Foivos Sep 4, 2023
5cf5ea5
Merge branch 'main' into feat/move-views-out-of-serivce
re1ro Sep 27, 2023
ab32389
Merge branch 'feat/move-views-out-of-serivce' into feat/ackee-3.0
re1ro Sep 27, 2023
8a21176
Merge branch 'feat/ackee-3.0' into feat/interchain-transsfer-everywhere
re1ro Sep 27, 2023
ac6e9cf
Merge branch 'feat/interchain-transsfer-everywhere' into feat/code4re…
re1ro Sep 27, 2023
81c9934
Merge remote-tracking branch 'origin/main' into feat/code4rena-gas-opts
Foivos Oct 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pragma solidity ^0.8.0;

import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';
import { IAxelarGasService } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol';
import { AxelarExecutable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol';
import { SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/SafeTransfer.sol';
Expand Down
2 changes: 1 addition & 1 deletion contracts/interchain-token/InterchainToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ abstract contract InterchainToken is IInterchainToken, ERC20 {
) external payable {
uint256 _allowance = allowance[sender][msg.sender];

if (_allowance != type(uint256).max) {
if (_allowance != UINT256_MAX) {
_approve(sender, msg.sender, _allowance - amount);
}

Expand Down
12 changes: 5 additions & 7 deletions contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

pragma solidity ^0.8.0;

import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';
import { IAxelarExecutable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarExecutable.sol';

import { IExpressCallHandler } from './IExpressCallHandler.sol';
import { ITokenManagerDeployer } from './ITokenManagerDeployer.sol';
import { ITokenManagerType } from './ITokenManagerType.sol';
import { IPausable } from './IPausable.sol';
import { IMulticall } from './IMulticall.sol';
Expand All @@ -30,9 +28,9 @@ interface IInterchainTokenService is ITokenManagerType, IExpressCallHandler, IAx
error AlreadyExecuted(bytes32 commandId);
error InvalidExpressSelector();

event TokenSent(bytes32 tokenId, string destinationChain, bytes destinationAddress, uint256 indexed amount);
event TokenSent(bytes32 indexed tokenId, string destinationChain, bytes destinationAddress, uint256 indexed amount);
event TokenSentWithData(
bytes32 tokenId,
bytes32 indexed tokenId,
string destinationChain,
bytes destinationAddress,
uint256 indexed amount,
Expand Down Expand Up @@ -62,19 +60,19 @@ interface IInterchainTokenService is ITokenManagerType, IExpressCallHandler, IAx
uint8 tokenDecimals,
bytes distributor,
bytes mintTo,
uint256 mintAmount,
uint256 indexed mintAmount,
bytes operator,
string destinationChain,
uint256 indexed gasValue
);
event TokenManagerDeployed(bytes32 indexed tokenId, TokenManagerType indexed tokenManagerType, bytes params);
event StandardizedTokenDeployed(
bytes32 indexed tokenId,
address distributor,
address indexed distributor,
string name,
string symbol,
uint8 decimals,
uint256 mintAmount,
uint256 indexed mintAmount,
address mintTo
);
event CustomTokenIdClaimed(bytes32 indexed tokenId, address indexed deployer, bytes32 indexed salt);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IPausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pragma solidity ^0.8.0;
* if a pause condition is activated.
*/
interface IPausable {
event PausedSet(bool paused);
event PausedSet(bool indexed paused);

error Paused();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {
function removeTrustedAddress(string calldata sourceChain) external onlyOwner {
if (bytes(sourceChain).length == 0) revert ZeroStringLength();

remoteAddressHashes[sourceChain] = bytes32(0);
remoteAddresses[sourceChain] = '';
delete remoteAddressHashes[sourceChain];
delete remoteAddresses[sourceChain];

emit TrustedAddressRemoved(sourceChain);
}
Expand Down
7 changes: 4 additions & 3 deletions contracts/test/FeeOnTransferTokenTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IERC20BurnableMintable } from '../interfaces/IERC20BurnableMintable.sol
contract FeeOnTransferTokenTest is InterchainToken, Distributable, IERC20BurnableMintable {
ITokenManager public tokenManager_;
bool internal tokenManagerRequiresApproval_ = true;

string public name;
string public symbol;
uint8 public decimals;
Expand All @@ -36,9 +37,9 @@ contract FeeOnTransferTokenTest is InterchainToken, Distributable, IERC20Burnabl
if (!tokenManagerRequiresApproval_) return;
address tokenManagerAddress = address(tokenManager_);
uint256 allowance_ = allowance[sender][tokenManagerAddress];
if (allowance_ != type(uint256).max) {
if (allowance_ > type(uint256).max - amount) {
allowance_ = type(uint256).max - amount;
if (allowance_ != UINT256_MAX) {
if (allowance_ > UINT256_MAX - amount) {
allowance_ = UINT256_MAX - amount;
}

_approve(sender, tokenManagerAddress, allowance_ + amount);
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/InterchainTokenTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ contract InterchainTokenTest is InterchainToken, Distributable, IERC20BurnableMi
if (!tokenManagerRequiresApproval_) return;
address tokenManagerAddress = address(tokenManager_);
uint256 allowance_ = allowance[sender][tokenManagerAddress];
if (allowance_ != type(uint256).max) {
if (allowance_ > type(uint256).max - amount) {
allowance_ = type(uint256).max - amount;
if (allowance_ != UINT256_MAX) {
if (allowance_ > UINT256_MAX - amount) {
allowance_ = UINT256_MAX - amount;
}

_approve(sender, tokenManagerAddress, allowance_ + amount);
Expand Down
3 changes: 2 additions & 1 deletion contracts/token-implementations/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contract ERC20 is IERC20 {
mapping(address => mapping(address => uint256)) public override allowance;

uint256 public override totalSupply;
uint256 internal constant UINT256_MAX = 2 ** 256 - 1;

/**
* @dev See {IERC20-transfer}.
Expand Down Expand Up @@ -79,7 +80,7 @@ contract ERC20 is IERC20 {
function transferFrom(address sender, address recipient, uint256 amount) external virtual override returns (bool) {
uint256 _allowance = allowance[sender][msg.sender];

if (_allowance != type(uint256).max) {
if (_allowance != UINT256_MAX) {
_approve(sender, msg.sender, _allowance - amount);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/token-implementations/StandardizedToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import { Distributable } from '../utils/Distributable.sol';
contract StandardizedToken is IERC20BurnableMintable, InterchainToken, ERC20Permit, Implementation, Distributable {
using AddressBytesUtils for bytes;

address internal tokenManager_;
string public name;
string public symbol;
uint8 public decimals;
address internal tokenManager_;

bytes32 private constant CONTRACT_ID = keccak256('standardized-token');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
pragma solidity ^0.8.0;

import { TokenManager } from '../TokenManager.sol';
import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';
import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';

/**
* @title TokenManagerAddressStorage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ contract TokenManagerLiquidityPool is TokenManagerAddressStorage, NoReEntrancy {
*/
function _giveToken(address to, uint256 amount) internal override noReEntrancy returns (uint256) {
IERC20 token = IERC20(tokenAddress());
uint256 balance = IERC20(token).balanceOf(to);
uint256 balance = token.balanceOf(to);

SafeTokenTransferFrom.safeTransferFrom(token, liquidityPool(), to, amount);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract TokenManagerLockUnlockFee is TokenManagerAddressStorage, NoReEntrancy {
*/
function _giveToken(address to, uint256 amount) internal override noReEntrancy returns (uint256) {
IERC20 token = IERC20(tokenAddress());
uint256 balance = IERC20(token).balanceOf(to);
uint256 balance = token.balanceOf(to);

SafeTokenTransfer.safeTransfer(token, to, amount);

Expand Down
Loading