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

Provide abi encoded exit event in hex format from bridge_generateExitProof JSON RPC #1929

Conversation

Stefan-Ethernal
Copy link
Collaborator

@Stefan-Ethernal Stefan-Ethernal commented Sep 22, 2023

Description

In order to be able to rely on external tools for executing bridge transactions (such as Foundry), bridge_generateExitProof should return an abi-encoded exit event, instead of an object, so that it becomes possible to submit an exit transaction without the need to programmatically decode returned exit event and transforming it into ABI-encoded byte array. With this fix, it is possible to provide a given exit event straight away to the exit transaction (namely invoking the ExitHelper.exit function).

This PR also changes the way the encode function is invoked for ABI events. Instead of accepting parameters to encode via inputs argument, now it uses already provided fields in each struct representing an ABI event.

Foundry test scenario

These are the steps that represent the test scenario that bridges the Supernets native token to the rootchain and withdraws it back to the Supernets. This is just an example that uses predefined private keys, receiver addresses, and contract addresses. For the most part, those need to be adapted, based on real values.

  1. Approve root predicate as a spender of deposit tokens (namely the one that is being bridged). Adapt private-key and rpc-url as well as amount values accordingly. Also contract address in case non-native token is being bridged (use arbitrary ERC20 token address instead of 0x0000000000000000000000000000000000001010)
cast send --private-key b0bda8d32bdc5f987ef9585bed2a1d2a7c1971e7abef0fa5d99249f9bd9a6c36 --rpc-url http://localhost:10002 \
0x0000000000000000000000000000000000001010 "function approve(address spender, uint256 amount) returns (bool)" 0x0000000000000000000000000000000000001009 1ether
  1. Deposit (Supernets mintable native token). Adapt private-key and rpc-url as well as receiver and amount values accordingly.
cast send --private-key b0bda8d32bdc5f987ef9585bed2a1d2a7c1971e7abef0fa5d99249f9bd9a6c36 --rpc-url http://localhost:10002 \
0x0000000000000000000000000000000000001009 "function depositTo(address rootToken, address receiver, uint256 amount) external" 0x0000000000000000000000000000000000001010 0x396225475de7D57964a20C7D149Fe827D0D434fa 1ether
  1. Acquire exit event proof (alongside exit event) and remember these values, because they are going to be needed for sending exit transaction. Provide adequate rpc-url and exit event id as a parameter.
cast rpc --rpc-url http://localhost:10002 "bridge_generateExitProof" 1
  1. Send exit transaction (for arguments, provide CheckpointBlock, LeafIndex, ExitEvent and Proof respectively). For contract address, provide address of the ExitHelper contract (it can be retrieved from the genesis.json exitHelperAddress)
cast send --private-key b0bda8d32bdc5f987ef9585bed2a1d2a7c1971e7abef0fa5d99249f9bd9a6c36 \
--rpc-url http://localhost:8545 0x72e85c41f3Fc1B69d20F91e502d7d923caFE3ed5 "function exit(uint256 blockNum, uint256 index, bytes leaf, bytes32[] proof) external" 7730 0 \
0000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000100900000000000000000000000045b0a43d5cdc3b402586a359373f90d801a0e888000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a087a7811f4bfedea3d341ad165680ae306b01aaeacc205d227629cf157dd9f8210000000000000000000000000000000000000000000000000000000000001010000000000000000000000000396225475de7d57964a20c7d149fe827d0d434fa000000000000000000000000396225475de7d57964a20c7d149fe827d0d434fa0000000000000000000000000000000000000000000000000de0b6b3a7640000 \
[]
  1. Send withdraw transaction (back to the Supernets). Adapt private-key, rpc-url, contract address (it corresponds to erc20ChildMintablePredicateAddress, which is acquired from the genesis.json), childToken value (can be acquired by querying either root or child predicate, rootTokenToChildToken and providing corresponding root token address as a key), receiver and amount parameters.
cast send --private-key b0bda8d32bdc5f987ef9585bed2a1d2a7c1971e7abef0fa5d99249f9bd9a6c36 --rpc-url http://localhost:8545 \
0x45B0a43d5CDc3b402586A359373f90D801a0e888 "function withdrawTo(address childToken, address receiver, uint256 amount) external" 0xa8933dF6C1A0A84501f446e4e3174415dE201c5F 0x396225475de7D57964a20C7D149Fe827D0D434fa 1ether

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Checklist

  • I have assigned this PR to myself
  • I have added at least 1 reviewer
  • I have added the relevant labels
  • I have updated the official documentation
  • I have added sufficient documentation in code

Testing

  • I have tested this code with the official test suite
  • I have tested this code manually

Manual tests

Please complete this section if you ran manual tests for this functionality, otherwise delete it

Documentation update

Please link the documentation update PR in this section if it's present, otherwise delete it

Additional comments

Please post additional comments in this section if you have them, otherwise delete it

@Stefan-Ethernal Stefan-Ethernal changed the title Provide abi encoded exit event in hex format Provide abi encoded exit event in hex format from bridge_generateExitProof JSON RPC Sep 22, 2023
@Stefan-Ethernal Stefan-Ethernal self-assigned this Sep 23, 2023
@Stefan-Ethernal Stefan-Ethernal added the bug fix Functionality that fixes a bug label Sep 23, 2023
@Stefan-Ethernal Stefan-Ethernal marked this pull request as ready for review September 25, 2023 06:13
@Stefan-Ethernal Stefan-Ethernal requested a review from a team September 26, 2023 06:18
@Stefan-Ethernal Stefan-Ethernal force-pushed the EVM-844-provide-abi-encoded-exit-event-in-bridge-generate-exit-proof branch from 1db5e6c to 9f990e1 Compare September 27, 2023 11:17
@Stefan-Ethernal Stefan-Ethernal merged commit e700006 into develop Sep 27, 2023
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 27, 2023
@Stefan-Ethernal Stefan-Ethernal deleted the EVM-844-provide-abi-encoded-exit-event-in-bridge-generate-exit-proof branch September 27, 2023 15:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fix Functionality that fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants