Skip to content

Commit

Permalink
Merge pull request #7 from Layr-Labs/epociask--fix-bugs
Browse files Browse the repository at this point in the history
fix(inbox): Add stubs and updated `addSequencerBatchFromEigenDA` function
  • Loading branch information
epociask authored Jul 8, 2024
2 parents 2f8d2cc + 2a561f8 commit 4395fa7
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 86 deletions.
19 changes: 9 additions & 10 deletions deploy/EigenDAServiceManagerStubCreator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module.exports = async hre => {
const { deployments, getNamedAccounts, ethers } = hre
const { deploy } = deployments
const { deployer } = await getNamedAccounts()

await deploy('EigenDAServiceManagerStub', { from: deployer, args: [] })
}

module.exports.tags = ['EigenDAServiceManagerStub', 'test']
module.exports.dependencies = []

const { deployments, getNamedAccounts, ethers } = hre
const { deploy } = deployments
const { deployer } = await getNamedAccounts()

await deploy('EigenDAServiceManagerStub', { from: deployer, args: [] })
}

module.exports.tags = ['EigenDAServiceManagerStub', 'test']
module.exports.dependencies = []
15 changes: 1 addition & 14 deletions deploy/SequencerInboxStubCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ module.exports = async hre => {
futureSeconds: 10000,
}

const eigenDAServiceManager = await ethers.getContract('EigenDAServiceManagerStub')

// constructor(
// IBridge bridge_,
// address sequencer_,
// ISequencerInbox.MaxTimeVariation memory maxTimeVariation_,
// uint256 maxDataSize_,
// IReader4844 reader4844_,
// IEigenDAServiceManager eigenDAServiceManager_,
// bool isUsingFeeToken_
// )

await deploy('SequencerInboxStub', {
from: deployer,
args: [
Expand All @@ -36,11 +24,10 @@ module.exports = async hre => {
maxTime,
117964,
reader4844.address,
eigenDAServiceManager.address,
false,
],
})
}

module.exports.tags = ['SequencerInboxStub', 'test']
module.exports.dependencies = ['BridgeStub', 'EigenDAServiceManagerStub']
module.exports.dependencies = ['BridgeStub']
24 changes: 18 additions & 6 deletions src/bridge/ISequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,30 @@ interface ISequencerInbox is IDelayedMessageProvider {
EigenDARollupUtils.BlobVerificationProof calldata blobVerificationProof,
IEigenDAServiceManager.BlobHeader calldata blobHeader,
uint256 afterDelayedMessagesRead,
IGasRefunder gasRefunder,
uint256 prevMessageCount,
uint256 newMessageCount
) external;

// ---------- onlyRollupOrOwner functions ----------

/**
* @notice Set the eigenda service manager contract
* @param newEigenDAServiceManager the new svc manager contract address
*/
function setEigenDAServiceManager(address newEigenDAServiceManager) external;

/**
* @notice Set the rollup manager contract address
* @param newRollupManager the new rollup manager contract address
*/
function setEigenDARollupManager(address newRollupManager) external;

/**
* @notice Set the new rollup contract address
*/
function setRollupAddress() external;


/**
* @notice Set max delay for sequencer inbox
* @param maxTimeVariation_ the maximum time variation parameters
Expand Down Expand Up @@ -242,11 +259,6 @@ interface ISequencerInbox is IDelayedMessageProvider {
/// @notice Allows the rollup owner to sync the rollup address
function updateRollupAddress() external;

/// @notice Allows the rollup owner to update the eigenDAServiceManager address
function updateEigenDAServiceManager(address newEigenDAServiceManager) external;

/// @notice Allows the rollup owner to update the eigenDARollupManager address
function updateEigenDARollupManager(address newEigenDARollupManager) external;

// ---------- initializer ----------

Expand Down
89 changes: 88 additions & 1 deletion src/bridge/RollupManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,93 @@ import {EigenDAHasher} from "@eigenda/eigenda-utils/libraries/EigenDAHasher.sol"
import {IEigenDAServiceManager} from "@eigenda/eigenda-utils/interfaces/IEigenDAServiceManager.sol";
import {BitmapUtils} from "@eigenda/eigenda-utils/libraries/BitmapUtils.sol";
import {EigenDARollupUtils} from "@eigenda/eigenda-utils/libraries/EigenDARollupUtils.sol";
import {IBLSSignatureChecker} from "@eigenda/eigenda-utils/interfaces/IBLSSignatureChecker.sol";
import {IPaymentCoordinator} from "@eigenda/eigenda-utils/interfaces/IPaymentCoordinator.sol";
import {ISignatureUtils} from "@eigenda/eigenda-utils/interfaces/ISignatureUtils.sol";


// DummyServiceManager is a dummy implementation of IEigenDAServiceManager
// and is used in nitro-testnode to avoid the overhead of deploying core EigenDA contracts
// to simplify the testing process.
contract DummyServiceManager is IEigenDAServiceManager {

constructor() {
}

function batchIdToBatchMetadataHash(uint32 batchId) external view override returns (bytes32) {
return bytes32(0);
}

function confirmBatch(
BatchHeader calldata batchHeader,
IBLSSignatureChecker.NonSignerStakesAndSignature memory nonSignerStakesAndSignature
) external override {
}

function setBatchConfirmer(address _batchConfirmer) external override {
}

function taskNumber() external view override returns (uint32) {
return 0;
}
function latestServeUntilBlock(uint32 referenceBlockNumber) external view override returns (uint32) {
return 0;
}
function BLOCK_STALE_MEASURE() external view override returns (uint32) {
return 0;
}

function quorumAdversaryThresholdPercentages() external view override returns (bytes memory) {
return "";
}

function quorumConfirmationThresholdPercentages() external view override returns (bytes memory) {
return "";
}

function quorumNumbersRequired() external view override returns (bytes memory) {
return "";
}

function payForRange(IPaymentCoordinator.RangePayment[] calldata rangePayments) external override {
return;
}

function updateAVSMetadataURI(string memory _metadataURI) external override {
return;
}

function registerOperatorToAVS(
address operator,
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature
) external override {
return;
}

function deregisterOperatorFromAVS(address operator) external override {
return;
}

function getOperatorRestakedStrategies(address operator) external view override returns (address[] memory){
address[] memory dummyAddresses = new address[](2);
dummyAddresses[0] = 0x0000000000000000000000000000000000000001;
dummyAddresses[1] = 0x0000000000000000000000000000000000000002;
return dummyAddresses;
}

function getRestakeableStrategies() external view override returns (address[] memory) {
address[] memory dummyAddresses = new address[](2);
dummyAddresses[0] = 0x0000000000000000000000000000000000000001;
dummyAddresses[1] = 0x0000000000000000000000000000000000000002;
return dummyAddresses;
}

function avsDirectory() external view returns (address) {
address x = 0x0000000000000000000000000000000000000001;
return x;
}

}

interface IRollupManager {

Expand All @@ -29,7 +114,9 @@ interface IRollupManager {

}


// EigenDADummyManager is a dummy implementation of IRollupManager
// and is used in nitro-testnode to avoid the overhead of deploying core EigenDA contracts
// to simplify the testing process.
contract EigenDADummyManager {

function verifyBlob(
Expand Down
41 changes: 25 additions & 16 deletions src/bridge/SequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox

IBridge public bridge;

IEigenDAServiceManager public eigenDAServiceManager;
IRollupManager public eigenDARollupManager;
address public eigenDAServiceManager;
address public eigenDARollupManager;

/// @inheritdoc ISequencerInbox
uint256 public constant HEADER_LENGTH = 40;
Expand Down Expand Up @@ -140,8 +140,6 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
constructor(
uint256 _maxDataSize,
IReader4844 reader4844_,
IEigenDAServiceManager eigenDAServiceManager_,
IRollupManager eigenDARollupManager_,
bool _isUsingFeeToken
) {
maxDataSize = _maxDataSize;
Expand All @@ -151,8 +149,6 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
if (reader4844_ == IReader4844(address(0))) revert InitParamZero("Reader4844");
}
reader4844 = reader4844_;
eigenDAServiceManager = eigenDAServiceManager_;
eigenDARollupManager = eigenDARollupManager_;
isUsingFeeToken = _isUsingFeeToken;
}

Expand Down Expand Up @@ -413,19 +409,22 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
submitBatchSpendingReport(dataHash, seqMessageIndex, block.basefee, blobGas);
}
}



function addSequencerL2BatchFromEigenDA(
uint256 sequenceNumber,
EigenDARollupUtils.BlobVerificationProof calldata blobVerificationProof,
IEigenDAServiceManager.BlobHeader calldata blobHeader,
uint256 afterDelayedMessagesRead,
IGasRefunder gasRefunder,
uint256 prevMessageCount,
uint256 newMessageCount
) external {
if (!isBatchPoster[msg.sender]) revert NotBatchPoster();

// verify that the blob was actually included before continuing
IRollupManager(eigenDARollupManager).verifyBlob(blobHeader, IEigenDAServiceManager(eigenDAServiceManager), blobVerificationProof);

eigenDARollupManager.verifyBlob(blobHeader, eigenDAServiceManager, blobVerificationProof);

// NOTE: to retrieve need the following
// see: https://github.com/Layr-Labs/eigenda/blob/master/api/docs/retriever.md#blobrequest
Expand Down Expand Up @@ -453,13 +452,14 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
}

emit SequencerBatchDelivered(
_sequenceNumber,
seqMessageIndex,
beforeAcc,
afterAcc,
delayedAcc,
totalDelayedMessagesRead,
timeBounds,
IBridge.BatchDataLocation.EigenDA

);
}

Expand Down Expand Up @@ -785,23 +785,32 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
}

/// @inheritdoc ISequencerInbox
function updateRollupAddress() external onlyRollupOwner {
function setRollupAddress() external onlyRollupOwner {
IOwnable newRollup = bridge.rollup();
if (rollup == newRollup) revert RollupNotChanged();
rollup = newRollup;
emit OwnerFunctionCalled(6);
}

/// @inheritdoc ISequencerInbox
function updateEigenDAServiceManager(address newEigenDAServiceManager) external onlyRollupOwner {
eigenDAServiceManager = IEigenDAServiceManager(newEigenDAServiceManager);
emit OwnerFunctionCalled(31);
function setEigenDAServiceManager(address newEigenDAServiceManager) external onlyRollupOwner {
eigenDAServiceManager = newEigenDAServiceManager;
emit OwnerFunctionCalled(7);
}

/// @inheritdoc ISequencerInbox
function updateEigenDARollupManager(address newEigenDARollupManager) external onlyRollupOwner {
eigenDARollupManager = IRollupManager(newEigenDARollupManager);
emit OwnerFunctionCalled(32);
function setEigenDARollupManager(address newRollupManager) external onlyRollupOwner {
eigenDARollupManager = newRollupManager;
emit OwnerFunctionCalled(8);
}

/// @notice Allows the rollup owner to sync the rollup address
function updateRollupAddress() external {
if (msg.sender != IOwnable(rollup).owner())
revert NotOwner(msg.sender, IOwnable(rollup).owner());
IOwnable newRollup = bridge.rollup();
if (rollup == newRollup) revert RollupNotChanged();
rollup = newRollup;
}

function isValidKeysetHash(bytes32 ksHash) external view returns (bool) {
Expand Down
4 changes: 1 addition & 3 deletions src/mocks/SequencerInboxStub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ contract SequencerInboxStub is SequencerInbox {
ISequencerInbox.MaxTimeVariation memory maxTimeVariation_,
uint256 maxDataSize_,
IReader4844 reader4844_,
IEigenDAServiceManager eigenDAServiceManager_,
IRollupManager eigenDARollupManager_,

bool isUsingFeeToken_
) SequencerInbox(maxDataSize_, reader4844_, eigenDAServiceManager_, eigenDARollupManager_, isUsingFeeToken_) {
) SequencerInbox(maxDataSize_, reader4844_, isUsingFeeToken_) {
bridge = bridge_;
rollup = IOwnable(msg.sender);
delayBlocks = uint64(maxTimeVariation_.delayBlocks);
Expand Down
2 changes: 1 addition & 1 deletion src/osp/OneStepProverHostIo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ contract OneStepProverHostIo is IOneStepProver {
} else if (inst.argumentData == 3) {
// The machine is asking for a EigenDA versioned hash preimage

require(proofType == 1, "UNKNOWN_PREIMAGE_PROOF");
require(proofType == 0, "UNKNOWN_EIGENDA_PREIMAGE_PROOF");

bytes calldata kzgProof = proof[proofOffset:];

Expand Down
6 changes: 6 additions & 0 deletions src/rollup/RollupCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ contract RollupCreator is Ownable {
//// @dev The address of the batch poster, not used when set to zero address
address[] batchPosters;
address batchPosterManager;
address eigenDAServiceManager;
address eigenDARollupManager;
}

BridgeCreator public bridgeCreator;
Expand Down Expand Up @@ -196,6 +198,10 @@ contract RollupCreator is Ownable {
bridgeContracts.sequencerInbox.setBatchPosterManager(deployParams.batchPosterManager);
}

// Setting EigenDAServiceManager and EigenDARollupManager
bridgeContracts.sequencerInbox.setEigenDAServiceManager(deployParams.eigenDAServiceManager);
bridgeContracts.sequencerInbox.setEigenDARollupManager(deployParams.eigenDARollupManager);

// Call setValidator on the newly created rollup contract just if validator set is not empty
if (deployParams.validators.length != 0) {
bool[] memory _vals = new bool[](deployParams.validators.length);
Expand Down
4 changes: 2 additions & 2 deletions test/foundry/BridgeCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ contract BridgeCreatorTest is Test {
BridgeCreator.BridgeContracts ethBasedTemplates =
BridgeCreator.BridgeContracts({
bridge: new Bridge(),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, dummyEigenDAServiceManager, rollupManager, false),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false),
inbox: new Inbox(MAX_DATA_SIZE),
rollupEventInbox: new RollupEventInbox(),
outbox: new Outbox()
});
BridgeCreator.BridgeContracts erc20BasedTemplates =
BridgeCreator.BridgeContracts({
bridge: new ERC20Bridge(),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, dummyEigenDAServiceManager, rollupManager, true),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true),
inbox: new ERC20Inbox(MAX_DATA_SIZE),
rollupEventInbox: new ERC20RollupEventInbox(),
outbox: new ERC20Outbox()
Expand Down
Loading

0 comments on commit 4395fa7

Please sign in to comment.