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

Adds bridge to fvm bootstrapping #7053

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

joshuahannan
Copy link
Member

@joshuahannan joshuahannan commented Feb 18, 2025

Work towards onflow/flow-emulator#782

Adds the bridge standup script as an option to fvm bootstrapping so that the bridge can be available in the emulator and other testing environments by default.

The option makes it so all the bridge contracts are deployed during bootstrapping. The VM bridge is effectively part of the core protocol now, so it should be deployed by default for the emulator. More and more developers need an easy way to test bridging, so this enables that with the emulator.

USDC deployment was also removed because the flow partnerships/defi team has given up on the old USDC contract in favor of a new EVM based USDC contract. It should never have been included here in the first place. Developers were not using USDC in the emulator, so this should not affect anyone

@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 52.91577% with 218 lines in your changes missing coverage. Please review.

Project coverage is 41.39%. Comparing base (02b0c42) to head (ca0867b).

Files with missing lines Patch % Lines
fvm/blueprints/bridge.go 0.00% 169 Missing ⚠️
fvm/bootstrap.go 90.45% 15 Missing and 10 partials ⚠️
fvm/blueprints/token.go 0.00% 17 Missing ⚠️
fvm/systemcontracts/system_contracts.go 61.53% 5 Missing ⚠️
utils/unittest/execution_state.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7053      +/-   ##
==========================================
+ Coverage   41.37%   41.39%   +0.02%     
==========================================
  Files        2174     2175       +1     
  Lines      190130   190557     +427     
==========================================
+ Hits        78657    78875     +218     
- Misses     104895   105091     +196     
- Partials     6578     6591      +13     
Flag Coverage Δ
unittests 41.39% <52.91%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshuahannan joshuahannan force-pushed the add-bridge-to-bootstrapping branch 2 times, most recently from 12adf5e to 7ae57c9 Compare February 25, 2025 14:52
@joshuahannan joshuahannan force-pushed the add-bridge-to-bootstrapping branch 2 times, most recently from ba6bf93 to 0d96420 Compare March 7, 2025 19:45
@joshuahannan joshuahannan marked this pull request as ready for review March 7, 2025 19:45
@joshuahannan
Copy link
Member Author

I finished writing all my tests so it is ready for review!

@janezpodhostnik There are still some tests failing that I'm confused about. In the evm tests, the bootstrapping is failing with this error:

    --- FAIL: TestEVMBatchRun/Batch_run_multiple_valid_transactions (0.68s)
panic: failed to set the factory as registrar: [Error Code: 1101] error caused by: 1 error occurred:
		* transaction execute failed: [Error Code: 1101] cadence runtime error: Execution failed:
	  --> 512aac31a246aa175e87cf5e9cf7334d69457540e034e85feeca351e80b07a80:44:28
	   |
	44 |         let decodedResult = EVM.decodeABI(
	45 |                 types: [Type<EVM.EVMAddress>()],
	46 |                 data: postRegistrarResult.data
	47 |             )
	   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	
	error: failed to ABI decode data
	   --> f8d6e0586b0a20c7.EVM:622:8

Do you know why the ABI decoding would fail in that test but not in any of the fvm tests?

@joshuahannan joshuahannan force-pushed the add-bridge-to-bootstrapping branch from 0d96420 to 2ae0bed Compare March 10, 2025 15:01
@janezpodhostnik
Copy link
Contributor

Thank you very much for preparing this! I will take a look at the error in a couple of days.

@joshuahannan joshuahannan force-pushed the add-bridge-to-bootstrapping branch from 2ae0bed to 976d09d Compare March 11, 2025 16:54
@joshuahannan
Copy link
Member Author

Thanks, just to provide a bit more context, that is coming from the bridge setup part of bootstrapping that I wrote. It is from the step where we provide the address of the registrar contract to set the token factory contract that deploys the bridge deployed solidity token smart contracts.

It happens when we are decoding the ABI data from the registrar contract.

This step succeeds in all of the fvm tests, but doesn't in the evm tests, so it sounds to me like maybe there is something in the config for the EVM tests that differs from the FVM tests that makes this not work in this context.

@janezpodhostnik
Copy link
Contributor

What I found is that there is an underlying error: "abi: attempting to unmarshal an empty string while arguments are expected"

at this location: https://github.com/onflow/flow-evm-bridge/blob/b32c787631c9c84c548b2e414d87b49fa32b12d8/cadence/transactions/bridge/admin/evm/set_registrar.cdc#L44

which means the postRegistrarResult.data was empty... but I don't know what that means yet.

@joshuahannan
Copy link
Member Author

Interesting. @sisyphusSmiling Are you able to take a look? Do you know why postRegistrarResult.data would be empty? I would assume that it being empty would mean that the registrar address was not set properly, but I also figured that one of the previous EVM transactions in the Cadence transaction would have failed first. What do you think?

@janezpodhostnik
Copy link
Contributor

Looks like evm_test are written a bit weird and are mixing 2 different storages, so the bootstrapping does not start with an empty storage.

They will need to be changed to be more like the fvm_tests.

@joshuahannan
Copy link
Member Author

