### Ethereum to Sora Assuming what contract is valid and confirmation period passed ```mermaid sequenceDiagram actor A as Alice participant C as Bridge contract participant W as Offchain worker participant R as Substrate runtime A ->> C: sendERC20ToSidechain<br/>sendEthToSidechain C ->> C: Burn/Reserve tokens C ->> W: emit Deposit W ->> R: LoadIncomingRequest<br/>Result<IncomingRequest> R ->> R: Process LoadIncomingRequest alt Result is Ok R ->> R: Process IncomingRequest R ->> A: Send/Mint tokens on Sora side else R ->> R: Abort request end link C: Deposit @ https://github.com/sora-xor/sora2-evm-contracts/blob/9d212bbcc7d5c20f291e6b21b1f8e189e716e275/Bridge/Bridge.sol#L47 link C: sendEthToSidechain @ https://github.com/sora-xor/sora2-evm-contracts/blob/9d212bbcc7d5c20f291e6b21b1f8e189e716e275/Bridge/Bridge.sol#L349 link C: sendERC20ToSidechain @ https://github.com/sora-xor/sora2-evm-contracts/blob/9d212bbcc7d5c20f291e6b21b1f8e189e716e275/Bridge/Bridge.sol#L367 link W: IncomingRequest @ https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/requests/mod.rs#L292 link W: LoadIncomingRequest @ https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/requests/mod.rs#L536 link R: import_incoming_request @ https://github.com/sora-xor/sora2-network/blob/192e955819750e07798c05bc6a5a6d4f0c8d4a06/pallets/eth-bridge/src/lib.rs#L1712 ``` ### Sora to Ethereum ```mermaid sequenceDiagram actor A as Alice participant R as Substrate runtime participant W as Offchain worker participant C as Bridge contract A ->> R: transferToSidechain R ->> R: Burn/Reserve tokens R ->> W: OutgoingRequest W ->> W: Sign request W ->> R: Approve request A ->> R: Get signatures A ->> C: receiveByEthereumAssetAddress<br/>receiveBySidechainAssetId C ->> A: Send/Mint tokens ``` ### Offchain workers workflow ```mermaid flowchart TB subgraph HS [Handle substrate] direction TB HS1(Load finalized header) HS2(Handle failed transactions queue) HS3(Load handle_from_height) subgraph HS4 [for each from handle_from_height to finalized. max 20] direction TB HS41(Load block) HS42(Load pending transactions) HS43(Remove pending transactions<br/>presented in block) HS44(Resend transactions which is not<br/>presented in last 50 blocks or<br/>add to failed_tx_queue after 5 retries) HS45(Update handle_from_height) HS41 --> HS42 HS42 --> HS43 HS43 --> HS44 HS44 --> HS45 end HS1 --> HS2 HS2 --> HS3 HS3 --> HS4 end subgraph HE [Handle ethereum] direction TB HE1(Load and update current height) HE2(Load to_handle_from_height) HE3(Load logs from to_handle_from_height to current - 30. max 50) subgraph HL [for each log] direction TB HL1(Check contract address) HL2(Parse deposit event) HL3(Check if transaction already presented) HL4(Send import_incoming_request) HL1 --> HL2 HL2 --> HL3 HL3 --> HL4 end subgraph HR [for each pending request] direction TB HR1(Check is confirmed) HR2(Check is should be skipped) HR3(Check if should be reapproved) subgraph HRI [handle request] direction LR subgraph HRI1 [handle outgoing] direction TB HRI11(Sign request with peer key) HRI12(Send approve_request) HRI11 --> HRI12 end subgraph HRI2 [handle incoming] direction TB HRI21(Check if exists) HRI22(Send finalize_incoming_request) HRI21 --> HRI22 end subgraph HRI3 [handle load incoming] direction TB HRI31(Load tx receipt) HRI32(Parse receipt) HRI33(Send register_incoming_request) HRI31 --> HRI32 HRI32 --> HRI33 end end HR1 --> HR2 HR2 --> HR3 HR3 --> HRI end HE1 --> HE2 HE2 --> HE3 HE3 --> HL HL --> HR end HS --> HE click HS1 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L437" click HS2 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L449" click HS3 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L456" click HS41 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L470" click HS42 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L143" click HS43 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L153" click HS44 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L173" click HS45 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L484" click HE1 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L492" click HE2 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L506" click HE3 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L318" click HL1 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/mod.rs#L442" click HL2 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/mod.rs#L98" click HL3 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L338" click HL4 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/transaction.rs#L244" click HR1 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L640" click HR2 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L620" click HR3 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L628" click HRI11 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L81" click HRI12 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/transaction.rs#L322" click HRI21 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/handle.rs#L127" click HRI22 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/transaction.rs#L234" click HRI31 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/http.rs#L261" click HRI32 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/mod.rs#L414" click HRI33 "https://github.com/sora-xor/sora2-network/blob/f4d500935715a2dca35c7aa1d3cca7388e402811/pallets/eth-bridge/src/offchain/transaction.rs#L313" ``` ### Fake Deposit hacker contract ```solidity pragma solidity >=0.7.0 <0.9.0; contract EmptyEmit { event Deposit( bytes32 destination, uint256 amount, address token, bytes32 sidechainAsset ); receive() external payable { bytes32 empty; emit Deposit( 0xfa00badb62e150ae0e1c08740ecbc9a0b2b92aa9897fa131419ee304b9451f17, 1000000000000000000, address(0x0), empty ); } } ```