Skip to content

Conversation

@fedealconada
Copy link
Contributor

@fedealconada fedealconada commented Sep 18, 2024

We want to use the canonical zkSync Bridge with a custom bridge implementation that works only for USDC (since we want to use the native USDC and not the ERC20 that the zksync bridge deploys by default).

The PR is a little bit large but the key contracts to review are:

Bridge/Withdrawal flow

The flow to bridge and withdraw using custom bridges is the same as when bridging with any token except for the fact that when Bridgehub is called, you need specify the address of the custom L1 bridge.

To bridge USDC from L1 (Ethereum) -> L2 (Sophon):

  • Call bridgehub.requestL2TransactionTwoBridges (same as normally) but you set the secondBridgeAddress with the custom shared bridge deployed on L1. This way, the bridgehub contracts knows which contract to ping to.
  • requestL2TransactionTwoBridges makes a call to the custom shared bridge customBridgeL1.bridgehubDeposit function and transfers USDC from the user to this contract and emits an event.
  • sequencers will pick this event and automatically make a call to customL2Bridge.finalizeDeposit on the custom bridge deployed on L2 (on Sophon).
  • finalizeDeposit is the one that calls usdc.mint() to mint USDC on L2 (note this custom bridge must have MINTER role on the USDC contract).

To withdraw USDC from L2 (Sophon) -> L1 (Etheruem):

  • User makes a call to customBridgeL2.withdraw (same as normally except for the fact that you're calling the custom bridge contract)
  • Once the batch is sealed, user needs to call customL1Bridge.finalizeWithdrawal to finalise the withdrawal

Fixes #SOP-53
Fixes #SOP-54
Fixes #SOP-88
Fixes #SOP-89

@fedealconada fedealconada force-pushed the custom-usdc-bridge branch 2 times, most recently from ca62b13 to 3f38ad5 Compare September 18, 2024 21:50
@linear
Copy link

linear bot commented Sep 19, 2024

SOP-54 Create L2SharedBridge.sol

Create a custom L2SharedBridge.sol that works with the native USDC

SOP-53 Create L1SharedBridge.sol

Create a custom L1SharedBridge.sol that works with the USDC implementation

SOP-88 Create unit tests

Copy link

@federava federava left a comment

Choose a reason for hiding this comment

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

This looks great! The implementation is clear, and the test coverage is thorough.

@kelemeno
Copy link

Look good overall I think, the main is a direct clone of one of era_contracts repo right?

I would get rid of even more of the legacy code, I don't think you need it, modifying the interfaces is ok.

But the approach/security/code looks good!

@fedealconada
Copy link
Contributor Author

Look good overall I think, the main is a direct clone of one of era_contracts repo right?

I would get rid of even more of the legacy code, I don't think you need it, modifying the interfaces is ok.

But the approach/security/code looks good!

Thanks for the comments!

@fedealconada
Copy link
Contributor Author

I would get rid of even more of the legacy code, I don't think you need it, modifying the interfaces is ok.

would you point me to which are the other legacy things that we are safe to remove?

}
}

// TODO: do we need?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kelemeno do we need this? or it's safe to be removed?

Copy link

Choose a reason for hiding this comment

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

yes you can remove.

@fedealconada
Copy link
Contributor Author

Btw, which commit did you branch off from in era-contracts? It is the audited one right? Could you include it somewhere please?

this is the commit we've forked from https://github.com/matter-labs/era-contracts.git#bce4b2d0f34bd87f1aaadd291772935afb1c3bd6

@fedealconada fedealconada merged commit 23f6be5 into main Nov 20, 2024
2 checks passed
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.

5 participants