Skip to content

Commit

Permalink
Abi bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkaplan13 committed Jun 6, 2024
1 parent a691a99 commit ceb0bc1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 12 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@

The Warp precompile also offers a `getVerifiedWarpBlockHash` interface function, which surfaces 32-byte hashes that were signed by a threshold of stake weight of a given Subnet. Validators of EVM chains that support Warp should be willing to sign the hash of any accepted block on that chain. **This enables importing information about that chain into other Subnets without needing to interact with the source chain at all.**

## Example Implementations
Contracts looking to import events from other chains should inherit from the abstract `EventImporter` contract in this repo. The `EventImporter` contract handles the authentication of block headers, verification of Merkle proofs, and parsing of event logs. The child contracts import events should provide their own `_onEventImport` implementation to define the logic that should be executed when a new event is received. For example:
```solidity
pragma solidity 0.8.18;
import {EVMEventInfo, EventImporter} from "./EventImporter.sol";
contract MyEventImporter is EventImporter {
// Blockchain ID of the source chain.
bytes32 public immutable sourceBlockchainID;
// Address of contract to import events from on the source chain.
address public immutable emittingContract;
constructor(bytes32 sourceBlockchainID_, address emittingContract_) {
sourceBlockchainID = sourceBlockchainID_;
emittingContract = emittingContract_;
}
function _onEventImport(EVMEventInfo memory eventInfo)
internal
override
{
require(eventInfo.blockchainID == sourceBlockchainID);
require(eventInfo.log.loggerAddress = emitterContract)
}
}
```

## Structure
- `contracts/` is a Foundry project that implments the necessary Merkle proof verification and RLP decoding to be able to import event logs from other Subnets.
- `EventImporter.sol` is an abstract contract that handles the Warp verification, Merkle proof verification, and RLP decoding for a given event against a provided block hash and header. Child contracts looking to import events only have to implement the `_onEventImport` function to define how they would like to handle specific event imports.
Expand Down Expand Up @@ -35,6 +65,7 @@ The E2E test flow:
5. Imports the price feed update event into the Subnet by constructing a Warp signature of the block hash that it occured in on the C-Chain, constructing a Merkle proof for the transaction receipt the event was contained in, and broadcasting this information to the Subnet by calling the `importEvent` interface function of the `PriceFeedImporter` contract.

## Open Questions and Considerations
The following is a non-exhaustive list of that should be answered and considerations to be made to move this idea from a proof-of-concept to a production-ready framework.
- Can/Should block hash authenticated via Warp messages be stored such that they can be used to prove arbitrarily many events going forward without having to re-verify a Warp aggregate signature?
- Is the Merkle proof verification or RLP decoding prohibitively expensive gas-wise? Can they be optimized if so? How does gas usage scale with the number of receipts in the block including the event to be imported?
- Is the delay from the time an event is emitted on a source chain to when it is imported on another chain a non-starter for certain applications?
Expand Down
Loading

0 comments on commit ceb0bc1

Please sign in to comment.