LayerZero-Labs/LayerZero

Adress format expected for 'sendFrom' is bytes32 in OFTv2 ?

PoCk3T-SPAI opened this issue · 1 comments

Hello LayerZero team & community,

Small technical challenge I'm facing here with LZ OFTv2, appreciate any insights or feedbacks anyone would be able to share with me :)

Context:

  • I've deployed this base LayerZero OFTv2 contract on my base chain Polygon
  • I've deployed this remote LayerZero OFTv2 contract on my remote chain Optimism
  • I've used the setTrustedRemoteAddress function on the base Polygon contract to point to the Optimism remote contract (transaction here)
  • And vice versa for Optimism->Polygon here

Problem:

  • Trying to use sendFrom on the base contract yields a Fail with error 'LayerZero: incorrect remote address size' error (example in this failed transaction)
  • I'm assuming it's related to the regular ETH wallet account 0x... type of address I've used for the "_toAddress" parameter, which is actually expecting a bytes32 instead

Question:

  • How to properly use sendFrom, and more precisely, how to format my value for "_toAddress" so it's accepted by LayerZero BaseOFTV2 ?
  • Bonus points if anyone has any idea on how to convert an address type of input into a bytes32 one in Python? I will be making these kind of sendFrom transactions as part of ApeX/ape which is using the underlying eth-abi Python library

Answering to myself thanks to the help of the dev team on Discord:
LzApp has 2 functions for setting trusted remote - setTrustedRemote and setTrustedRemoteAddress. They are interchangeable. Please refer to the contract code. When calling setTrustedRemote you need to supply the pathway (encodePacked(remoteAddress,localAddress)), but when calling setTrustedRemoteAddress you need to supply a remote address. The pathway encoding will be performed in the contract function.

image

Using setTrustedRemote ended up working for me.

In Python with ApeX/ape library, it translates into:

from eth_abi.packed import encode_packed
remoteEndpoint = encode_packed(['address', 'address'], [remote_contract_addr, base_contract_deployed.address])
base_contract_deployed.setTrustedRemote(_remote_chain_id, _remoteEndpoint, sender=account)