@janezpodhostnik Just to clarify, how would starting with a different storage affect the bridge bootstrapping? And are you saying that you'll be able to help update them, or I should do that?

@janezpodhostnik
Copy link
Contributor

I am trying to update the tests, but I'm unfamiliar with these tests and its proving difficult. I will let you know how it goes.

@janezpodhostnik
Copy link
Contributor

@joshuahannan I tried fixing the tests, but it would take me more time than I currently have.

I suggest adding a disable option for bootstrapping the bridge, and disable the bridge in these specific tests (evm_test.go).

@joshuahannan
Copy link
Member Author

okay, I'll do that. Thanks for taking a look!

@joshuahannan joshuahannan force-pushed the add-bridge-to-bootstrapping branch from 976d09d to 30cb755 Compare March 20, 2025 16:12
@joshuahannan
Copy link
Member Author

@janezpodhostnik I just pushed the changes and everything is passing now. Can you review? Also, since I added the bootstrap option to setup the bridge and it doesn't happen by default any more, where do we add that to use that for the bootstrapping that is used for the emulator?

@janezpodhostnik janezpodhostnik force-pushed the add-bridge-to-bootstrapping branch from e8c1ceb to f0624b6 Compare March 25, 2025 15:30
Copy link
Contributor

@janezpodhostnik janezpodhostnik left a comment

Choose a reason for hiding this comment

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

Added a commit to cleanup some stuff.

I had some minor comments but overall it looks ok.

for the emulator, the option can be enabled here: https://github.com/onflow/flow-emulator/blob/8528f3e70bae633ff6774a1f32f3cd65a255192d/emulator/blockchain.go#L606

Can you also add a bit more description to the PR (or link it to an issue if you have one):

  • the option added
  • what does the option enable
  • the removal of USDC

@@ -375,9 +386,6 @@ func (b *bootstrapExecutor) Execute() error {
b.deployMetadataViews(fungibleToken, nonFungibleToken, &env)
b.deployFungibleTokenSwitchboard(fungibleToken, &env)

// deploys the USDCFlow smart contract
b.deployUSDCFlow(fungibleToken, &env)
Copy link
Contributor

Choose a reason for hiding this comment

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

will the removal of the USDCFlow smart contract cause any issues with developers using the emulator?

Please not the removal in the PR description.

Copy link
Member Author

@joshuahannan joshuahannan Mar 25, 2025

Choose a reason for hiding this comment

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

I added some stuff to the description of the PR. USDC was only in here very briefly (only in the latest release from a few weeks ago), and we never announced it, so it is extremely unlikely that anyone was using it. We should have never added it in the first place. That was my bad

fvm/bootstrap.go Outdated
).(cadence.String)

if contractAddr.String() == "" {
log.Fatal("Contract address not found in event")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you return an error instead and handle the error one level higher.

Should this function also return an error if there was no "TransactionExecuted" event found?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, I added both of those. 👍

fvm/bootstrap.go Outdated
if contractAddr.String() == "" {
log.Fatal("Contract address not found in event")
}
address := strings.ToLower(strings.Split(contractAddr.String(), "x")[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this removing a hex prefix? If so, try:

Suggested change
address := strings.ToLower(strings.Split(contractAddr.String(), "x")[1])
address := strings.ToLower(strings.TrimPrefix(contractAddr.String(), "0x"))

fvm/bootstrap.go Outdated
log.Fatal("Contract address not found in event")
}
address := strings.ToLower(strings.Split(contractAddr.String(), "x")[1])
return address[:len(address)-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why this is needed. Can you add a comment describing what is being parsed here.

Copy link
Member Author

@joshuahannan joshuahannan Mar 25, 2025

Choose a reason for hiding this comment

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

For some reason, there are extra double quotes here in the address so the first and last character needs to be removed for it to only be the address. I added a comment saying that.

fvm/bootstrap.go Outdated
)
panicOnMetaInvokeErrf("failed to create COA in Service Account: %s", txError, err)

gasLimit := 15000000
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a comment describing how this constant was picked.

Copy link
Member Author

Choose a reason for hiding this comment

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

added

nameWithCDC := slashSplit[len(slashSplit)-1]
name := nameWithCDC[:len(nameWithCDC)-4]

if name == "FlowEVMBridgeUtils" {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this one is special deploy it outside of the loop. that way you do not need the logic to extract the name.

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that it needs to be deployed in the middle of all the contracts it is looping through, so if I deployed it outside, i'd have to start a new loop which feels like it kind of negates the code saved from removing the name logic.

@joshuahannan joshuahannan force-pushed the add-bridge-to-bootstrapping branch from f0624b6 to ca0867b Compare March 25, 2025 22:03
Copy link
Contributor

@janezpodhostnik janezpodhostnik left a comment

Choose a reason for hiding this comment

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

looks good.

Do you anticipate more contracts being needed in the short term? I would like to take some time to clean up bootstrapping before we add more.

@joshuahannan
Copy link
Member Author

We're making an upgrade to the bridge soon that will add two more contracts to the bridge bootstrapping, but besides that, I don't think we'll need to add any more soon.

@joshuahannan
Copy link
Member Author

@zhangchiqing Would you be able to review this also?

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