Skip to content

Commit

Permalink
Merge branch 'optimistic-da-verification' into avail-develop-v2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RISHABHAGRAWALZRA committed Aug 6, 2024
2 parents e98d933 + 938940e commit 535c5b4
Show file tree
Hide file tree
Showing 16 changed files with 346 additions and 158 deletions.
6 changes: 6 additions & 0 deletions .env.sample.goerli
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ ARBISCAN_API_KEY=""
## deployer key
DEVNET_PRIVKEY=""

## optional keys based on requirement
INFURA_KEY=""
ALCHEMY_KEY=""
ETHERSCAN_API_KEY=""
BASESCAN_API_KEY=""

## optional - address of already deployed ERC20 token which shall be used as rollup's fee token
FEE_TOKEN_ADDRESS=""
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ module.exports = {
nova: process.env['NOVA_ARBISCAN_API_KEY'],
arbGoerliRollup: process.env['ARBISCAN_API_KEY'],
arbSepolia: process.env['ARBISCAN_API_KEY'],
baseSepolia: process.env['BASESCAN_API_KEY'],
baseSepolia: process.env['BASESCAN_API_KEY']
},
customChains: [
{
Expand Down
16 changes: 16 additions & 0 deletions scripts/deploymentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export async function deployAllContracts(
const isOnArb = await _isRunningOnArbitrum(signer)

const ethBridge = await deployContract('Bridge', signer, [])

//Deployment of DA Bridge
const daBridge = await deployDABridge("Avail", signer, [])

const reader4844 = isOnArb
? ethers.constants.AddressZero
: (await Toolkit4844.deployReader4844(signer)).address
Expand Down Expand Up @@ -132,13 +136,15 @@ export async function deployAllContracts(
ethInbox.address,
ethRollupEventInbox.address,
ethOutbox.address,
daBridge.address,
],
[
erc20Bridge.address,
erc20SequencerInbox.address,
erc20Inbox.address,
erc20RollupEventInbox.address,
erc20Outbox.address,
daBridge.address,
],
])
const prover0 = await deployContract('OneStepProver0', signer)
Expand Down Expand Up @@ -180,6 +186,16 @@ export async function deployAllContracts(
}
}


async function deployDABridge(bridge: string, signer: any, args: any): Promise<Contract> {
switch (bridge) {
case "Avail":
return await deployContract("AvailDABridge", signer, args)
default:
return Promise.resolve(new ethers.Contract("0x0000000000000000000000000000000000000000", [], ethers.getDefaultProvider()))
}
}

