Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: upgradeable adapters #122

Merged
merged 12 commits into from
Jul 29, 2024

Conversation

0xDiscotech
Copy link
Contributor

🤖 Linear

Closes OPT-168

…pter

* feat: add initialize and authorize upgrade function on universal adapter

* refactor: update deployment flow on factory and l2 deploy contracts

* chore: update unit tests setup to deploy proxy and implementation
@0xDiscotech 0xDiscotech self-assigned this Jul 25, 2024
Copy link

linear bot commented Jul 25, 2024

OPT-168 Make adapters upgradeable (again)

Talked to circle and despite us following their process, they want the adapters to be upgradeable incase something related to their process was to ever change.

😞

@0xDiscotech 0xDiscotech changed the base branch from dev to audit/spearbit July 25, 2024 16:22
@@ -42,15 +42,13 @@ contract L1OpUSDCBridgeAdapter is IL1OpUSDCBridgeAdapter, OpUSDCBridgeAdapter {
* @param _usdc The address of the USDC Contract to be used by the adapter
* @param _messenger The address of the L1 messenger
* @param _linkedAdapter The address of the linked adapter
* @param _owner The address of the owner of the contract
* @dev The constructor is only used to initialize the OpUSDCBridgeAdapter immutable variables
*/
constructor(
address _usdc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure this contract inherits the UUPSUpgradeable from openzeppelin-upgradeable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or does it not need it because we inherit in the base contract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it is inherited on the base contract

@@ -30,7 +30,7 @@ contract L2OpUSDCBridgeAdapter is IL2OpUSDCBridgeAdapter, OpUSDCBridgeAdapter {
bytes4 internal constant _UPGRADE_TO_AND_CALL_SELECTOR = 0x4f1ef286;

/// @inheritdoc IL2OpUSDCBridgeAdapter
FallbackProxyAdmin public immutable FALLBACK_PROXY_ADMIN;
FallbackProxyAdmin public FALLBACK_PROXY_ADMIN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer immutable, just change it to fallback_proxy_admin, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it behaves as immutable, just that I need to set it on the initialize() function instead of on constructor. I added a note and the ignore flag.
Wdyt?

FALLBACK_PROXY_ADMIN = new FallbackProxyAdmin(_usdc);
}
address _linkedAdapter
) OpUSDCBridgeAdapter(_usdc, _messenger, _linkedAdapter) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be sure to add __gap variable to reserve slots for new implementations on all three contracts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint256[50] private __gap; seems enough, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea should be fine

@0xDiscotech 0xDiscotech marked this pull request as ready for review July 26, 2024 03:14
address _owner
) Ownable(_owner) EIP712('OpUSDCBridgeAdapter', '1.0.0') {
// solhint-disable-next-line no-unused-vars
constructor(address _usdc, address _messenger, address _linkedAdapter) EIP712('OpUSDCBridgeAdapter', '1.0.0') {
Copy link
Member

@hexshire hexshire Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice catch

* implementation contract
*/
function initialize(address _owner) public virtual initializer {
__Ownable_init(_owner);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* @notice Checks the caller is the owner to authorize the upgrade
*/
function _authorizeUpgrade(address) internal virtual override onlyOwner {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

@@ -1,17 +1,19 @@
pragma solidity ^0.8.25;

import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';
import {ERC1967Proxy} from '@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol';
import {IL1OpUSDCBridgeAdapter, L1OpUSDCBridgeAdapter} from 'contracts/L1OpUSDCBridgeAdapter.sol';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter

) OpUSDCBridgeAdapter(_usdc, _messenger, _linkedAdapter, _owner) {}
address _linkedAdapter
) OpUSDCBridgeAdapter(_usdc, _messenger, _linkedAdapter) {}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add the __gap to the L1 and L2 adapters as well, it will make maintanence should a chain op ever want to upgrade much easier

@0xDiscotech
Copy link
Contributor Author

0xDiscotech commented Jul 26, 2024

Deployments:

L1 factory: 0xC6570909811191DAfEd6a7775d6363662540F5E2

op:
  L1 Adapter: 0xfAf1Bb6E2f8007A51fBBA0AeFDE7631c175a1aBC
  L2 Factory: 0xa16243fF1BCB12b2627db3755FC0863D54a1bFD9
  L2 Adapter: 0x764057565403b23B5BC7FE920457870Df4348374

base:
  L1 Adapter: 0x9EC67f3F353a4B3123E93399725D4D1187Ab4A29
  L2 Factory: 0x4BA083dbf1Fd3e3c9b42BfF4F344e0dBeBb47337
  L2 Adapter: 0xD6Ebca002058c0E5d7Dcdf2ca6ca8a9C274ACA24

For OP

L1 Adapter owner:
cast call 0xfAf1Bb6E2f8007A51fBBA0AeFDE7631c175a1aBC 'owner()(address)' --rpc-url wss://ethereum-sepolia-rpc.publicnode.com -> 0x8421D6D2253d3f8e25586Aa6692b1Bf591da3779 ✅

L2 Adapter owner:
cast call 0x764057565403b23B5BC7FE920457870Df4348374 "owner()(address)" --rpc-url https://sepolia.optimism.io -> 0x8421D6D2253d3f8e25586Aa6692b1Bf591da3779 ✅

Fallback proxy admin:
cast call 0x764057565403b23B5BC7FE920457870Df4348374 "FALLBACK_PROXY_ADMIN()(address)" --rpc-url https://sepolia.optimism.io -> 0xA6abC0390c9aD135025b98a69d9764FBEdE7D651

USDC:
cast call 0x764057565403b23B5BC7FE920457870Df4348374 "USDC()(address)" --rpc-url https://sepolia.optimism.io -> 0x77ac613B82b30fAc7d545E2D62723c4ac3E4d5c4 ✅

USDC owner:
cast call 0x764057565403b23B5BC7FE920457870Df4348374 "owner()(address)" --rpc-url https://sepolia.optimism.io -> 0x8421D6D2253d3f8e25586Aa6692b1Bf591da3779

USDC admin:
cast call 0x77ac613B82b30fAc7d545E2D62723c4ac3E4d5c4 "admin()(address)" --rpc-url https://sepolia.optimism.io -> 0xA6abC0390c9aD135025b98a69d9764FBEdE7D651 (fallback proxy admin) ✅

// Deploy L2 Adapter implementation and proxy, initializing it with the owner
address _l2AdapterImpl = address(new L2OpUSDCBridgeAdapter(_usdcProxy, _L2_MESSENGER, _l1Adapter));
address _l2Adapter =
address(new ERC1967Proxy(_l2AdapterImpl, abi.encodeCall(OpUSDCBridgeAdapter.initialize, _l2AdapterOwner)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be a problem when the contracts are verfied on etherscan, the name of the contract will be ERC1967Proxy ... I would wrap the ERC1967Proxy into something like contact AdapterProxy is ERC1967Proxy

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we arent changing anything lets leave it as is, circle uses custom location for their proxy, we dont, it will be easier to read since we dont change anything logic wise

@excaliborr excaliborr merged commit 601ec75 into audit/spearbit Jul 29, 2024
4 checks passed
@excaliborr excaliborr deleted the refactor/upgradeable-adapters branch July 29, 2024 11:50
hexshire pushed a commit that referenced this pull request Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants