Skip to content

Commit

Permalink
feat: address to bytes32 contract changes (#650)
Browse files Browse the repository at this point in the history
* feat: add address to bytes32 contract changes

Signed-off-by: Pablo Maldonado <[email protected]>

* refactor: remove todos

Signed-off-by: Pablo Maldonado <[email protected]>

* refactor: imports

Signed-off-by: Pablo Maldonado <[email protected]>

* Update contracts/SpokePool.sol

Co-authored-by: Reinis Martinsons <[email protected]>

* feat: bytes 32 comparisons

Signed-off-by: Pablo Maldonado <[email protected]>

* refactor: format code

Signed-off-by: Pablo Maldonado <[email protected]>

* fix: tests

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: bytes 32 check

Signed-off-by: Pablo Maldonado <[email protected]>

* fix: ts

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: reuse lib in cctp adapter

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: _preExecuteLeafHook

Signed-off-by: Pablo Maldonado <[email protected]>

* refactor: comments

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: _verifyUpdateV3DepositMessage

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: backward compatibility

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: backwards compatibility tests

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: change comparison casting address bytes32

Signed-off-by: Pablo Maldonado <[email protected]>

* fix: test

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: merkle tree leaf to bytes32

Signed-off-by: Pablo Maldonado <[email protected]>

* test: leaf type update fixes

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: remove helper

Signed-off-by: Pablo Maldonado <[email protected]>

---------

Signed-off-by: Pablo Maldonado <[email protected]>
Co-authored-by: Reinis Martinsons <[email protected]>
  • Loading branch information
md0x and Reinis-FRP authored Oct 21, 2024
1 parent 9201079 commit 5a54ddb
Show file tree
Hide file tree
Showing 34 changed files with 1,005 additions and 529 deletions.
5 changes: 3 additions & 2 deletions contracts/Linea_SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
*/
contract Linea_SpokePool is SpokePool {
using SafeERC20 for IERC20;
using AddressToBytes32 for address;

/**
* @notice Address of Linea's Canonical Message Service contract on L2.
Expand Down Expand Up @@ -122,8 +123,8 @@ contract Linea_SpokePool is SpokePool {
* @notice Wraps any ETH into WETH before executing base function. This is necessary because SpokePool receives
* ETH over the canonical token bridge instead of WETH.
*/
function _preExecuteLeafHook(address l2TokenAddress) internal override {
if (l2TokenAddress == address(wrappedNativeToken)) _depositEthToWeth();
function _preExecuteLeafHook(bytes32 l2TokenAddress) internal override {
if (l2TokenAddress == address(wrappedNativeToken).toBytes32()) _depositEthToWeth();
}

// Wrap any ETH owned by this contract so we can send expected L2 token to recipient. This is necessary because
Expand Down
6 changes: 4 additions & 2 deletions contracts/Ovm_SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ interface IL2ERC20Bridge {
*/
contract Ovm_SpokePool is SpokePool, CircleCCTPAdapter {
using SafeERC20 for IERC20;
using AddressToBytes32 for address;
// "l1Gas" parameter used in call to bridge tokens from this contract back to L1 via IL2ERC20Bridge. Currently
// unused by bridge but included for future compatibility.

uint32 public l1Gas;

// ETH is an ERC20 on OVM.
Expand Down Expand Up @@ -133,8 +135,8 @@ contract Ovm_SpokePool is SpokePool, CircleCCTPAdapter {
* @notice Wraps any ETH into WETH before executing leaves. This is necessary because SpokePool receives
* ETH over the canonical token bridge instead of WETH.
*/
function _preExecuteLeafHook(address l2TokenAddress) internal override {
if (l2TokenAddress == address(wrappedNativeToken)) _depositEthToWeth();
function _preExecuteLeafHook(bytes32 l2TokenAddress) internal override {
if (l2TokenAddress == address(wrappedNativeToken).toBytes32()) _depositEthToWeth();
}

// Wrap any ETH owned by this contract so we can send expected L2 token to recipient. This is necessary because
Expand Down
7 changes: 4 additions & 3 deletions contracts/PolygonZkEVM_SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ interface IBridgeMessageReceiver {
*/
contract PolygonZkEVM_SpokePool is SpokePool, IBridgeMessageReceiver {
using SafeERC20 for IERC20;

using AddressToBytes32 for address;
// Address of Polygon zkEVM's Canonical Bridge on L2.

IPolygonZkEVMBridge public l2PolygonZkEVMBridge;

// Polygon zkEVM's internal network id for L1.
Expand Down Expand Up @@ -157,8 +158,8 @@ contract PolygonZkEVM_SpokePool is SpokePool, IBridgeMessageReceiver {
* @notice Wraps any ETH into WETH before executing base function. This is necessary because SpokePool receives
* ETH over the canonical token bridge instead of WETH.
*/
function _preExecuteLeafHook(address l2TokenAddress) internal override {
if (l2TokenAddress == address(wrappedNativeToken)) _depositEthToWeth();
function _preExecuteLeafHook(bytes32 l2TokenAddress) internal override {
if (l2TokenAddress == address(wrappedNativeToken).toBytes32()) _depositEthToWeth();
}

// Wrap any ETH owned by this contract so we can send expected L2 token to recipient. This is necessary because
Expand Down
7 changes: 3 additions & 4 deletions contracts/Polygon_SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ contract Polygon_SpokePool is IFxMessageProcessor, SpokePool, CircleCCTPAdapter
* @param data ABI encoded function call to execute on this contract.
*/
function processMessageFromRoot(
uint256, /*stateId*/
uint256,
/*stateId*/
address rootMessageSender,
bytes calldata data
) public validateInternalCalls {
Expand Down Expand Up @@ -203,7 +204,6 @@ contract Polygon_SpokePool is IFxMessageProcessor, SpokePool, CircleCCTPAdapter
* whereby someone batches this call with a bunch of other calls and produces a very large L2 burn transaction.
* This might make the L2 -> L1 message fail due to exceeding the L1 calldata limit.
*/

function executeRelayerRefundLeaf(
uint32 rootBundleId,
SpokePoolInterface.RelayerRefundLeaf memory relayerRefundLeaf,
Expand All @@ -220,7 +220,6 @@ contract Polygon_SpokePool is IFxMessageProcessor, SpokePool, CircleCCTPAdapter
/**************************************
* INTERNAL FUNCTIONS *
**************************************/

function _setFxChild(address _fxChild) internal {
//slither-disable-next-line missing-zero-check
fxChild = _fxChild;
Expand All @@ -232,7 +231,7 @@ contract Polygon_SpokePool is IFxMessageProcessor, SpokePool, CircleCCTPAdapter
emit SetPolygonTokenBridger(address(_polygonTokenBridger));
}

function _preExecuteLeafHook(address) internal override {
function _preExecuteLeafHook(bytes32) internal override {
// Wraps MATIC --> WMATIC before distributing tokens from this contract.
_wrap();
}
Expand Down
Loading

0 comments on commit 5a54ddb

Please sign in to comment.