Skip to content

Commit

Permalink
Add possibility to override origin check for the native token on sove…
Browse files Browse the repository at this point in the history
…reign chains
  • Loading branch information
gretzke committed Mar 28, 2024
1 parent 6bf2c00 commit 171129d
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions contracts/v2/lib/PolygonRollupBaseEtrog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,8 @@ abstract contract PolygonRollupBaseEtrog is
) external virtual onlyRollupManager initializer {
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);
_verifyOrigin(_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 +929,28 @@ abstract contract PolygonRollupBaseEtrog is

return transaction;
}

function _verifyOrigin(address _gasTokenAddress) internal virtual {
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 171129d

Please sign in to comment.