Skip to content

Commit

Permalink
feat: add avail attestation contract
Browse files Browse the repository at this point in the history
  • Loading branch information
QEDK committed Apr 9, 2024
1 parent 5a803e2 commit f1aeb9e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/AvailAttestation.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.25;

import {Initializable} from "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import {IVectorx} from "src/interfaces/IVectorx.sol";
import {IAvailBridge} from "src/interfaces/IAvailBridge.sol";

/**
* @author @QEDK (Avail)
* @title AvailAttestation
* @notice An abstract data attestation implementation for validiums, optimiums and generic rollup stacks
* @custom:security security@availproject.org
*/
abstract contract AvailAttestation is Initializable {
struct AttestationData {
uint32 blockNumber;
uint128 leafIndex;
}

IAvailBridge public bridge;
IVectorx public vectorx;

mapping (bytes32 => AttestationData) public attestations;

error InvalidAttestationProof();
event Attested(bytes32 indexed leaf, uint32 indexed blockNumber, uint128 indexed leafIndex);

function initialize(IAvailBridge _bridge) external initializer {
bridge = _bridge;
vectorx = bridge.vectorx();
}

function _attest(IAvailBridge.MerkleProofInput calldata input) external {
if (!bridge.verifyBlobLeaf(input)) revert InvalidAttestationProof();
attestations[input.leaf] = AttestationData(
vectorx.rangeStartBlocks(input.rangeHash) + uint32(input.dataRootIndex),
uint128(input.leafIndex)
);
}
}
1 change: 1 addition & 0 deletions src/interfaces/IAvailBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface IAvailBridge {
error UnlockFailed();
error WithdrawFailed();

function vectorx() external view returns (IVectorx);
function setPaused(bool status) external;
function updateVectorx(IVectorx newVectorx) external;
function updateTokens(bytes32[] calldata assetIds, address[] calldata tokenAddresses) external;
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/IVectorx.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pragma solidity ^0.8.25;

interface IVectorx {
function dataRootCommitments(bytes32 rangeHash) external view returns (bytes32 dataRoot);
function rangeStartBlocks(bytes32 rangeHash) external view returns (uint32 startBlock);
}
5 changes: 5 additions & 0 deletions src/mocks/VectorxMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import {IVectorx} from "src/interfaces/IVectorx.sol";

contract VectorxMock is IVectorx {
mapping(bytes32 => bytes32) public dataRootCommitments;
mapping(bytes32 => uint32) public rangeStartBlocks;

function set(bytes32 rangeHash, bytes32 dataRoot) external {
dataRootCommitments[rangeHash] = dataRoot;
}

function setStartBlock(bytes32 rangeHash, uint32 startBlock) external {
rangeStartBlocks[rangeHash] = startBlock;
}
}

0 comments on commit f1aeb9e

Please sign in to comment.