Skip to content

Commit

Permalink
Merge pull request #230 from 0xPolygonHermez/feat/origin-check-override
Browse files Browse the repository at this point in the history
Add possibility to override origin check for the native token on sovereign chains
  • Loading branch information
invocamanman committed Apr 19, 2024
2 parents 54f58c8 + b297fd5 commit 65f9481
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions contracts/v2/lib/PolygonRollupBaseEtrog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -302,29 +302,8 @@ abstract contract PolygonRollupBaseEtrog is
string memory sequencerURL,
string memory _networkName
) external virtual onlyRollupManager initializer {
bytes memory gasTokenMetadata;
bytes memory gasTokenMetadata = _verifyOrigin(_gasTokenAddress);

if (_gasTokenAddress != address(0)) {
// Ask for token metadata, the same way is enconded in the bridge
// Note that this function will revert if the token is not in this network
// Note that this could be a possible reentrant call, but cannot make changes on the state since are static call
gasTokenMetadata = bridgeAddress.getTokenMetadata(_gasTokenAddress);

// Check gas token address on the bridge
(
uint32 originWrappedNetwork,
address originWrappedAddress
) = bridgeAddress.wrappedTokenToTokenInfo(_gasTokenAddress);

if (originWrappedNetwork != 0) {
// It's a wrapped token, get the wrapped parameters
gasTokenAddress = originWrappedAddress;
gasTokenNetwork = originWrappedNetwork;
} else {
// gasTokenNetwork will be mainnet, for instance 0
gasTokenAddress = _gasTokenAddress;
}
}
// Sequence transaction to initilize the bridge

// Calculate transaction to initialize the bridge
Expand Down Expand Up @@ -948,4 +927,30 @@ abstract contract PolygonRollupBaseEtrog is

return transaction;
}

function _verifyOrigin(
address _gasTokenAddress
) internal virtual returns (bytes memory gasTokenMetadata) {
if (_gasTokenAddress != address(0)) {
// Ask for token metadata, the same way is enconded in the bridge
// Note that this function will revert if the token is not in this network
// Note that this could be a possible reentrant call, but cannot make changes on the state since are static call
gasTokenMetadata = bridgeAddress.getTokenMetadata(_gasTokenAddress);

// Check gas token address on the bridge
(
uint32 originWrappedNetwork,
address originWrappedAddress
) = bridgeAddress.wrappedTokenToTokenInfo(_gasTokenAddress);

if (originWrappedNetwork != 0) {
// It's a wrapped token, get the wrapped parameters
gasTokenAddress = originWrappedAddress;
gasTokenNetwork = originWrappedNetwork;
} else {
// gasTokenNetwork will be mainnet, for instance 0
gasTokenAddress = _gasTokenAddress;
}
}
}
}

0 comments on commit 65f9481

Please sign in to comment.