From 171129def23d958116b9496e6ebebe19cc4f0e90 Mon Sep 17 00:00:00 2001 From: gretzke Date: Thu, 28 Mar 2024 16:27:27 +0100 Subject: [PATCH 1/2] Add possibility to override origin check for the native token on sovereign chains --- contracts/v2/lib/PolygonRollupBaseEtrog.sol | 45 ++++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/contracts/v2/lib/PolygonRollupBaseEtrog.sol b/contracts/v2/lib/PolygonRollupBaseEtrog.sol index c4b03a890..03ae1028c 100644 --- a/contracts/v2/lib/PolygonRollupBaseEtrog.sol +++ b/contracts/v2/lib/PolygonRollupBaseEtrog.sol @@ -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 @@ -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; + } + } + } } From b297fd560743ab8153909de78a249c4b0a77a4e7 Mon Sep 17 00:00:00 2001 From: gretzke Date: Fri, 19 Apr 2024 15:59:38 +0200 Subject: [PATCH 2/2] compilation fix --- contracts/v2/lib/PolygonRollupBaseEtrog.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/v2/lib/PolygonRollupBaseEtrog.sol b/contracts/v2/lib/PolygonRollupBaseEtrog.sol index 03ae1028c..ce522c995 100644 --- a/contracts/v2/lib/PolygonRollupBaseEtrog.sol +++ b/contracts/v2/lib/PolygonRollupBaseEtrog.sol @@ -302,9 +302,7 @@ abstract contract PolygonRollupBaseEtrog is string memory sequencerURL, string memory _networkName ) external virtual onlyRollupManager initializer { - bytes memory gasTokenMetadata; - - _verifyOrigin(_gasTokenAddress); + bytes memory gasTokenMetadata = _verifyOrigin(_gasTokenAddress); // Sequence transaction to initilize the bridge @@ -930,7 +928,9 @@ abstract contract PolygonRollupBaseEtrog is return transaction; } - function _verifyOrigin(address _gasTokenAddress) internal virtual { + 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