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: rateLimiterConfig mapping of localToRemoteTokens to take bytes instead of bytes32 #1207

Merged
merged 24 commits into from
Aug 14, 2024

Conversation

defistar
Copy link
Contributor

@defistar defistar commented Jul 17, 2024

Description:

rateLimiterConfig mapping of localToRemoteTokens to take bytes instead of bytes32

Details

  • In the MultiAggregateRateLimiter contract, the the following mapping might be simplifiable to
  • (uint64 remoteChainSelector -> address token) ,
  • since it is only used as an isEnabled check (i.e. the (address token -> bytes32 remoteToken) is never used on-chain)
  • mapping being necessary off-chain, we need to convert the (address -> bytes32) mapping to (address -> bytes) to be consistent with using bytes for all family-agnostic addresses
mapping(uint64 remoteChainSelector => EnumerableMapAddresses.AddressToBytes32Map tokensLocalToRemote) internal
    s_rateLimitedTokensLocalToRemote;

this has to been changed to

  mapping(uint64 remoteChainSelector => EnumerableMapAddresses.AddressToBytesMap tokensLocalToRemote) internal
    s_rateLimitedTokensLocalToRemote;

Change List:

  1. New solidity library EnumerableMapBytes32 which contains Bytes32ToBytes Mapping and enumerate it
  2. EnumerableMapAddresses.sol library has added support for the new library cherrypicked from chainlink repo EnumerableMapBytes32
  3. MultiAggregateRateLimiter with mapping for remoteSelector -> localTokenAddress -> remoteTokenAddress is updated to contain remoteTokenAddress as bytes instead of bytes32

@defistar defistar changed the title feat: CCIP-2465 rateLimiterConfig mapping of localToremoteTokens upda… feat: rateLimiterConfig mapping of localToremoteTokens to take bytes instead of bytes32 Jul 17, 2024
Copy link
Contributor

github-actions bot commented Jul 17, 2024

LCOV of commit f9586b3 during Solidity Foundry #7226

Summary coverage rate:
  lines......: 98.7% (1882 of 1907 lines)
  functions..: 96.4% (347 of 360 functions)
  branches...: 90.6% (797 of 880 branches)

Files changed coverage rate: n/a

@defistar defistar self-assigned this Jul 17, 2024
@defistar defistar added the looking for review This needs more reviewers label Jul 17, 2024
@defistar defistar marked this pull request as ready for review July 17, 2024 19:33
@defistar defistar requested review from makramkd, RayXpub and a team as code owners July 17, 2024 19:34
@defistar defistar changed the title feat: rateLimiterConfig mapping of localToremoteTokens to take bytes instead of bytes32 feat: rateLimiterConfig mapping of localToRemoteTokens to take bytes instead of bytes32 Jul 18, 2024
@@ -482,14 +482,14 @@ contract MultiAggregateRateLimiter_updateRateLimitTokens is MultiAggregateRateLi
remoteChainSelector: CHAIN_SELECTOR_1,
localToken: s_destTokens[0]
}),
remoteToken: bytes32(bytes20(s_sourceTokens[0]))
remoteToken: abi.encodePacked(s_sourceTokens[0])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: we use abi.encode for addresses -> bytes conversion instead of encodePacked - e.g. see https://github.com/smartcontractkit/ccip/blob/ccip-develop/contracts/src/v0.8/ccip/onRamp/EVM2EVMOnRamp.sol#L371

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

contracts/src/v0.8/shared/enumerable/CCIPEnumerableMap.sol Outdated Show resolved Hide resolved
contracts/src/v0.8/ccip/MultiAggregateRateLimiter.sol Outdated Show resolved Hide resolved
@@ -1,12 +1,15 @@
// SPDX-License-Identifier: MIT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should cherry-pick the commit from chainlink to make this lib in sync:

  1. Add chainlink remote via: git remote add
  2. git cherry-pick <commit-id>

This looks like it's missing the src/v0.8/shared/test/enumerable files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

contracts/src/v0.8/ccip/MultiAggregateRateLimiter.sol Outdated Show resolved Hide resolved
@@ -918,7 +915,7 @@ contract MultiAggregateRateLimiter_onOutboundMessage is MultiAggregateRateLimite
remoteChainSelector: CHAIN_SELECTOR_1,
localToken: s_sourceTokens[i]
}),
remoteToken: bytes32(bytes20(s_destTokenBySourceToken[s_sourceTokens[i]]))
remoteToken: abi.encodePacked(bytes20(s_destTokenBySourceToken[s_sourceTokens[i]]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
remoteToken: abi.encodePacked(bytes20(s_destTokenBySourceToken[s_sourceTokens[i]]))
remoteToken: abi.encode(bytes20(s_destTokenBySourceToken[s_sourceTokens[i]]))

defistar and others added 2 commits August 14, 2024 09:38
* feat: CCIP-2465 enumerableMap for addressToBytes Mapping

* fix: CCIP-2465 prettier write for new library contracts

* fix: CCIP-2465 gas-snapshot updated and changeset added for new library

* fix: CCIP-2465 gassnapshot corrections for EnumerableAddresses
@cl-sonarqube-production
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Comment on lines 5 to +6
import {EnumerableMap} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/structs/EnumerableMap.sol";
import {EnumerableMapBytes32} from "./EnumerableMapBytes32.sol";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: probably not for this PR but now that we have OZ v5 we might want to update this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it will add a note for this one

@defistar defistar merged commit deec42f into ccip-develop Aug 14, 2024
109 checks passed
@defistar defistar deleted the feature/CCIP-2465-rateLimiter-tokenMapping branch August 14, 2024 08:40
dhaidashenko pushed a commit that referenced this pull request Sep 2, 2024
…instead of bytes32 (#1207)

rateLimiterConfig mapping of localToRemoteTokens to take bytes instead
of bytes32

- In the MultiAggregateRateLimiter contract, the the following mapping
might be simplifiable to
- (uint64 remoteChainSelector -> address token) ,
- since it is only used as an isEnabled check (i.e. the (address token
-> bytes32 remoteToken) is never used on-chain)
- mapping being necessary off-chain, we need to convert the (address ->
bytes32) mapping to (address -> bytes) to be consistent with using bytes
for all family-agnostic addresses

```js
mapping(uint64 remoteChainSelector => EnumerableMapAddresses.AddressToBytes32Map tokensLocalToRemote) internal
    s_rateLimitedTokensLocalToRemote;
```

this has to been changed to

```js
  mapping(uint64 remoteChainSelector => EnumerableMapAddresses.AddressToBytesMap tokensLocalToRemote) internal
    s_rateLimitedTokensLocalToRemote;
```

1. New solidity library `EnumerableMapBytes32` which contains
`Bytes32ToBytes` Mapping and enumerate it
2. `EnumerableMapAddresses.sol` library has added support for the new
library cherrypicked from chainlink repo `EnumerableMapBytes32`
3. `MultiAggregateRateLimiter` with mapping for remoteSelector ->
localTokenAddress -> remoteTokenAddress is updated to contain
remoteTokenAddress as `bytes` instead of `bytes32`

---------

Co-authored-by: app-token-issuer-infra-releng[bot] <120227048+app-token-issuer-infra-releng[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
looking for review This needs more reviewers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants