Skip to content

Commit

Permalink
Review fixes II
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Sep 17, 2024
1 parent 0dc632d commit d922a88
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 83 deletions.
6 changes: 6 additions & 0 deletions contracts/PolygonZkEVMGlobalExitRootL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ contract PolygonZkEVMGlobalExitRootL2 is IBasePolygonZkEVMGlobalExitRoot {
// PolygonZkEVM Bridge address
address public immutable bridgeAddress;

/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
*/
uint256[50] private _gap;

/**
* @param _bridgeAddress PolygonZkEVMBridge contract address
*/
Expand Down
72 changes: 40 additions & 32 deletions contracts/v2/PolygonZkEVMBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -319,36 +319,6 @@ contract PolygonZkEVMBridgeV2 is
}
}

/**
* @notice Burn tokens from wrapped token to execute the bridge
* note This function has been extracted to be able to override it by other contracts like Bridge2SovereignChain
* @param tokenWrapped Wrapped token to burnt
* @param amount Amount of tokens
*/
function _bridgeWrappedAsset(
TokenWrapped tokenWrapped,
uint256 amount
) internal virtual {
// Burn tokens
tokenWrapped.burn(msg.sender, amount);
}

/**
* @notice Mints tokens from wrapped token to proceed with the claim
* note This function has been extracted to be able to override it by other contracts like Bridge2SovereignChain
* @param tokenWrapped Wrapped token to mint
* @param destinationAddress Minted token receiver
* @param amount Amount of tokens
*/
function _claimWrappedAsset(
TokenWrapped tokenWrapped,
address destinationAddress,
uint256 amount
) internal virtual {
// Burn tokens
tokenWrapped.mint(destinationAddress, amount);
}

/**
* @notice Bridge message and send ETH value
* note User/UI must be aware of the existing/available networks when choosing the destination network
Expand Down Expand Up @@ -571,7 +541,11 @@ contract PolygonZkEVMBridgeV2 is
);

// Mint tokens for the destination address
_claimWrappedAsset(newWrappedToken, destinationAddress, amount);
_claimWrappedAsset(
newWrappedToken,
destinationAddress,
amount
);

// Create mappings
tokenInfoToWrappedToken[tokenInfoHash] = address(
Expand All @@ -590,7 +564,11 @@ contract PolygonZkEVMBridgeV2 is
);
} else {
// Use the existing wrapped erc20
_claimWrappedAsset(TokenWrapped(wrappedToken), destinationAddress, amount);
_claimWrappedAsset(
TokenWrapped(wrappedToken),
destinationAddress,
amount
);
}
}
}
Expand Down Expand Up @@ -927,6 +905,36 @@ contract PolygonZkEVMBridgeV2 is
globalExitRootManager.updateExitRoot(getRoot());
}

/**
* @notice Burn tokens from wrapped token to execute the bridge
* note This function has been extracted to be able to override it by other contracts like Bridge2SovereignChain
* @param tokenWrapped Wrapped token to burnt
* @param amount Amount of tokens
*/
function _bridgeWrappedAsset(
TokenWrapped tokenWrapped,
uint256 amount
) internal virtual {
// Burn tokens
tokenWrapped.burn(msg.sender, amount);
}

/**
* @notice Mints tokens from wrapped token to proceed with the claim
* note This function has been extracted to be able to override it by other contracts like Bridge2SovereignChain
* @param tokenWrapped Wrapped token to mint
* @param destinationAddress Minted token receiver
* @param amount Amount of tokens
*/
function _claimWrappedAsset(
TokenWrapped tokenWrapped,
address destinationAddress,
uint256 amount
) internal virtual {
// Burn tokens
tokenWrapped.mint(destinationAddress, amount);
}

/**
* @notice Function decode an index into a wordPos and bitPos
* @param index Index
Expand Down
8 changes: 1 addition & 7 deletions contracts/v2/PolygonZkEVMGlobalExitRootV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ contract PolygonZkEVMGlobalExitRootV2 is
// Store every l1InfoLeaf
mapping(uint32 leafCount => bytes32 l1InfoRoot) public l1InfoRootMap;

/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
*/
uint256[50] private _gap;

