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

[Flow EVM] use transfer from/to a fixed native token bridge address for deposit/withdraw calls #5469

Merged

Conversation

ramtinms
Copy link
Contributor

@ramtinms ramtinms commented Feb 27, 2024

This PR

  • changes the deposit to adjust a balance on a fixed pre-allocated address and then do a simple transfer call from the bridge address to the target address.
  • changes the withdraw call to be a simple transfer call to the bridge address followed by a balance subtraction for the bridge account.

But why?

  1. This is the first PR towards [Flow EVM] make deposit available for any EVM address #5468, using simple transfer makes it possible to deposit to any address (even smart contracts).

  2. Not using a fixed pre-allocated address, means all the tools should be updated to expect a COA account balance changes after bridging and some legacy tools might not know how to deal with these anomalies, using a fixed address, manage the anomaly to a single EOA (bridge account).

  3. This would allow later expansion of COA smart contracts to introduce TokenDeposit events like other smart contract wallets.

@ramtinms ramtinms marked this pull request as ready for review February 27, 2024 23:04
@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 67.56757% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 55.83%. Comparing base (53aaae3) to head (55feff3).

Files Patch % Lines
fvm/evm/emulator/emulator.go 69.69% 6 Missing and 4 partials ⚠️
fvm/evm/types/call.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5469      +/-   ##
==========================================
- Coverage   55.85%   55.83%   -0.02%     
==========================================
  Files        1030     1030              
  Lines      100807   100803       -4     
==========================================
- Hits        56304    56283      -21     
- Misses      40171    40186      +15     
- Partials     4332     4334       +2     
Flag Coverage Δ
unittests 55.83% <67.56%> (-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.

Copy link
Collaborator

@m-Peter m-Peter left a comment

Choose a reason for hiding this comment

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

Looks nice 👌

if !proc.state.Exist(addr) {
proc.state.CreateAccount(addr)
// create bridge account if not exist
if !proc.state.Exist(bridge) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just wondering why we don't create these "special" accounts as part of evm setup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, we could, I was more leaning towards lazy creation, but we can revisit this in a future PR for all of the special accounts.

msg := call.Message()
proc.evm.TxContext.Origin = msg.From
// withdraw the amount and move it to the bridge account
res, err := proc.run(msg, txHash, 0, types.DirectCallTxType)
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

fvm/evm/types/call.go Outdated Show resolved Hide resolved
Copy link
Contributor

@sideninja sideninja left a comment

Choose a reason for hiding this comment

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

very nice

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.

@ramtinms ramtinms enabled auto-merge March 5, 2024 19:56
@ramtinms ramtinms added this pull request to the merge queue Mar 5, 2024
Merged via the queue into master with commit d3d48b1 Mar 5, 2024
51 checks passed
@ramtinms ramtinms deleted the ramtin/5468-part1-use-transfer-for-native-token-bridging branch March 5, 2024 20:33
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