Forum

Programmatically enabling "executeSignatures" on home AMB side

We have a transaction on the home side that we want to transfer to the foreign side : https://blockscout.com/poa/sokol/tx/0x9ae1356fd361d4021b39f1c25f5a15327b95db9eeda420f2c168914fecc86358/token-transfers

We can finalize the transfer from the home side back to the foreign side manually here :

We did it and it was successful : https://kovan.etherscan.io/tx/0x2a70e38b3f8903b7a3ed1caaff5b57e7880c202a8afa6ea9bed791839a7dc2ab

We would like to do this programmatically but do not know where to get the parameters for the executeSignatures function [ executeSignatures(bytes _data, bytes _signatures) ].

We looked at the AMB Oracle code : https://github.com/poanetwork/tokenbridge/blob/bbc68f9fa2c8d4fff5d2c464eb99cea5216b7a0f/oracle/src/events/processAMBCollectedSignatures/index.js#L149

but still do not understand how or where the “_data” and “_signatures” are coming from.

Are they coming from the payload of an event from the home side AMB? Any help or insight would be greatly appreciated. Our goal is to make it easier for users to navigate back and forth from main net to xdai chain.

@jamesyoung

authorityResponsibleForRelay, messageHash and NumberOfCollectedSignatures are emitted as part of the CollectedSignatures event: https://github.com/poanetwork/tokenbridge-contracts/blob/835742dfd8f1c869d4e7b61582155d250d6cf094/contracts/upgradeable_contracts/arbitrary_message/BasicHomeAMB.sol#L101

Where you can see the messageHash argument is calculated as keccak256 of the message signed by the oracles: https://github.com/poanetwork/tokenbridge-contracts/blob/835742dfd8f1c869d4e7b61582155d250d6cf094/contracts/upgradeable_contracts/arbitrary_message/BasicHomeAMB.sol#L75

You can find that the message comes from the UserRequestForSignature event and signed by the oracle: https://github.com/poanetwork/tokenbridge/blob/bbc68f9fa2c8d4fff5d2c464eb99cea5216b7a0f/oracle/src/events/processAMBSignatureRequests/index.js#L35

The event UserRequestForSignature specifies the encoded data prepared by AMB contract as the message: https://github.com/poanetwork/tokenbridge-contracts/blob/835742dfd8f1c869d4e7b61582155d250d6cf094/contracts/upgradeable_contracts/arbitrary_message/HomeAMB.sol#L15. This message contains the message header and the encoded call of the OmniBridge contract on the Ethereum Mainnet.

The simplest way to get signatures is to iterate through the range from 0 till NumberOfCollectedSignatures-1 and call the method signature of AMB contract for every index of the iteration: https://github.com/poanetwork/tokenbridge/blob/bbc68f9fa2c8d4fff5d2c464eb99cea5216b7a0f/oracle/src/events/processAMBCollectedSignatures/index.js#L105.

1 Like