/**
* @dev Emitted when the global exit root is updated
*/
Expand Down Expand Up @@ -83,7 +77,7 @@ contract PolygonZkEVMGlobalExitRootV2 is
* @notice Update the exit root of one of the networks and the global exit root
* @param newRoot new exit tree root
*/
function updateExitRoot(bytes32 newRoot) external virtual {
function updateExitRoot(bytes32 newRoot) external {
// Store storage variables into temporal variables since will be used multiple times
bytes32 cacheLastRollupExitRoot;
bytes32 cacheLastMainnetExitRoot;
Expand Down
87 changes: 44 additions & 43 deletions contracts/v2/sovereignChains/BridgeL2SovereignChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,49 +76,6 @@ contract BridgeL2SovereignChain is
_;
}

/**
* @notice Burn tokens from wrapped token to execute the bridge
* note This function has been extracted to be able to override it by other contracts like Bridge2SovereignChain
* @param tokenWrapped Wrapped token to burnt
* @param amount Amount of tokens
*/
function _bridgeWrappedAsset(
TokenWrapped tokenWrapped,
uint256 amount
) internal override {
// The token is either (1) a correctly wrapped token from another network
// or (2) wrapped with custom contract from origin network
if (wrappedAddressIsNotMintable[address(tokenWrapped)]) {
// Don't use burn but transfer to bridge
IERC20Upgradeable(address(tokenWrapped)).safeTransferFrom(msg.sender, address(this), amount);
} else {
// Burn tokens
tokenWrapped.burn(msg.sender, amount);
}
}

/**
* @notice Mints tokens from wrapped token to proceed with the claim
* note This function has been extracted to be able to override it by other contracts like Bridge2SovereignChain
* @param tokenWrapped Wrapped token to mint
* @param destinationAddress Minted token receiver
* @param amount Amount of tokens
*/
function _claimWrappedAsset(
TokenWrapped tokenWrapped,
address destinationAddress,
uint256 amount
) internal override {
// If is not mintable transfer instead of mint
if (wrappedAddressIsNotMintable[address(tokenWrapped)]) {
// Transfer wETH
IERC20Upgradeable(address(tokenWrapped)).safeTransfer(destinationAddress, amount);
} else {
// Claim wETH
tokenWrapped.mint(destinationAddress, amount);
}
}

/**
* @notice Updated bridge manager address
* @param _bridgeManager Bridge manager address
Expand Down Expand Up @@ -209,4 +166,48 @@ contract BridgeL2SovereignChain is
WETHToken = TokenWrapped(sovereignWETHTokenAddress);
wrappedAddressIsNotMintable[sovereignWETHTokenAddress] = isNotMintable;
}


/**
* @notice Burn tokens from wrapped token to execute the bridge
* note This function has been extracted to be able to override it by other contracts like Bridge2SovereignChain
* @param tokenWrapped Wrapped token to burnt
* @param amount Amount of tokens
*/
function _bridgeWrappedAsset(
TokenWrapped tokenWrapped,
uint256 amount
) internal override {
// The token is either (1) a correctly wrapped token from another network
// or (2) wrapped with custom contract from origin network
if (wrappedAddressIsNotMintable[address(tokenWrapped)]) {
// Don't use burn but transfer to bridge
IERC20Upgradeable(address(tokenWrapped)).safeTransferFrom(msg.sender, address(this), amount);
} else {
// Burn tokens
tokenWrapped.burn(msg.sender, amount);
}
}

/**
* @notice Mints tokens from wrapped token to proceed with the claim
* note This function has been extracted to be able to override it by other contracts like Bridge2SovereignChain
* @param tokenWrapped Wrapped token to mint
* @param destinationAddress Minted token receiver
* @param amount Amount of tokens
*/
function _claimWrappedAsset(
TokenWrapped tokenWrapped,
address destinationAddress,
uint256 amount
) internal override {
// If is not mintable transfer instead of mint
if (wrappedAddressIsNotMintable[address(tokenWrapped)]) {
// Transfer wETH
IERC20Upgradeable(address(tokenWrapped)).safeTransfer(destinationAddress, amount);
} else {
// Claim wETH
tokenWrapped.mint(destinationAddress, amount);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0

pragma solidity 0.8.20;
import {PolygonAccessControlUpgradeable} from "../lib/PolygonAccessControlUpgradeable.sol";
import "../../PolygonZkEVMGlobalExitRootL2.sol";

/**
Expand Down

0 comments on commit d922a88

Please sign in to comment.