// Check if we're deploying to an Arbitrum chain
async function _isRunningOnArbitrum(signer: any): Promise<Boolean> {
const arbSys = ArbSys__factory.connect(ARB_SYS_ADDRESS, signer)
Expand Down
3 changes: 3 additions & 0 deletions scripts/rollupCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface RollupCreatedEvent {
adminProxy: string
sequencerInbox: string
bridge: string
dabridge: string
validatorUtils: string
validatorWalletCreator: string
}
Expand Down Expand Up @@ -109,6 +110,7 @@ export async function createRollup(feeToken?: string) {
const adminProxy = rollupCreatedEvent.args?.adminProxy
const sequencerInbox = rollupCreatedEvent.args?.sequencerInbox
const bridge = rollupCreatedEvent.args?.bridge
const dabridge = rollupCreatedEvent.args?.dabridge
const validatorUtils = rollupCreatedEvent.args?.validatorUtils
const validatorWalletCreator =
rollupCreatedEvent.args?.validatorWalletCreator
Expand Down Expand Up @@ -148,6 +150,7 @@ export async function createRollup(feeToken?: string) {
console.log('AdminProxy Contract created at address:', adminProxy)
console.log('SequencerInbox (proxy) created at address:', sequencerInbox)
console.log('Bridge (proxy) Contract created at address:', bridge)
console.log('DABridge (proxy) Contract created at address:', dabridge)
console.log('ValidatorUtils Contract created at address:', validatorUtils)
console.log(
'ValidatorWalletCreator Contract created at address:',
Expand Down
12 changes: 2 additions & 10 deletions src/bridge/ISequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
pragma solidity >=0.6.9 <0.9.0;
pragma experimental ABIEncoderV2;

import "../data-availability/IAvailDABridge.sol";
import "../data-availability/MerkleProofInput.sol";
import "../data-availability/IDABridge.sol";
import "../libraries/IGasRefunder.sol";
import "./IDelayedMessageProvider.sol";
import "./IBridge.sol";
Expand All @@ -30,8 +29,6 @@ interface ISequencerInbox is IDelayedMessageProvider {
IBridge.BatchDataLocation dataLocation
);

event validateBatchDataOverAvailDA(MerkleProofInput indexed merkleProofInput);

event OwnerFunctionCalled(uint256 indexed id);

/// @dev a separate event that emits batch data when this isn't easily accessible in the tx.input
Expand Down Expand Up @@ -69,11 +66,6 @@ interface ISequencerInbox is IDelayedMessageProvider {
// solhint-disable-next-line func-name-mixedcase
function DAS_MESSAGE_HEADER_FLAG() external view returns (bytes1);

/// @dev If the first data byte after the header has this bit set,
/// then the batch data is a avail blobpointer message
// solhint-disable-next-line func-name-mixedcase
function AVAIL_MESSAGE_HEADER_FLAG() external view returns (bytes1);

/// @dev If the first data byte after the header has this bit set,
/// then the batch data is a das message that employs a merklesization strategy
/// See: https://github.com/OffchainLabs/nitro/blob/69de0603abf6f900a4128cab7933df60cad54ded/arbstate/das_reader.go
Expand Down Expand Up @@ -237,6 +229,6 @@ interface ISequencerInbox is IDelayedMessageProvider {
function initialize(
IBridge bridge_,
MaxTimeVariation calldata maxTimeVariation_,
IAvailDABridge AvailBridge
IDABridge daBridge_
) external;
}
72 changes: 18 additions & 54 deletions src/bridge/SequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
BadSequencerNumber,
AlreadyValidDASKeyset,
NoSuchKeyset,
BatchDataValidationForAvailDAFailed,
NotForked,
NotBatchPosterManager,
RollupNotChanged,
Expand All @@ -30,7 +29,8 @@ import {
InvalidHeaderFlag,
NativeTokenMismatch,
BadMaxTimeVariation,
Deprecated
Deprecated,
BadDABatchAttestation
} from "../libraries/Error.sol";
import "./IBridge.sol";
import "./IInboxBase.sol";
Expand All @@ -40,17 +40,13 @@ import "./Messages.sol";
import "../precompiles/ArbGasInfo.sol";
import "../precompiles/ArbSys.sol";
import "../libraries/IReader4844.sol";

import "../data-availability/IAvailDABridge.sol";
import "../data-availability/MerkleProofInput.sol";
import "../data-availability/BlobPointer.sol";
import {L1MessageType_batchPostingReport} from "../libraries/MessageTypes.sol";
import "../libraries/DelegateCallAware.sol";
import {IGasRefunder} from "../libraries/IGasRefunder.sol";
import {GasRefundEnabled} from "../libraries/GasRefundEnabled.sol";
import "../libraries/ArbitrumChecker.sol";
import {IERC20Bridge} from "./IERC20Bridge.sol";
//import "hardhat/console.sol";
import "../data-availability/IDABridge.sol";

/**
* @title Accepts batches from the sequencer and adds them to the rollup inbox.
Expand All @@ -64,6 +60,8 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox

IBridge public bridge;

IDABridge public daBridge;

/// @inheritdoc ISequencerInbox
uint256 public constant HEADER_LENGTH = 40;

Expand All @@ -76,9 +74,6 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
/// @inheritdoc ISequencerInbox
bytes1 public constant DAS_MESSAGE_HEADER_FLAG = 0x80;

/// @inheritdoc ISequencerInbox
bytes1 public constant AVAIL_MESSAGE_HEADER_FLAG = 0x0a;

/// @inheritdoc ISequencerInbox
bytes1 public constant TREE_DAS_MESSAGE_HEADER_FLAG = 0x08;

Expand Down Expand Up @@ -133,8 +128,6 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
// True if the chain this SequencerInbox is deployed on uses custom fee token
bool public immutable isUsingFeeToken;

IAvailDABridge public availBridge;

constructor(uint256 _maxDataSize, IReader4844 reader4844_, bool _isUsingFeeToken) {
maxDataSize = _maxDataSize;
if (hostChainIsArbitrum) {
Expand Down Expand Up @@ -185,7 +178,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
function initialize(
IBridge bridge_,
ISequencerInbox.MaxTimeVariation calldata maxTimeVariation_,
IAvailDABridge availBridge_
IDABridge daBridge_
) external onlyDelegated {
if (bridge != IBridge(address(0))) revert AlreadyInit();
if (bridge_ == IBridge(address(0))) revert HadZeroInit();
Expand All @@ -206,7 +199,13 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
rollup = bridge_.rollup();

_setMaxTimeVariation(maxTimeVariation_);
availBridge = availBridge_;

//initialise DA bridge for DA attestation verification
if (daBridge != IDABridge(address(0))) revert AlreadyInit();

// Can be zero if there is no da bridge requirement
// if (daBridge_ == IDABridge(address(0))) revert HadZeroInit();
daBridge = daBridge_;
}

/// @notice Allows the rollup owner to sync the rollup address
Expand Down Expand Up @@ -542,13 +541,13 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
/// therefore we restrict which flags can be provided as a header in this field
/// This also safe guards unused flags for future use, as we know they would have been disallowed up until this point
/// @param headerByte The first byte in the calldata
function isValidCallDataFlag(bytes1 headerByte) internal pure returns (bool) {
function isValidCallDataFlag(bytes1 headerByte) internal view returns (bool) {
return
headerByte == BROTLI_MESSAGE_HEADER_FLAG ||
headerByte == DAS_MESSAGE_HEADER_FLAG ||
(headerByte == (DAS_MESSAGE_HEADER_FLAG | TREE_DAS_MESSAGE_HEADER_FLAG)) ||
headerByte == ZERO_HEAVY_MESSAGE_HEADER_FLAG ||
headerByte == AVAIL_MESSAGE_HEADER_FLAG;
headerByte == daBridge.DA_MESSAGE_HEADER_FLAG();
}

/// @dev Form a hash of the data taken from the calldata
Expand All @@ -559,7 +558,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
function formCallDataHash(
bytes calldata data,
uint256 afterDelayedMessagesRead
) internal view returns (bytes32, IBridge.TimeBounds memory) {
) internal returns (bytes32, IBridge.TimeBounds memory) {
uint256 fullDataLen = HEADER_LENGTH + data.length;
if (fullDataLen > maxDataSize) revert DataTooLarge(fullDataLen, maxDataSize);

Expand All @@ -582,43 +581,8 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
// we skip the first byte, then read the next 32 bytes for the keyset
bytes32 dasKeysetHash = bytes32(data[1:33]);
if (!dasKeySetInfo[dasKeysetHash].isValidKeyset) revert NoSuchKeyset(dasKeysetHash);
}
// Avail batch expect to have the type byte set, followed by
if (data[0] & AVAIL_MESSAGE_HEADER_FLAG != 0 && data.length >= 100) {
// console.logString("Avail header found");
BlobPointer memory blobPointer;
(
blobPointer.blockHash,
blobPointer.sender,
blobPointer.nonce,
blobPointer.dasTreeRootHash,
blobPointer.merkleProofInput
) = abi.decode(data[1:], (bytes32, string, uint32, bytes32, MerkleProofInput));

// console.logBytes32(blobPointer.blockHash);
// console.logString(blobPointer.sender);
// console.logUint(blobPointer.nonce);
// console.logBytes32(blobPointer.dasTreeRootHash);

// for (uint256 i = 0; i < blobPointer.merkleProofInput.dataRootProof.length; i++) {
// console.logBytes32(blobPointer.merkleProofInput.dataRootProof[i]);
// }

// for (uint256 i = 0; i < blobPointer.merkleProofInput.leafProof.length; i++) {
// console.logBytes32(blobPointer.merkleProofInput.leafProof[i]);
// }

// console.logBytes32(blobPointer.merkleProofInput.rangeHash);
// console.logUint(blobPointer.merkleProofInput.dataRootIndex);
// console.logBytes32(blobPointer.merkleProofInput.blobRoot);
// console.logBytes32(blobPointer.merkleProofInput.bridgeRoot);
// console.logBytes32(blobPointer.merkleProofInput.leaf);
// console.logUint(blobPointer.merkleProofInput.leafIndex);
if (!availBridge.verifyBlobLeaf(blobPointer.merkleProofInput))
revert BatchDataValidationForAvailDAFailed(blobPointer.merkleProofInput.leaf);

// Not included this event as this function declared as view
//emit validateBatchDataOverAvailDA(blobPointer.merkleProofInput);
} else if (data[0] & daBridge.DA_MESSAGE_HEADER_FLAG() != 0 && data.length >= 100) {
if (daBridge.verifyBatchAttestation(data)) revert BadDABatchAttestation(data[0]);
}
}
return (keccak256(bytes.concat(header, data)), timeBounds);
Expand Down
Loading

0 comments on commit 535c5b4

Please sign in to comment.