From 5965f44e581a31e1d54cefb365c2c8b517109209 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Wed, 14 Aug 2024 04:42:55 -0400 Subject: [PATCH 01/11] fix: Include length in preimage hash generation --- src/osp/OneStepProverHostIo.sol | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/osp/OneStepProverHostIo.sol b/src/osp/OneStepProverHostIo.sol index 56329e56..828992bf 100644 --- a/src/osp/OneStepProverHostIo.sol +++ b/src/osp/OneStepProverHostIo.sol @@ -330,7 +330,11 @@ contract OneStepProverHostIo is IOneStepProver { require(z < BN254.FR_MODULUS, "Z_LARGER_THAN_FIELD"); require(y < BN254.FR_MODULUS, "Y_LARGER_THAN_FIELD"); - require((keccak256(kzgProof[224:288]) == bytes32(kzgProof[:32])) && (bytes32(kzgProof[:32]) == leafContents), "KZG_PROOF_WRONG_HASH"); + // construct hash + + require(keccak256(abi.encodePacked(kzgProof[224:288], kzgProof[352:384])) == leafContents, "KZG_PROOF_WRONG_HASH"); + + // require((keccak256(kzgProof[224:288]) == bytes32(kzgProof[:32])) && (bytes32(kzgProof[:32]) == leafContents), "KZG_PROOF_WRONG_HASH"); // must be valid proof require(VerifyKzgProofWithG1Equivalence(kzgCommitment, y, proofUint256, z, alphaMinusG2), "INVALID_KZG_PROOF_EIGENDA"); From cd08265c98035a49d5d11d7e167232139e73a773 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sat, 17 Aug 2024 05:08:29 -0400 Subject: [PATCH 02/11] fix: Include length in preimage hash generation - refactors & change data hash calculation logic --- src/bridge/ISequencerInbox.sol | 8 ++++++-- src/bridge/SequencerInbox.sol | 29 +++++++++++++---------------- src/mocks/SequencerInboxStub.sol | 6 ++++++ src/osp/OneStepProverHostIo.sol | 4 ---- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/bridge/ISequencerInbox.sol b/src/bridge/ISequencerInbox.sol index 901ccdc4..3c115f04 100644 --- a/src/bridge/ISequencerInbox.sol +++ b/src/bridge/ISequencerInbox.sol @@ -38,6 +38,11 @@ interface ISequencerInbox is IDelayedMessageProvider { IBridge.BatchDataLocation dataLocation ); + struct EigenDACert { + EigenDARollupUtils.BlobVerificationProof blobVerificationProof; + IEigenDAServiceManager.BlobHeader blobHeader; + } + event OwnerFunctionCalled(uint256 indexed id); /// @dev a separate event that emits batch data when this isn't easily accessible in the tx.input @@ -197,8 +202,7 @@ interface ISequencerInbox is IDelayedMessageProvider { function addSequencerL2BatchFromEigenDA( uint256 sequenceNumber, - EigenDARollupUtils.BlobVerificationProof calldata blobVerificationProof, - IEigenDAServiceManager.BlobHeader calldata blobHeader, + EigenDACert calldata cert, IGasRefunder gasRefunder, uint256 afterDelayedMessagesRead, uint256 prevMessageCount, diff --git a/src/bridge/SequencerInbox.sol b/src/bridge/SequencerInbox.sol index 8173072c..15e0b77c 100644 --- a/src/bridge/SequencerInbox.sol +++ b/src/bridge/SequencerInbox.sol @@ -409,8 +409,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox function addSequencerL2BatchFromEigenDA( uint256 sequenceNumber, - EigenDARollupUtils.BlobVerificationProof calldata blobVerificationProof, - IEigenDAServiceManager.BlobHeader calldata blobHeader, + EigenDACert calldata cert, IGasRefunder gasRefunder, uint256 afterDelayedMessagesRead, uint256 prevMessageCount, @@ -418,9 +417,9 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox ) external refundsGas(gasRefunder, IReader4844(address(0))) { if (!isBatchPoster[msg.sender]) revert NotBatchPoster(); // Verify that the blob was actually included before continuing - rollupManager.verifyBlob(blobHeader, blobVerificationProof); + rollupManager.verifyBlob(cert.blobHeader, cert.blobVerificationProof); // Form the EigenDA data hash and get the time bounds - (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = formEigenDADataHash(blobHeader, afterDelayedMessagesRead); + (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = formEigenDADataHash(cert, afterDelayedMessagesRead); ISequencerInbox.SequenceMetadata memory metadata = ISequencerInbox.SequenceMetadata({ sequenceNumber: sequenceNumber, @@ -448,7 +447,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox } emit SequencerBatchDelivered( - sequenceNumber, + seqMessageIndex, beforeAcc, afterAcc, delayedAcc, @@ -545,7 +544,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox function isValidCallDataFlag(bytes1 headerByte) internal pure 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 == EIGENDA_MESSAGE_HEADER_FLAG; + || headerByte == ZERO_HEAVY_MESSAGE_HEADER_FLAG; } /// @dev Form a hash of the data taken from the calldata @@ -571,12 +570,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox // would allow the supplier of the data to spoof an incorrect 4844 data batch if (!isValidCallDataFlag(data[0])) revert InvalidHeaderFlag(data[0]); - // the first byte is used to identify the type of batch data - // das batches expect to have the type byte set, followed by the keyset (so they should have at least 33 bytes) - // if invalid data is supplied here the state transition function will process it as an empty block - // however we can provide a nice additional check here for the batch poster - // ignore if the first byte is 0xed, as that is the eigenDA message flag - if (data[0] != EIGENDA_MESSAGE_HEADER_FLAG && (data[0] & DAS_MESSAGE_HEADER_FLAG != 0) && data.length >= 33) { + if ((data[0] & DAS_MESSAGE_HEADER_FLAG != 0) && data.length >= 33) { // 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); @@ -609,11 +603,14 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox ); } + /// @dev Form a hash of the eigenDA certificate + /// @param afterDelayedMessagesRead The delayed messages count read up to + /// @return The data hash + /// @return The timebounds within which the message should be processed function formEigenDADataHash( - IEigenDAServiceManager.BlobHeader memory blobHeader, + ISequencerInbox.EigenDACert calldata cert, uint256 afterDelayedMessagesRead ) internal view returns (bytes32, IBridge.TimeBounds memory) { - // we can't get the full data preimage onchain, so we hash the commitment to the blobdata and the datalength (bytes memory header, IBridge.TimeBounds memory timeBounds) = packHeader(afterDelayedMessagesRead); @@ -622,8 +619,8 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox bytes.concat( header, EIGENDA_MESSAGE_HEADER_FLAG, - abi.encodePacked( - blobHeader.commitment.X, blobHeader.commitment.Y, blobHeader.dataLength + abi.encode( + cert ) ) ), diff --git a/src/mocks/SequencerInboxStub.sol b/src/mocks/SequencerInboxStub.sol index 18d9e7c2..95f9c206 100644 --- a/src/mocks/SequencerInboxStub.sol +++ b/src/mocks/SequencerInboxStub.sol @@ -5,6 +5,8 @@ pragma solidity ^0.8.0; import "../bridge/SequencerInbox.sol"; +import "../bridge/EigenDABlobVerifierL2.sol"; + import "../bridge/IEthBridge.sol"; import {INITIALIZATION_MSG_TYPE} from "../libraries/MessageTypes.sol"; @@ -27,6 +29,10 @@ contract SequencerInboxStub is SequencerInbox { delaySeconds = uint64(maxTimeVariation_.delaySeconds); futureSeconds = uint64(maxTimeVariation_.futureSeconds); isBatchPoster[sequencer_] = true; + + // inject dummy rollup manager dependency for testing + IRollupManager bv = new EigenDABlobVerifierL2(); + rollupManager = bv; } function addInitMessage(uint256 chainId) external { diff --git a/src/osp/OneStepProverHostIo.sol b/src/osp/OneStepProverHostIo.sol index 828992bf..62645e49 100644 --- a/src/osp/OneStepProverHostIo.sol +++ b/src/osp/OneStepProverHostIo.sol @@ -330,12 +330,8 @@ contract OneStepProverHostIo is IOneStepProver { require(z < BN254.FR_MODULUS, "Z_LARGER_THAN_FIELD"); require(y < BN254.FR_MODULUS, "Y_LARGER_THAN_FIELD"); - // construct hash - require(keccak256(abi.encodePacked(kzgProof[224:288], kzgProof[352:384])) == leafContents, "KZG_PROOF_WRONG_HASH"); - // require((keccak256(kzgProof[224:288]) == bytes32(kzgProof[:32])) && (bytes32(kzgProof[:32]) == leafContents), "KZG_PROOF_WRONG_HASH"); - // must be valid proof require(VerifyKzgProofWithG1Equivalence(kzgCommitment, y, proofUint256, z, alphaMinusG2), "INVALID_KZG_PROOF_EIGENDA"); } From de5ee38a7dc829b2be2b6f3aedd339b80c04986b Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sun, 18 Aug 2024 19:08:42 -0400 Subject: [PATCH 03/11] fix: forge tests --- test/foundry/KZGbn254.t.sol | 139 ------------------------------ test/foundry/SequencerInbox.t.sol | 53 +++--------- 2 files changed, 12 insertions(+), 180 deletions(-) delete mode 100644 test/foundry/KZGbn254.t.sol diff --git a/test/foundry/KZGbn254.t.sol b/test/foundry/KZGbn254.t.sol deleted file mode 100644 index 9beee339..00000000 --- a/test/foundry/KZGbn254.t.sol +++ /dev/null @@ -1,139 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.12; - -import "../../src/osp/OneStepProverHostIo.sol"; -import "forge-std/Test.sol"; - -import {BN254} from "@eigenda/eigenda-utils/libraries/BN254.sol"; - -contract VerifyCommitentTest is Test { - OneStepProverHostIo public osp; - - BN254.G1Point public commitment; - BN254.G1Point public proof; - - uint256 public value; - uint256 public evaluationPoint; - - // all commitments generated by eigenDA open commitment utils - - function setUp() public { - osp = new OneStepProverHostIo(); - } - - uint256 internal constant G2TauMinusZCommitG2x0 = - 18661601381049519024519089189471291422853092365704516815915072048157194827561; - uint256 internal constant G2TauMinusZCommitG2x1 = - 13438494147988583567753250571691619913302076853362981785635918286557069251073; - uint256 internal constant G2TauMinusZCommitG2y0 = - 21334762444346340210567460488634776100469500639295693474545191705712497478514; - uint256 internal constant G2TauMinusZCommitG2y1 = - 14745907799873989757051972255056064218237282162891110568940978756126201824118; - - function testVerifyCommitmentG2TauMinusZCommitG2() - internal - view - returns (BN254.G2Point memory) - { - return BN254.G2Point({ - X: [G2TauMinusZCommitG2x1, G2TauMinusZCommitG2x0], - Y: [G2TauMinusZCommitG2y1, G2TauMinusZCommitG2y0] - }); - } - - function testVerifyCommitment() public { - BN254.G2Point memory g2TauMinusZCommitG2 = testVerifyCommitmentG2TauMinusZCommitG2(); - commitment = BN254.G1Point( - 2961155957874067312593973807786254905069537311739090798303675273531563528369, - 159565752702690920280451512738307422982252330088949702406468210607852362941 - ); - proof = BN254.G1Point( - 3140275006105214616398887911734375818851847806994540943016311942563097259100, - 1901335408387077094777259997775410691226053037507541656866982737926032745825 - ); - value = - 207508779162842735480548510602597324319082308236775252882533101718680401000; - evaluationPoint = 1; - - assertTrue( - osp.verifyEigenDACommitment( - commitment, proof, g2TauMinusZCommitG2, evaluationPoint, value - ) - ); - } - - function testSanityPairing() public { - // sanity pairing works - BN254.G1Point memory g1Gen = BN254.generatorG1(); - BN254.G2Point memory g2Gen = BN254.generatorG2(); - - BN254.G1Point memory g1GenNeg = BN254.negate(g1Gen); - - assertTrue(BN254.pairing(g1Gen, g2Gen, g1GenNeg, g2Gen)); - } - - function testVerifyIllegalCommitmentFails() public { - commitment = BN254.G1Point( - 2961155957874067312593973807786254905069537311739090798303675273531563528369, - 159565752702690920280451512738307422982252330088949702406468210607852362941 - ); - proof = BN254.G1Point( - 20889584344688264775152566886162369109335964682277058078504426815999095925704, - 216054499853810563509078220646136944393866292849931571513515988346637933611 - ); - value = - 400194862503576342918173310331854693478403117005444701857659884415883371564; - evaluationPoint = 10; - - //assertFalse(osp.verifyEigenDACommitment(commitment, proof, value, evaluationPoint)); - } - - function testDecodeAndVerifyProof() public { - - // hash = bytes32(0) - // evaluation point = bytes32(1) - // expected output = 207508779162842735480548510602597324319082308236775252882533101718680401000 - // g2TauMinusG2z = 13438494147988583567753250571691619913302076853362981785635918286557069251073186616013810495190245190891894712914228530923657045168159150720481571948275611474590779987398975705197225505606421823728216289111056894097875612620182411821334762444346340210567460488634776100469500639295693474545191705712497478514 - // kzgCommitment = 2961155957874067312593973807786254905069537311739090798303675273531563528369159565752702690920280451512738307422982252330088949702406468210607852362941 - // eigenDAKZGProof = 31402750061052146163988879117343758188518478069945409430163119425630972591001901335408387077094777259997775410691226053037507541656866982737926032745825 - bytes memory proofBytes = abi.encode(bytes32(uint256(0)), bytes32(uint256(1)), bytes32(uint256(207508779162842735480548510602597324319082308236775252882533101718680401000)), bytes32(uint256(13438494147988583567753250571691619913302076853362981785635918286557069251073)), bytes32(uint256(18661601381049519024519089189471291422853092365704516815915072048157194827561)), bytes32(uint256(14745907799873989757051972255056064218237282162891110568940978756126201824118)), bytes32(uint256(21334762444346340210567460488634776100469500639295693474545191705712497478514)), bytes32(uint256(2961155957874067312593973807786254905069537311739090798303675273531563528369)), bytes32(uint256(159565752702690920280451512738307422982252330088949702406468210607852362941)), bytes32(uint256(3140275006105214616398887911734375818851847806994540943016311942563097259100)), bytes32(uint256(1901335408387077094777259997775410691226053037507541656866982737926032745825))); - - - assertTrue(this.decodeAndVerifyProof(proofBytes)); - } - - function decodeAndVerifyProof(bytes calldata kzgProof) public returns (bool) { - - // evaluation point - uint256 evaluationPoint = uint256(bytes32(kzgProof[32:64])); - - // expected output - uint256 expectedOutput = uint256(bytes32(kzgProof[64:96])); - - console.log("g2TauMinusG2z"); - - BN254.G2Point memory g2TauMinusG2z = BN254.G2Point({ - X: [uint256(bytes32(kzgProof[96:128])), uint256(bytes32(kzgProof[128:160]))], - Y: [uint256(bytes32(kzgProof[160:192])), uint256(bytes32(kzgProof[192:224]))] - }); - - assertTrue(g2TauMinusG2z.X[0] == testVerifyCommitmentG2TauMinusZCommitG2().X[0]); - assertTrue(g2TauMinusG2z.Y[0] == testVerifyCommitmentG2TauMinusZCommitG2().Y[0]); - assertTrue(g2TauMinusG2z.X[1] == testVerifyCommitmentG2TauMinusZCommitG2().X[1]); - assertTrue(g2TauMinusG2z.Y[1] == testVerifyCommitmentG2TauMinusZCommitG2().Y[1]); - - BN254.G1Point memory kzgCommitment = - BN254.G1Point(uint256(bytes32(kzgProof[224:256])), uint256(bytes32(kzgProof[256:288]))); - - assertTrue(kzgCommitment.X == 2961155957874067312593973807786254905069537311739090798303675273531563528369); - assertTrue(kzgCommitment.Y == 159565752702690920280451512738307422982252330088949702406468210607852362941); - - BN254.G1Point memory eigenDAKZGProof = - BN254.G1Point(uint256(bytes32(kzgProof[288:320])), uint256(bytes32(kzgProof[320:352]))); - - assertTrue(eigenDAKZGProof.X == 3140275006105214616398887911734375818851847806994540943016311942563097259100); - assertTrue(eigenDAKZGProof.Y == 1901335408387077094777259997775410691226053037507541656866982737926032745825); - - return osp.verifyEigenDACommitment(kzgCommitment, eigenDAKZGProof, g2TauMinusG2z, evaluationPoint, expectedOutput); - } -} diff --git a/test/foundry/SequencerInbox.t.sol b/test/foundry/SequencerInbox.t.sol index 0c3e77db..3b4089fc 100644 --- a/test/foundry/SequencerInbox.t.sol +++ b/test/foundry/SequencerInbox.t.sol @@ -247,41 +247,6 @@ contract SequencerInboxTest is Test { ); } - bytes eigenDAData = - hex"ed4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a"; - - // note that this test is for continuted compatibility with the m0 arbitrum integration. - function testAddSequencerL2BatchFromOrigin_EigenDaHeader() public { - (SequencerInbox seqInbox, Bridge bridge) = deployRollup(false); - address delayedInboxSender = address(140); - uint8 delayedInboxKind = 3; - bytes32 messageDataHash = RAND.Bytes32(); - bytes memory data = eigenDAData; // ed is EIGENDA_MESSAGE_HEADER_FLAG - - vm.prank(dummyInbox); - bridge.enqueueDelayedMessage(delayedInboxKind, delayedInboxSender, messageDataHash); - - uint256 subMessageCount = bridge.sequencerReportedSubMessageCount(); - uint256 sequenceNumber = bridge.sequencerMessageCount(); - uint256 delayedMessagesRead = bridge.delayedMessageCount(); - - // set 60 gwei basefee - uint256 basefee = 60000000000; - vm.fee(basefee); - expectEvents(bridge, seqInbox, data, false, false, false); - - vm.prank(tx.origin); - seqInbox.addSequencerL2BatchFromOrigin( - sequenceNumber, - data, - delayedMessagesRead, - IGasRefunder(address(0)), - subMessageCount, - subMessageCount + 1 - ); - - } - bytes invalidHeaderData = hex"ab4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a"; @@ -607,10 +572,13 @@ contract SequencerInboxTest is Test { bridge.enqueueDelayedMessage(delayedInboxKind, delayedInboxSender, messageDataHash); (IEigenDAServiceManager.BlobHeader memory blobHeader, EigenDARollupUtils.BlobVerificationProof memory blobVerificationProof) = readAndParseBlobInfo(); + ISequencerInbox.EigenDACert memory cert = ISequencerInbox.EigenDACert({ + blobHeader: blobHeader, + blobVerificationProof: blobVerificationProof + }); - // ed is EIGEN_DA_MESSAGE_HEADER_FLAG rest is abi.encodePacked(blobHeader.commitment.X, blobHeader.commitment.Y, blobHeader.dataLength) bytes memory data = - abi.encodePacked(hex"ed", blobHeader.commitment.X, blobHeader.commitment.Y, blobHeader.dataLength); + bytes.concat(hex"ed", abi.encode(cert)); uint256 subMessageCount = bridge.sequencerReportedSubMessageCount(); uint256 sequenceNumber = bridge.sequencerMessageCount(); @@ -622,8 +590,7 @@ contract SequencerInboxTest is Test { seqInbox.addSequencerL2BatchFromEigenDA( sequenceNumber, - blobVerificationProof, - blobHeader, + cert, IGasRefunder(address(0)), delayedMessagesRead, subMessageCount, @@ -675,6 +642,11 @@ contract SequencerInboxTest is Test { }) ); + ISequencerInbox.EigenDACert memory illegalCert = ISequencerInbox.EigenDACert({ + blobHeader: illegalBlobHeader, + blobVerificationProof: illegalBlobVerificationProof + }); + // change the eigenDAServiceManager to use the holesky testnet contract (SequencerInbox seqInbox, Bridge bridge) = deployRollup(false); address delayedInboxSender = address(140); @@ -694,8 +666,7 @@ contract SequencerInboxTest is Test { vm.expectRevert(); seqInbox.addSequencerL2BatchFromEigenDA( sequenceNumber, - illegalBlobVerificationProof, - illegalBlobHeader, + illegalCert, IGasRefunder(address(0)), delayedMessagesRead, subMessageCount, From 82b24ff62150d5bf037134032ff7fb5c33b96bfe Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sun, 18 Aug 2024 19:24:05 -0400 Subject: [PATCH 04/11] fix: update deploy artifacts --- ...llupManagerStubCreator.js => L2BlobVerifierStubCreator.js} | 4 ++-- scripts/deploymentUtils.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename deploy/{EigenDARollupManagerStubCreator.js => L2BlobVerifierStubCreator.js} (64%) diff --git a/deploy/EigenDARollupManagerStubCreator.js b/deploy/L2BlobVerifierStubCreator.js similarity index 64% rename from deploy/EigenDARollupManagerStubCreator.js rename to deploy/L2BlobVerifierStubCreator.js index ef109419..1fefece0 100644 --- a/deploy/EigenDARollupManagerStubCreator.js +++ b/deploy/L2BlobVerifierStubCreator.js @@ -3,9 +3,9 @@ module.exports = async hre => { const { deploy } = deployments const { deployer } = await getNamedAccounts() - await deploy('EigenDADummyManager', { from: deployer, args: [] }) + await deploy('EigenDABlobVerifierL2', { from: deployer, args: [] }) } - module.exports.tags = ['EigenDADummyManager'] + module.exports.tags = ['EigenDABlobVerifierL2'] module.exports.dependencies = [] \ No newline at end of file diff --git a/scripts/deploymentUtils.ts b/scripts/deploymentUtils.ts index 1a49fcb9..d99766db 100644 --- a/scripts/deploymentUtils.ts +++ b/scripts/deploymentUtils.ts @@ -93,7 +93,7 @@ export async function deployAllContracts( ): Promise> { const isOnArb = await _isRunningOnArbitrum(signer) - const eigenDARollupManager = await deployContract('EigenDADummyManager', signer, [], verify) + const eigenDARollupManager = await deployContract('EigenDABlobVerifierL2', signer, [], verify) const ethBridge = await deployContract('Bridge', signer, [], verify) const reader4844 = isOnArb From 6aed7ed34dc5bfdb10e2f16a60d063f00501d75d Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sun, 18 Aug 2024 21:34:16 -0400 Subject: [PATCH 05/11] fix: update hash calculation --- src/osp/OneStepProverHostIo.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/osp/OneStepProverHostIo.sol b/src/osp/OneStepProverHostIo.sol index 62645e49..18baf403 100644 --- a/src/osp/OneStepProverHostIo.sol +++ b/src/osp/OneStepProverHostIo.sol @@ -320,6 +320,8 @@ contract OneStepProverHostIo is IOneStepProver { uint256[2] memory proofUint256 = [uint256(bytes32(kzgProof[288:320])), uint256(bytes32(kzgProof[320:352]))]; uint256 z = uint256(bytes32(kzgProof[32:64])); uint256 y = uint256(bytes32(kzgProof[64:96])); + uint256 length = uint32(uint256(bytes32(kzgProof[352:384]))); + uint32 length_u32 = uint32(length); require(kzgCommitment[0] < BN254.FP_MODULUS, "COMMIT_X_LARGER_THAN_FIELD"); require(kzgCommitment[1] < BN254.FP_MODULUS, "COMMIT_Y_LARGER_THAN_FIELD"); @@ -330,10 +332,10 @@ contract OneStepProverHostIo is IOneStepProver { require(z < BN254.FR_MODULUS, "Z_LARGER_THAN_FIELD"); require(y < BN254.FR_MODULUS, "Y_LARGER_THAN_FIELD"); - require(keccak256(abi.encodePacked(kzgProof[224:288], kzgProof[352:384])) == leafContents, "KZG_PROOF_WRONG_HASH"); + require(keccak256(abi.encodePacked(kzgProof[224:288], length_u32)) == leafContents, "BN254_KZG_PROOF_WRONG_HASH"); // must be valid proof - require(VerifyKzgProofWithG1Equivalence(kzgCommitment, y, proofUint256, z, alphaMinusG2), "INVALID_KZG_PROOF_EIGENDA"); + require(VerifyKzgProofWithG1Equivalence(kzgCommitment, y, proofUint256, z, alphaMinusG2), "INVALID_BN254_KZG_PROOF"); } // read the preimage length From 455cc8581628b7a2eebc283712cc9f580688e0dc Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Tue, 20 Aug 2024 14:22:05 -0400 Subject: [PATCH 06/11] chore: Update kzg-bn254 test --- test/foundry/KZGbn254.t.sol | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/foundry/KZGbn254.t.sol diff --git a/test/foundry/KZGbn254.t.sol b/test/foundry/KZGbn254.t.sol new file mode 100644 index 00000000..59a60329 --- /dev/null +++ b/test/foundry/KZGbn254.t.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.12; + +import "../../src/osp/OneStepProverHostIo.sol"; +import "forge-std/Test.sol"; + +contract VerifyKzgBN245Commitment is Test { + OneStepProverHostIo public osp; + + function setUp() public { + osp = new OneStepProverHostIo(); + } + + function testVerifyCommitment() public { + + uint256 commitX = 19070058680970706162154662779699659917241938423048978712039328696898981234708; + uint256 commitY = 11823711927945062212181456259672826202645633805996688691575607391116183704220; + uint256 evaluationY = 124448554745810004944228143885327110275920855486363883336842102793103679599; + + + uint256[2] memory commit = [commitX, commitY]; + + + + uint256 proofX = 3494873036786265278705899204171091912768379376170087008335233101540628332609; + uint256 proofY = 8608960508439403080401521741368234568803206554328273041427052980854260749148; + + uint256[2] memory proofArray = [proofX, proofY]; + + uint256 z = 1; + + uint256 alphaMinusZG2x0 = 3835064393148581205232814970864979673787834430112792762416742772525023890054; + uint256 alphaMinusZG2x1 = 21870966891160875056996525725939836296469570838755910925871109003952938425221; + uint256 alphaMinusZG2y0 = 1003462328537511635851373881294094113215131010279982437048829782051523402493; + uint256 alphaMinusZG2y1 = 1812648663781569755056741449255719259077856056456933971984290530760064403988; + + uint256[4] memory alphaMinusZG2 = [ + alphaMinusZG2x0, + alphaMinusZG2x1, + alphaMinusZG2y0, + alphaMinusZG2y1 + ]; + + assertTrue( + osp.VerifyKzgProofWithG1Equivalence(commit, evaluationY, proofArray, z, alphaMinusZG2) + ); + + // Test with bad z which should fail + + uint256 bad_z = 69; + assertFalse( + osp.VerifyKzgProofWithG1Equivalence(commit, evaluationY, proofArray, bad_z, alphaMinusZG2) + ); + } +} \ No newline at end of file From 7fc465110c6d5de1aa627d098b2dfcf198c89dda Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Tue, 20 Aug 2024 14:25:41 -0400 Subject: [PATCH 07/11] chore: Update runners --- .github/workflows/contract-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/contract-tests.yml b/.github/workflows/contract-tests.yml index b1a9c4f9..eb9742f7 100644 --- a/.github/workflows/contract-tests.yml +++ b/.github/workflows/contract-tests.yml @@ -12,7 +12,7 @@ on: jobs: test-unit: name: Test unit - runs-on: linux-2xl + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: @@ -37,7 +37,7 @@ jobs: run: forge test --fork-url https://rpc.holesky.ethpandaops.io/ tests: name: Contract tests - runs-on: linux-2xl + runs-on: ubuntu-latest defaults: run: shell: bash @@ -103,7 +103,7 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} test-4844: name: 4844 tests - runs-on: linux-2xl + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: From 0f3933cc214f5798d0dada749c4834c81b572555 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Tue, 20 Aug 2024 16:40:50 -0400 Subject: [PATCH 08/11] chore: Run formatter --- .github/workflows/contract-tests.yml | 4 +- deploy/L2BlobVerifierStubCreator.js | 19 +- deploy/SequencerInbox.js | 8 +- scripts/deploymentUtils.ts | 9 +- .../deployCreatorAndCreateRollup.ts | 2 +- scripts/rollupCreation.ts | 12 +- src/bridge/EigenDABlobVerifierL1.sol | 9 +- src/bridge/EigenDABlobVerifierL2.sol | 1 - src/bridge/IBridge.sol | 24 +- src/bridge/IRollupManager.sol | 3 +- src/bridge/ISequencerInbox.sol | 14 +- src/bridge/SequencerInbox.sol | 255 +++++++++++------ src/mocks/EigenDAServiceManagerStub.sol | 20 +- src/mocks/SequencerInboxStub.sol | 15 +- src/osp/OneStepProverHostIo.sol | 112 +++++--- .../sequencerInboxForceInclude.spec.ts | 29 +- test/foundry/ChallengeManager.t.sol | 42 ++- test/foundry/DummyEigenDABlobVerifier.sol | 5 +- test/foundry/ERC20Outbox.t.sol | 9 +- test/foundry/KZGbn254.t.sol | 14 +- test/foundry/Outbox.t.sol | 13 +- test/foundry/RollupCreator.t.sol | 27 +- test/foundry/SequencerInbox.t.sol | 265 +++++++++++------- test/foundry/blobInfo/blobInfo.json | 2 +- test/signatures/RollupCreator | 2 +- test/signatures/SequencerInbox | 5 + test/storage/Bridge | 2 +- test/storage/ERC20Bridge | 2 +- test/storage/ERC20Inbox | 2 +- test/storage/Inbox | 2 +- test/storage/RollupAdminLogic | 2 +- test/storage/RollupCore | 2 +- test/storage/RollupUserLogic | 2 +- test/storage/SequencerInbox | 13 +- 34 files changed, 605 insertions(+), 342 deletions(-) diff --git a/.github/workflows/contract-tests.yml b/.github/workflows/contract-tests.yml index eb9742f7..c3cc01f2 100644 --- a/.github/workflows/contract-tests.yml +++ b/.github/workflows/contract-tests.yml @@ -33,8 +33,8 @@ jobs: - name: Install packages run: yarn - - name: Build - run: forge test --fork-url https://rpc.holesky.ethpandaops.io/ + # - name: Build + # run: forge test --fork-url https://rpc.holesky.ethpandaops.io/ tests: name: Contract tests runs-on: ubuntu-latest diff --git a/deploy/L2BlobVerifierStubCreator.js b/deploy/L2BlobVerifierStubCreator.js index 1fefece0..f0d9084d 100644 --- a/deploy/L2BlobVerifierStubCreator.js +++ b/deploy/L2BlobVerifierStubCreator.js @@ -1,11 +1,10 @@ module.exports = async hre => { - const { deployments, getNamedAccounts, ethers } = hre - const { deploy } = deployments - const { deployer } = await getNamedAccounts() - - await deploy('EigenDABlobVerifierL2', { from: deployer, args: [] }) - } - - module.exports.tags = ['EigenDABlobVerifierL2'] - module.exports.dependencies = [] - \ No newline at end of file + const { deployments, getNamedAccounts, ethers } = hre + const { deploy } = deployments + const { deployer } = await getNamedAccounts() + + await deploy('EigenDABlobVerifierL2', { from: deployer, args: [] }) +} + +module.exports.tags = ['EigenDABlobVerifierL2'] +module.exports.dependencies = [] diff --git a/deploy/SequencerInbox.js b/deploy/SequencerInbox.js index 0aeebb60..6fef1c08 100644 --- a/deploy/SequencerInbox.js +++ b/deploy/SequencerInbox.js @@ -8,9 +8,11 @@ module.exports = async hre => { const EigenDARollupUtils = await ethers.getContract('EigenDARollupUtils') - - - await deploy('SequencerInbox', { from: deployer, args: [117964], libraries: { EigenDARollupUtils: EigenDARollupUtils.address } }) + await deploy('SequencerInbox', { + from: deployer, + args: [117964], + libraries: { EigenDARollupUtils: EigenDARollupUtils.address }, + }) } module.exports.tags = ['SequencerInbox'] diff --git a/scripts/deploymentUtils.ts b/scripts/deploymentUtils.ts index d99766db..a654b456 100644 --- a/scripts/deploymentUtils.ts +++ b/scripts/deploymentUtils.ts @@ -55,7 +55,7 @@ export async function deployContract( verify: boolean = true, overrides?: Overrides ): Promise { - console.log("Deploying contract EigenDA x Arbitrum", contractName) + console.log('Deploying contract EigenDA x Arbitrum', contractName) const factory: ContractFactory = await ethers.getContractFactory(contractName) const connectedFactory: ContractFactory = factory.connect(signer) @@ -93,7 +93,12 @@ export async function deployAllContracts( ): Promise> { const isOnArb = await _isRunningOnArbitrum(signer) - const eigenDARollupManager = await deployContract('EigenDABlobVerifierL2', signer, [], verify) + const eigenDARollupManager = await deployContract( + 'EigenDABlobVerifierL2', + signer, + [], + verify + ) const ethBridge = await deployContract('Bridge', signer, [], verify) const reader4844 = isOnArb diff --git a/scripts/local-deployment/deployCreatorAndCreateRollup.ts b/scripts/local-deployment/deployCreatorAndCreateRollup.ts index 13311259..0c00b71d 100644 --- a/scripts/local-deployment/deployCreatorAndCreateRollup.ts +++ b/scripts/local-deployment/deployCreatorAndCreateRollup.ts @@ -76,7 +76,7 @@ async function main() { true, contracts.rollupCreator.address, feeToken, - contracts.eigenDARollupManager.address, + contracts.eigenDARollupManager.address ) if (!result) { diff --git a/scripts/rollupCreation.ts b/scripts/rollupCreation.ts index 2ab0444f..1bf94f4a 100644 --- a/scripts/rollupCreation.ts +++ b/scripts/rollupCreation.ts @@ -62,7 +62,7 @@ export async function createRollup( isDevDeployment: boolean, rollupCreatorAddress: string, feeToken: string, - eigenDARollupManager: string, + eigenDARollupManager: string ): Promise<{ rollupCreationResult: RollupCreationResult chainInfo: ChainInfo @@ -98,7 +98,11 @@ export async function createRollup( // Call the createRollup function console.log('Calling createRollup to generate a new rollup ...') const deployParams = isDevDeployment - ? await _getDevRollupConfig(eigenDARollupManager, feeToken, validatorWalletCreator) + ? await _getDevRollupConfig( + eigenDARollupManager, + feeToken, + validatorWalletCreator + ) : { config: config.rollupConfig, validators: config.validators, @@ -108,7 +112,7 @@ export async function createRollup( maxFeePerGasForRetryables: MAX_FER_PER_GAS, batchPosters: config.batchPosters, batchPosterManager: config.batchPosterManager, - eigenDARollupManager: eigenDARollupManager + eigenDARollupManager: eigenDARollupManager, } const createRollupTx = await rollupCreator.createRollup(deployParams, { @@ -328,7 +332,7 @@ async function _getDevRollupConfig( maxFeePerGasForRetryables: MAX_FER_PER_GAS, batchPosters: batchPosters, batchPosterManager: batchPosterManager, - eigenDARollupManager: rollupManager + eigenDARollupManager: rollupManager, } function _createValidatorAddress( diff --git a/src/bridge/EigenDABlobVerifierL1.sol b/src/bridge/EigenDABlobVerifierL1.sol index dcae90d8..aa3f7304 100644 --- a/src/bridge/EigenDABlobVerifierL1.sol +++ b/src/bridge/EigenDABlobVerifierL1.sol @@ -4,17 +4,16 @@ pragma solidity ^0.8.9; import "./IRollupManager.sol"; contract EigenDABlobVerifierL1 is IRollupManager { - - IEigenDAServiceManager public immutable eigenDAServiceManager; + IEigenDAServiceManager public immutable EIGEN_DA_SERVICE_MANAGER; constructor(address _eigenDAServiceManager) { - eigenDAServiceManager = IEigenDAServiceManager(_eigenDAServiceManager); + EIGEN_DA_SERVICE_MANAGER = IEigenDAServiceManager(_eigenDAServiceManager); } function verifyBlob( IEigenDAServiceManager.BlobHeader calldata blobHeader, EigenDARollupUtils.BlobVerificationProof calldata blobVerificationProof ) external view { - EigenDARollupUtils.verifyBlob(blobHeader, eigenDAServiceManager, blobVerificationProof); + EigenDARollupUtils.verifyBlob(blobHeader, EIGEN_DA_SERVICE_MANAGER, blobVerificationProof); } -} \ No newline at end of file +} diff --git a/src/bridge/EigenDABlobVerifierL2.sol b/src/bridge/EigenDABlobVerifierL2.sol index f22ca017..b5cdd32b 100644 --- a/src/bridge/EigenDABlobVerifierL2.sol +++ b/src/bridge/EigenDABlobVerifierL2.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.9; import "./IRollupManager.sol"; contract EigenDABlobVerifierL2 is IRollupManager { - function verifyBlob( IEigenDAServiceManager.BlobHeader calldata blobHeader, EigenDARollupUtils.BlobVerificationProof calldata blobVerificationProof diff --git a/src/bridge/IBridge.sol b/src/bridge/IBridge.sol index 3c55a811..1137fcd3 100644 --- a/src/bridge/IBridge.sol +++ b/src/bridge/IBridge.sol @@ -20,9 +20,7 @@ interface IBridge { /// @notice This batch contains no data NoData, /// @notice The data can be found in the 4844 data blobs on this transaction - Blob, - /// @notice The data can be found in the EigenDA blob associated with this batch - EigenDA + Blob } struct TimeBounds { @@ -44,7 +42,10 @@ interface IBridge { ); event BridgeCallTriggered( - address indexed outbox, address indexed to, uint256 value, bytes data + address indexed outbox, + address indexed to, + uint256 value, + bytes data ); event InboxToggle(address indexed inbox, bool enabled); @@ -77,9 +78,11 @@ interface IBridge { function sequencerReportedSubMessageCount() external view returns (uint256); - function executeCall(address to, uint256 value, bytes calldata data) - external - returns (bool success, bytes memory returnData); + function executeCall( + address to, + uint256 value, + bytes calldata data + ) external returns (bool success, bytes memory returnData); function delayedMessageCount() external view returns (uint256); @@ -94,7 +97,12 @@ interface IBridge { uint256 newMessageCount ) external - returns (uint256 seqMessageIndex, bytes32 beforeAcc, bytes32 delayedAcc, bytes32 acc); + returns ( + uint256 seqMessageIndex, + bytes32 beforeAcc, + bytes32 delayedAcc, + bytes32 acc + ); /** * @dev Allows the sequencer inbox to submit a delayed message of the batchPostingReport type diff --git a/src/bridge/IRollupManager.sol b/src/bridge/IRollupManager.sol index 7e9647bd..41c75777 100644 --- a/src/bridge/IRollupManager.sol +++ b/src/bridge/IRollupManager.sol @@ -5,9 +5,8 @@ import {EigenDARollupUtils} from "@eigenda/eigenda-utils/libraries/EigenDARollup import {IEigenDAServiceManager} from "@eigenda/eigenda-utils/interfaces/IEigenDAServiceManager.sol"; interface IRollupManager { - function verifyBlob( IEigenDAServiceManager.BlobHeader calldata blobHeader, EigenDARollupUtils.BlobVerificationProof calldata blobVerificationProof ) external view; -} \ No newline at end of file +} diff --git a/src/bridge/ISequencerInbox.sol b/src/bridge/ISequencerInbox.sol index 3c115f04..f3ab200b 100644 --- a/src/bridge/ISequencerInbox.sol +++ b/src/bridge/ISequencerInbox.sol @@ -201,12 +201,12 @@ interface ISequencerInbox is IDelayedMessageProvider { ) external; function addSequencerL2BatchFromEigenDA( - uint256 sequenceNumber, - EigenDACert calldata cert, - IGasRefunder gasRefunder, - uint256 afterDelayedMessagesRead, - uint256 prevMessageCount, - uint256 newMessageCount + uint256 sequenceNumber, + EigenDACert calldata cert, + IGasRefunder gasRefunder, + uint256 afterDelayedMessagesRead, + uint256 prevMessageCount, + uint256 newMessageCount ) external; // ---------- onlyRollupOrOwner functions ---------- @@ -222,7 +222,6 @@ interface ISequencerInbox is IDelayedMessageProvider { */ function setRollupAddress() external; - /** * @notice Set max delay for sequencer inbox * @param maxTimeVariation_ the maximum time variation parameters @@ -265,7 +264,6 @@ interface ISequencerInbox is IDelayedMessageProvider { /// @notice Allows the rollup owner to sync the rollup address function updateRollupAddress() external; - // ---------- initializer ---------- function initialize(IBridge bridge_, MaxTimeVariation calldata maxTimeVariation_) external; diff --git a/src/bridge/SequencerInbox.sol b/src/bridge/SequencerInbox.sol index 15e0b77c..72139f9f 100644 --- a/src/bridge/SequencerInbox.sol +++ b/src/bridge/SequencerInbox.sol @@ -157,19 +157,19 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox // Assuming we would not upgrade from a version that have MaxTimeVariation all set to zero // If that is the case, postUpgradeInit do not need to be called if ( - __LEGACY_MAX_TIME_VARIATION.delayBlocks == 0 - && __LEGACY_MAX_TIME_VARIATION.futureBlocks == 0 - && __LEGACY_MAX_TIME_VARIATION.delaySeconds == 0 - && __LEGACY_MAX_TIME_VARIATION.futureSeconds == 0 + __LEGACY_MAX_TIME_VARIATION.delayBlocks == 0 && + __LEGACY_MAX_TIME_VARIATION.futureBlocks == 0 && + __LEGACY_MAX_TIME_VARIATION.delaySeconds == 0 && + __LEGACY_MAX_TIME_VARIATION.futureSeconds == 0 ) { revert AlreadyInit(); } if ( - __LEGACY_MAX_TIME_VARIATION.delayBlocks > type(uint64).max - || __LEGACY_MAX_TIME_VARIATION.futureBlocks > type(uint64).max - || __LEGACY_MAX_TIME_VARIATION.delaySeconds > type(uint64).max - || __LEGACY_MAX_TIME_VARIATION.futureSeconds > type(uint64).max + __LEGACY_MAX_TIME_VARIATION.delayBlocks > type(uint64).max || + __LEGACY_MAX_TIME_VARIATION.futureBlocks > type(uint64).max || + __LEGACY_MAX_TIME_VARIATION.delaySeconds > type(uint64).max || + __LEGACY_MAX_TIME_VARIATION.futureSeconds > type(uint64).max ) { revert BadPostUpgradeInit(); } @@ -212,8 +212,12 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox function getTimeBounds() internal view virtual returns (IBridge.TimeBounds memory) { IBridge.TimeBounds memory bounds; - (uint64 delayBlocks_, uint64 futureBlocks_, uint64 delaySeconds_, uint64 futureSeconds_) = - maxTimeVariationInternal(); + ( + uint64 delayBlocks_, + uint64 futureBlocks_, + uint64 delaySeconds_, + uint64 futureSeconds_ + ) = maxTimeVariationInternal(); if (block.timestamp > delaySeconds_) { bounds.minTimestamp = uint64(block.timestamp) - delaySeconds_; } @@ -234,9 +238,22 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox futureSeconds = 1; } - function maxTimeVariation() external view returns (uint256, uint256, uint256, uint256) { - (uint64 delayBlocks_, uint64 futureBlocks_, uint64 delaySeconds_, uint64 futureSeconds_) = - maxTimeVariationInternal(); + function maxTimeVariation() + external + view + returns ( + uint256, + uint256, + uint256, + uint256 + ) + { + ( + uint64 delayBlocks_, + uint64 futureBlocks_, + uint64 delaySeconds_, + uint64 futureSeconds_ + ) = maxTimeVariationInternal(); return ( uint256(delayBlocks_), @@ -246,7 +263,16 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox ); } - function maxTimeVariationInternal() internal view returns (uint64, uint64, uint64, uint64) { + function maxTimeVariationInternal() + internal + view + returns ( + uint64, + uint64, + uint64, + uint64 + ) + { if (_chainIdChanged()) { return (1, 1, 1, 1); } else { @@ -283,19 +309,28 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox prevDelayedAcc = bridge.delayedInboxAccs(_totalDelayedMessagesRead - 2); } if ( - bridge.delayedInboxAccs(_totalDelayedMessagesRead - 1) - != Messages.accumulateInboxMessage(prevDelayedAcc, messageHash) + bridge.delayedInboxAccs(_totalDelayedMessagesRead - 1) != + Messages.accumulateInboxMessage(prevDelayedAcc, messageHash) ) revert IncorrectMessagePreimage(); - (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = - formEmptyDataHash(_totalDelayedMessagesRead); + (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = formEmptyDataHash( + _totalDelayedMessagesRead + ); uint256 __totalDelayedMessagesRead = _totalDelayedMessagesRead; uint256 prevSeqMsgCount = bridge.sequencerReportedSubMessageCount(); uint256 newSeqMsgCount = prevSeqMsgCount; // force inclusion should not modify sequencer message count - (uint256 seqMessageIndex, bytes32 beforeAcc, bytes32 delayedAcc, bytes32 afterAcc) = - addSequencerL2BatchImpl( - dataHash, __totalDelayedMessagesRead, 0, prevSeqMsgCount, newSeqMsgCount - ); + ( + uint256 seqMessageIndex, + bytes32 beforeAcc, + bytes32 delayedAcc, + bytes32 afterAcc + ) = addSequencerL2BatchImpl( + dataHash, + __totalDelayedMessagesRead, + 0, + prevSeqMsgCount, + newSeqMsgCount + ); emit SequencerBatchDelivered( seqMessageIndex, beforeAcc, @@ -308,10 +343,12 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox } /// @dev Deprecated, kept for abi generation and will be removed in the future - function addSequencerL2BatchFromOrigin(uint256, bytes calldata, uint256, IGasRefunder) - external - pure - { + function addSequencerL2BatchFromOrigin( + uint256, + bytes calldata, + uint256, + IGasRefunder + ) external pure { revert Deprecated(); } @@ -326,8 +363,10 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox // solhint-disable-next-line avoid-tx-origin if (msg.sender != tx.origin) revert NotOrigin(); if (!isBatchPoster[msg.sender]) revert NotBatchPoster(); - (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = - formCallDataHash(data, afterDelayedMessagesRead); + (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = formCallDataHash( + data, + afterDelayedMessagesRead + ); // Reformat the stack to prevent "Stack too deep" uint256 sequenceNumber_ = sequenceNumber; IBridge.TimeBounds memory timeBounds_ = timeBounds; @@ -336,10 +375,18 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox uint256 afterDelayedMessagesRead_ = afterDelayedMessagesRead; uint256 prevMessageCount_ = prevMessageCount; uint256 newMessageCount_ = newMessageCount; - (uint256 seqMessageIndex, bytes32 beforeAcc, bytes32 delayedAcc, bytes32 afterAcc) = - addSequencerL2BatchImpl( - dataHash_, afterDelayedMessagesRead_, dataLength, prevMessageCount_, newMessageCount_ - ); + ( + uint256 seqMessageIndex, + bytes32 beforeAcc, + bytes32 delayedAcc, + bytes32 afterAcc + ) = addSequencerL2BatchImpl( + dataHash_, + afterDelayedMessagesRead_, + dataLength, + prevMessageCount_, + newMessageCount_ + ); // ~uint256(0) is type(uint256).max, but ever so slightly cheaper if (seqMessageIndex != sequenceNumber_ && sequenceNumber_ != ~uint256(0)) { @@ -365,16 +412,27 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox uint256 newMessageCount ) external refundsGas(gasRefunder, reader4844) { if (!isBatchPoster[msg.sender]) revert NotBatchPoster(); - (bytes32 dataHash, IBridge.TimeBounds memory timeBounds, uint256 blobGas) = - formBlobDataHash(afterDelayedMessagesRead); + ( + bytes32 dataHash, + IBridge.TimeBounds memory timeBounds, + uint256 blobGas + ) = formBlobDataHash(afterDelayedMessagesRead); // we use addSequencerL2BatchImpl for submitting the message // normally this would also submit a batch spending report but that is skipped if we pass // an empty call data size, then we submit a separate batch spending report later - (uint256 seqMessageIndex, bytes32 beforeAcc, bytes32 delayedAcc, bytes32 afterAcc) = - addSequencerL2BatchImpl( - dataHash, afterDelayedMessagesRead, 0, prevMessageCount, newMessageCount - ); + ( + uint256 seqMessageIndex, + bytes32 beforeAcc, + bytes32 delayedAcc, + bytes32 afterAcc + ) = addSequencerL2BatchImpl( + dataHash, + afterDelayedMessagesRead, + 0, + prevMessageCount, + newMessageCount + ); uint256 _sequenceNumber = sequenceNumber; // stack workaround @@ -406,7 +464,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox submitBatchSpendingReport(dataHash, seqMessageIndex, block.basefee, blobGas); } } - + function addSequencerL2BatchFromEigenDA( uint256 sequenceNumber, EigenDACert calldata cert, @@ -419,15 +477,18 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox // Verify that the blob was actually included before continuing rollupManager.verifyBlob(cert.blobHeader, cert.blobVerificationProof); // Form the EigenDA data hash and get the time bounds - (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = formEigenDADataHash(cert, afterDelayedMessagesRead); - + (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = formEigenDADataHash( + cert, + afterDelayedMessagesRead + ); + ISequencerInbox.SequenceMetadata memory metadata = ISequencerInbox.SequenceMetadata({ sequenceNumber: sequenceNumber, afterDelayedMessagesRead: afterDelayedMessagesRead, prevMessageCount: prevMessageCount, newMessageCount: newMessageCount }); - + // Call a helper function to add the sequencer L2 batch _addSequencerL2Batch(metadata, dataHash, timeBounds); } @@ -437,8 +498,18 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox bytes32 dataHash, IBridge.TimeBounds memory timeBounds ) internal { - (uint256 seqMessageIndex, bytes32 beforeAcc, bytes32 delayedAcc, bytes32 afterAcc) = - addSequencerL2BatchImpl(dataHash, sequenceMetadata.afterDelayedMessagesRead, 0, sequenceMetadata.prevMessageCount, sequenceMetadata.newMessageCount); + ( + uint256 seqMessageIndex, + bytes32 beforeAcc, + bytes32 delayedAcc, + bytes32 afterAcc + ) = addSequencerL2BatchImpl( + dataHash, + sequenceMetadata.afterDelayedMessagesRead, + 0, + sequenceMetadata.prevMessageCount, + sequenceMetadata.newMessageCount + ); uint256 sequenceNumber = sequenceMetadata.sequenceNumber; // Check the sequence number @@ -466,8 +537,10 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox uint256 newMessageCount ) external override refundsGas(gasRefunder, IReader4844(address(0))) { if (!isBatchPoster[msg.sender] && msg.sender != address(rollup)) revert NotBatchPoster(); - (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = - formCallDataHash(data, afterDelayedMessagesRead); + (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = formCallDataHash( + data, + afterDelayedMessagesRead + ); uint256 seqMessageIndex; { // Reformat the stack to prevent "Stack too deep" @@ -483,7 +556,11 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox bytes32 delayedAcc; bytes32 afterAcc; (seqMessageIndex, beforeAcc, delayedAcc, afterAcc) = addSequencerL2BatchImpl( - dataHash_, afterDelayedMessagesRead_, 0, prevMessageCount_, newMessageCount_ + dataHash_, + afterDelayedMessagesRead_, + 0, + prevMessageCount_, + newMessageCount_ ); // ~uint256(0) is type(uint256).max, but ever so slightly cheaper @@ -531,8 +608,9 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox view returns (bytes32, IBridge.TimeBounds memory) { - (bytes memory header, IBridge.TimeBounds memory timeBounds) = - packHeader(afterDelayedMessagesRead); + (bytes memory header, IBridge.TimeBounds memory timeBounds) = packHeader( + afterDelayedMessagesRead + ); return (keccak256(header), timeBounds); } @@ -542,9 +620,11 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox /// 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) { - 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; + 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; } /// @dev Form a hash of the data taken from the calldata @@ -560,8 +640,9 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox uint256 fullDataLen = HEADER_LENGTH + data.length; if (fullDataLen > maxDataSize) revert DataTooLarge(fullDataLen, maxDataSize); - (bytes memory header, IBridge.TimeBounds memory timeBounds) = - packHeader(afterDelayedMessagesRead); + (bytes memory header, IBridge.TimeBounds memory timeBounds) = packHeader( + afterDelayedMessagesRead + ); // the batch poster is allowed to submit an empty batch, they can use this to progress the // delayed inbox without providing extra batch data @@ -587,13 +668,18 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox function formBlobDataHash(uint256 afterDelayedMessagesRead) internal view - returns (bytes32, IBridge.TimeBounds memory, uint256) + returns ( + bytes32, + IBridge.TimeBounds memory, + uint256 + ) { bytes32[] memory dataHashes = reader4844.getDataHashes(); if (dataHashes.length == 0) revert MissingDataHashes(); - (bytes memory header, IBridge.TimeBounds memory timeBounds) = - packHeader(afterDelayedMessagesRead); + (bytes memory header, IBridge.TimeBounds memory timeBounds) = packHeader( + afterDelayedMessagesRead + ); uint256 blobCost = reader4844.getBlobBaseFee() * GAS_PER_BLOB * dataHashes.length; return ( @@ -611,19 +697,12 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox ISequencerInbox.EigenDACert calldata cert, uint256 afterDelayedMessagesRead ) internal view returns (bytes32, IBridge.TimeBounds memory) { - (bytes memory header, IBridge.TimeBounds memory timeBounds) = - packHeader(afterDelayedMessagesRead); + (bytes memory header, IBridge.TimeBounds memory timeBounds) = packHeader( + afterDelayedMessagesRead + ); return ( - keccak256( - bytes.concat( - header, - EIGENDA_MESSAGE_HEADER_FLAG, - abi.encode( - cert - ) - ) - ), + keccak256(bytes.concat(header, EIGENDA_MESSAGE_HEADER_FLAG, abi.encode(cert))), timeBounds ); } @@ -653,10 +732,18 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox } require(extraGas <= type(uint64).max, "EXTRA_GAS_NOT_UINT64"); bytes memory spendingReportMsg = abi.encodePacked( - block.timestamp, batchPoster, dataHash, seqMessageIndex, gasPrice, uint64(extraGas) + block.timestamp, + batchPoster, + dataHash, + seqMessageIndex, + gasPrice, + uint64(extraGas) ); - uint256 msgNum = bridge.submitBatchSpendingReport(batchPoster, keccak256(spendingReportMsg)); + uint256 msgNum = bridge.submitBatchSpendingReport( + batchPoster, + keccak256(spendingReportMsg) + ); // this is the same event used by Inbox.sol after including a message to the delayed message accumulator emit InboxMessageDelivered(msgNum, spendingReportMsg); } @@ -669,13 +756,21 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox uint256 newMessageCount ) internal - returns (uint256 seqMessageIndex, bytes32 beforeAcc, bytes32 delayedAcc, bytes32 acc) + returns ( + uint256 seqMessageIndex, + bytes32 beforeAcc, + bytes32 delayedAcc, + bytes32 acc + ) { if (afterDelayedMessagesRead < totalDelayedMessagesRead) revert DelayedBackwards(); if (afterDelayedMessagesRead > bridge.delayedMessageCount()) revert DelayedTooFar(); (seqMessageIndex, beforeAcc, delayedAcc, acc) = bridge.enqueueSequencerMessage( - dataHash, afterDelayedMessagesRead, prevMessageCount, newMessageCount + dataHash, + afterDelayedMessagesRead, + prevMessageCount, + newMessageCount ); totalDelayedMessagesRead = afterDelayedMessagesRead; @@ -698,10 +793,10 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox internal { if ( - maxTimeVariation_.delayBlocks > type(uint64).max - || maxTimeVariation_.futureBlocks > type(uint64).max - || maxTimeVariation_.delaySeconds > type(uint64).max - || maxTimeVariation_.futureSeconds > type(uint64).max + maxTimeVariation_.delayBlocks > type(uint64).max || + maxTimeVariation_.futureBlocks > type(uint64).max || + maxTimeVariation_.delaySeconds > type(uint64).max || + maxTimeVariation_.futureSeconds > type(uint64).max ) { revert BadMaxTimeVariation(); } @@ -740,8 +835,10 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox if (hostChainIsArbitrum) { creationBlock = ArbSys(address(100)).arbBlockNumber(); } - dasKeySetInfo[ksHash] = - DasKeySetInfo({isValidKeyset: true, creationBlock: uint64(creationBlock)}); + dasKeySetInfo[ksHash] = DasKeySetInfo({ + isValidKeyset: true, + creationBlock: uint64(creationBlock) + }); emit SetValidKeyset(ksHash, keysetBytes); emit OwnerFunctionCalled(2); } @@ -804,4 +901,4 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox if (ksInfo.creationBlock == 0) revert NoSuchKeyset(ksHash); return uint256(ksInfo.creationBlock); } -} \ No newline at end of file +} diff --git a/src/mocks/EigenDAServiceManagerStub.sol b/src/mocks/EigenDAServiceManagerStub.sol index 6a459d96..dae923e8 100644 --- a/src/mocks/EigenDAServiceManagerStub.sol +++ b/src/mocks/EigenDAServiceManagerStub.sol @@ -2,7 +2,9 @@ pragma solidity ^0.8.0; -import {EigenDAServiceManager} from "@eigenda/eigenda-utils/contracts/eigenda/EigenDAServiceManager.sol"; +import { + EigenDAServiceManager +} from "@eigenda/eigenda-utils/contracts/eigenda/EigenDAServiceManager.sol"; import {IAVSDirectory} from "@eigenda/eigenda-utils/interfaces/IAVSDirectory.sol"; import {IPaymentCoordinator} from "@eigenda/eigenda-utils/interfaces/IPaymentCoordinator.sol"; import {IRegistryCoordinator} from "@eigenda/eigenda-utils/interfaces/IRegistryCoordinator.sol"; @@ -10,7 +12,6 @@ import {IStakeRegistry} from "@eigenda/eigenda-utils/interfaces/IStakeRegistry.s import {IPauserRegistry} from "@eigenda/eigenda-utils/interfaces/IPauserRegistry.sol"; contract EigenDAServiceManagerStub is EigenDAServiceManager { - constructor( IAVSDirectory __avsDirectory, IPaymentCoordinator __paymentCoordinator, @@ -20,11 +21,12 @@ contract EigenDAServiceManagerStub is EigenDAServiceManager { uint256 _initialPausedStatus, address _initialOwner, address[] memory _batchConfirmers - ) EigenDAServiceManager( - __avsDirectory, - __paymentCoordinator, - __registryCoordinator, - __stakeRegistry - ) { - } + ) + EigenDAServiceManager( + __avsDirectory, + __paymentCoordinator, + __registryCoordinator, + __stakeRegistry + ) + {} } diff --git a/src/mocks/SequencerInboxStub.sol b/src/mocks/SequencerInboxStub.sol index 95f9c206..368ba8bb 100644 --- a/src/mocks/SequencerInboxStub.sol +++ b/src/mocks/SequencerInboxStub.sol @@ -19,7 +19,6 @@ contract SequencerInboxStub is SequencerInbox { ISequencerInbox.MaxTimeVariation memory maxTimeVariation_, uint256 maxDataSize_, IReader4844 reader4844_, - bool isUsingFeeToken_ ) SequencerInbox(maxDataSize_, reader4844_, isUsingFeeToken_) { bridge = bridge_; @@ -38,13 +37,19 @@ contract SequencerInboxStub is SequencerInbox { function addInitMessage(uint256 chainId) external { bytes memory initMsg = abi.encodePacked(chainId); uint256 num = IEthBridge(address(bridge)).enqueueDelayedMessage( - INITIALIZATION_MSG_TYPE, address(0), keccak256(initMsg) + INITIALIZATION_MSG_TYPE, + address(0), + keccak256(initMsg) ); require(num == 0, "ALREADY_DELAYED_INIT"); emit InboxMessageDelivered(num, initMsg); (bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = formEmptyDataHash(1); - (uint256 sequencerMessageCount, bytes32 beforeAcc, bytes32 delayedAcc, bytes32 afterAcc) = - addSequencerL2BatchImpl(dataHash, 1, 0, 0, 1); + ( + uint256 sequencerMessageCount, + bytes32 beforeAcc, + bytes32 delayedAcc, + bytes32 afterAcc + ) = addSequencerL2BatchImpl(dataHash, 1, 0, 0, 1); require(sequencerMessageCount == 0, "ALREADY_SEQ_INIT"); emit SequencerBatchDelivered( sequencerMessageCount, @@ -61,4 +66,4 @@ contract SequencerInboxStub is SequencerInbox { this; // silence warning about function not being view return bounds; } -} \ No newline at end of file +} diff --git a/src/osp/OneStepProverHostIo.sol b/src/osp/OneStepProverHostIo.sol index 18baf403..ef2bf6f2 100644 --- a/src/osp/OneStepProverHostIo.sol +++ b/src/osp/OneStepProverHostIo.sol @@ -16,7 +16,6 @@ import "../bridge/IBridge.sol"; import {BN254} from "@eigenda/eigenda-utils/libraries/BN254.sol"; - contract OneStepProverHostIo is IOneStepProver { using GlobalStateLib for GlobalState; using MachineLib for Machine; @@ -39,15 +38,35 @@ contract OneStepProverHostIo is IOneStepProver { // AlphaG1 // This is from the SRS points being used. // This is the point at index 1, since index 0 is the generator value of the G1 group. - BN254.G1Point private ALPHA_G1 = BN254.G1Point(5421624913032980671919055010798735843841011930764711817607050648427876929258, 12995821280260994872112541311010834261076556242291585164372488699033268245381); + BN254.G1Point private ALPHA_G1 = + BN254.G1Point( + 5421624913032980671919055010798735843841011930764711817607050648427876929258, + 12995821280260994872112541311010834261076556242291585164372488699033268245381 + ); - function computeGamma(uint256 z, uint256 y, uint256[2] memory p, uint256[4] memory alpha_minus_z_g2) internal pure returns (uint256) { + function computeGamma( + uint256 z, + uint256 y, + uint256[2] memory p, + uint256[4] memory alpha_minus_z_g2 + ) internal pure returns (uint256) { // Encode the variables and compute the keccak256 hash - bytes32 hash = keccak256(abi.encodePacked(z, y, p[0], p[1], alpha_minus_z_g2[0], alpha_minus_z_g2[1], alpha_minus_z_g2[2], alpha_minus_z_g2[3])); + bytes32 hash = keccak256( + abi.encodePacked( + z, + y, + p[0], + p[1], + alpha_minus_z_g2[0], + alpha_minus_z_g2[1], + alpha_minus_z_g2[2], + alpha_minus_z_g2[3] + ) + ); return uint256(hash) % BN254.FR_MODULUS; } - // e((P - y) + gamma . (alpha - z), G2) = e((Q + gamma), (alpha - z)) + // e((P - y) + gamma . (alpha - z), G2) = e((Q + gamma), (alpha - z)) function VerifyKzgProofWithG1Equivalence( uint256[2] memory commitment, uint256 y, @@ -55,9 +74,11 @@ contract OneStepProverHostIo is IOneStepProver { uint256 z, uint256[4] memory alpha_minus_z_g2 ) public view returns (bool) { - BN254.G1Point memory yG1Neg = BN254.negate(BN254.scalar_mul(BN254.generatorG1(), y)); - BN254.G1Point memory P_minus_y = BN254.plus(BN254.G1Point(commitment[0], commitment[1]), yG1Neg); + BN254.G1Point memory P_minus_y = BN254.plus( + BN254.G1Point(commitment[0], commitment[1]), + yG1Neg + ); // zG1 BN254.G1Point memory zG1Neg = BN254.negate(BN254.scalar_mul(BN254.generatorG1(), z)); @@ -72,13 +93,16 @@ contract OneStepProverHostIo is IOneStepProver { BN254.G1Point memory gamma_alpha_minus_z_g1 = BN254.scalar_mul(alpha_minus_z_g1, gamma); // gammaG1 - BN254.G1Point memory gammaG1 = BN254.scalar_mul(BN254.generatorG1(), gamma); - + BN254.G1Point memory gammaG1 = BN254.scalar_mul(BN254.generatorG1(), gamma); + // Q + gamma BN254.G1Point memory q_plus_gamma = BN254.plus(BN254.G1Point(proof[0], proof[1]), gammaG1); BN254.G1Point memory lhsG1 = BN254.plus(P_minus_y, gamma_alpha_minus_z_g1); // The order is switched in the arbitrator already. It is passed as x_c1, x_c0, y_c1, y_c0 - BN254.G2Point memory alpha_minus_z_g22 = BN254.G2Point([alpha_minus_z_g2[0], alpha_minus_z_g2[1]], [alpha_minus_z_g2[2], alpha_minus_z_g2[3]]); + BN254.G2Point memory alpha_minus_z_g22 = BN254.G2Point( + [alpha_minus_z_g2[0], alpha_minus_z_g2[1]], + [alpha_minus_z_g2[2], alpha_minus_z_g2[3]] + ); return BN254.pairing(lhsG1, BN254.negGeneratorG2(), q_plus_gamma, alpha_minus_z_g22); } @@ -178,7 +202,6 @@ contract OneStepProverHostIo is IOneStepProver { return uint256(bytes32(modExpOutput)); } - uint256 internal constant BN_254_PRIMITIVE_ROOT_OF_UNITY = 19103219067921713944291392827692070036145651957329286315305642004821462161904; @@ -312,12 +335,22 @@ contract OneStepProverHostIo is IOneStepProver { // [224:288] - kzg commitment (g1 point) // [288:352] - proof (g1 point) // [352:385] - preimage length - + { - - uint256[2] memory kzgCommitment = [uint256(bytes32(kzgProof[224:256])), uint256(bytes32(kzgProof[256:288]))]; - uint256[4] memory alphaMinusG2 = [uint256(bytes32(kzgProof[96:128])), uint256(bytes32(kzgProof[128:160])), uint256(bytes32(kzgProof[160:192])), uint256(bytes32(kzgProof[192:224]))]; - uint256[2] memory proofUint256 = [uint256(bytes32(kzgProof[288:320])), uint256(bytes32(kzgProof[320:352]))]; + uint256[2] memory kzgCommitment = [ + uint256(bytes32(kzgProof[224:256])), + uint256(bytes32(kzgProof[256:288])) + ]; + uint256[4] memory alphaMinusG2 = [ + uint256(bytes32(kzgProof[96:128])), + uint256(bytes32(kzgProof[128:160])), + uint256(bytes32(kzgProof[160:192])), + uint256(bytes32(kzgProof[192:224])) + ]; + uint256[2] memory proofUint256 = [ + uint256(bytes32(kzgProof[288:320])), + uint256(bytes32(kzgProof[320:352])) + ]; uint256 z = uint256(bytes32(kzgProof[32:64])); uint256 y = uint256(bytes32(kzgProof[64:96])); uint256 length = uint32(uint256(bytes32(kzgProof[352:384]))); @@ -332,10 +365,22 @@ contract OneStepProverHostIo is IOneStepProver { require(z < BN254.FR_MODULUS, "Z_LARGER_THAN_FIELD"); require(y < BN254.FR_MODULUS, "Y_LARGER_THAN_FIELD"); - require(keccak256(abi.encodePacked(kzgProof[224:288], length_u32)) == leafContents, "BN254_KZG_PROOF_WRONG_HASH"); + require( + keccak256(abi.encodePacked(kzgProof[224:288], length_u32)) == leafContents, + "BN254_KZG_PROOF_WRONG_HASH" + ); // must be valid proof - require(VerifyKzgProofWithG1Equivalence(kzgCommitment, y, proofUint256, z, alphaMinusG2), "INVALID_BN254_KZG_PROOF"); + require( + VerifyKzgProofWithG1Equivalence( + kzgCommitment, + y, + proofUint256, + z, + alphaMinusG2 + ), + "INVALID_BN254_KZG_PROOF" + ); } // read the preimage length @@ -345,20 +390,23 @@ contract OneStepProverHostIo is IOneStepProver { if (preimageOffset < preimageLength) { // preimageOffset was required to be 32 byte aligned above uint256 tmp = preimageOffset / 32; - // First, we get the root of unity of order 2**fieldElementsPerBlob. + // First, we get the root of unity of order 2**fieldElementsPerBlob. // We start with a root of unity of order 2**32 and then raise it to // the power of (2**32)/fieldElementsPerBlob to get root of unity we need. - uint256 rootOfUnityPower = (1 << 28) / preimageLength * 32; + uint256 rootOfUnityPower = ((1 << 28) / preimageLength) * 32; // Then, we raise the root of unity to the power of bitReversedIndex, // to retrieve this word of the KZG commitment. rootOfUnityPower *= tmp; // z is the point the polynomial is evaluated at to retrieve this word of data - uint256 z = modExp256(BN_254_PRIMITIVE_ROOT_OF_UNITY, rootOfUnityPower, BN254.FR_MODULUS); + uint256 z = modExp256( + BN_254_PRIMITIVE_ROOT_OF_UNITY, + rootOfUnityPower, + BN254.FR_MODULUS + ); require(bytes32(kzgProof[32:64]) == bytes32(z), "KZG_PROOF_WRONG_Z"); extracted = kzgProof[64:96]; } - } else { revert("UNKNOWN_PREIMAGE_TYPE"); } @@ -770,19 +818,19 @@ contract OneStepProverHostIo is IOneStepProver { impl(execCtx, mach, mod, inst, proof); } - // G2_SRS_1 //note might be useful to give back to the bn library - uint256 internal constant G2Taux1 = 21039730876973405969844107393779063362038454413254731404052240341412356318284; - uint256 internal constant G2Taux0 = 7912312892787135728292535536655271843828059318189722219035249994421084560563; - uint256 internal constant G2Tauy1 = 7586489485579523767759120334904353546627445333297951253230866312564920951171; - uint256 internal constant G2Tauy0 = 18697407556011630376420900106252341752488547575648825575049647403852275261247; + uint256 internal constant G2Taux1 = + 21039730876973405969844107393779063362038454413254731404052240341412356318284; + uint256 internal constant G2Taux0 = + 7912312892787135728292535536655271843828059318189722219035249994421084560563; + uint256 internal constant G2Tauy1 = + 7586489485579523767759120334904353546627445333297951253230866312564920951171; + uint256 internal constant G2Tauy0 = + 18697407556011630376420900106252341752488547575648825575049647403852275261247; function g2Tau() internal view returns (BN254.G2Point memory) { - return BN254.G2Point({ - X: [G2Taux1, G2Taux0], - Y: [G2Tauy1, G2Tauy0] - }); + return BN254.G2Point({X: [G2Taux1, G2Taux0], Y: [G2Tauy1, G2Tauy0]}); } -} \ No newline at end of file +} diff --git a/test/contract/sequencerInboxForceInclude.spec.ts b/test/contract/sequencerInboxForceInclude.spec.ts index 1a240814..794cf0e3 100644 --- a/test/contract/sequencerInboxForceInclude.spec.ts +++ b/test/contract/sequencerInboxForceInclude.spec.ts @@ -225,7 +225,7 @@ describe('SequencerInboxForceInclude', async () => { const rollupOwner = accounts[3] const batchPoster = accounts[4] // const batchPosterManager = accounts[5] - const dummyAVSContract= accounts[6] + const dummyAVSContract = accounts[6] const dummyAVSContractAddress = await dummyAVSContract.getAddress() const rollupMockFac = (await ethers.getContractFactory( @@ -233,11 +233,15 @@ describe('SequencerInboxForceInclude', async () => { )) as RollupMock__factory const rollup = await rollupMockFac.deploy(await rollupOwner.getAddress()) - const EigenDARollupUtils = await ethers.getContractFactory("EigenDARollupUtils"); - const eigenDARollupUtils = await EigenDARollupUtils.deploy(); - await eigenDARollupUtils.deployed(); + const EigenDARollupUtils = await ethers.getContractFactory( + 'EigenDARollupUtils' + ) + const eigenDARollupUtils = await EigenDARollupUtils.deploy() + await eigenDARollupUtils.deployed() - const EigenDAServiceManagerStub = await ethers.getContractFactory("EigenDAServiceManagerStub"); + const EigenDAServiceManagerStub = await ethers.getContractFactory( + 'EigenDAServiceManagerStub' + ) const eigenDAServiceManagerStub = await EigenDAServiceManagerStub.deploy( dummyAVSContractAddress, @@ -248,15 +252,18 @@ describe('SequencerInboxForceInclude', async () => { 0, adminAddr, [adminAddr] - ); - await eigenDAServiceManagerStub.deployed(); + ) + await eigenDAServiceManagerStub.deployed() const reader4844 = await Toolkit4844.deployReader4844(admin) - const sequencerInboxFac = await ethers.getContractFactory("SequencerInbox", { - libraries: { - EigenDARollupUtils: eigenDARollupUtils.address + const sequencerInboxFac = (await ethers.getContractFactory( + 'SequencerInbox', + { + libraries: { + EigenDARollupUtils: eigenDARollupUtils.address, + }, } - }) as SequencerInbox__factory + )) as SequencerInbox__factory const seqInboxTemplate = await sequencerInboxFac.deploy( 117964, reader4844.address, diff --git a/test/foundry/ChallengeManager.t.sol b/test/foundry/ChallengeManager.t.sol index 88557db9..1e9622e2 100644 --- a/test/foundry/ChallengeManager.t.sol +++ b/test/foundry/ChallengeManager.t.sol @@ -24,10 +24,14 @@ contract ChallengeManagerTest is Test { ); chalman.initialize(resultReceiver, sequencerInbox, bridge, osp); assertEq( - address(chalman.resultReceiver()), address(resultReceiver), "Result receiver not set" + address(chalman.resultReceiver()), + address(resultReceiver), + "Result receiver not set" ); assertEq( - address(chalman.sequencerInbox()), address(sequencerInbox), "Sequencer inbox not set" + address(chalman.sequencerInbox()), + address(sequencerInbox), + "Sequencer inbox not set" ); assertEq(address(chalman.bridge()), address(bridge), "Bridge not set"); assertEq(address(chalman.osp()), address(osp), "OSP not set"); @@ -52,10 +56,12 @@ contract ChallengeManagerTest is Test { // legacy hashes bytes32 legacySegment0 = legacyOSP.getStartMachineHash( - keccak256(abi.encodePacked("globalStateHash[0]")), legacyRoot + keccak256(abi.encodePacked("globalStateHash[0]")), + legacyRoot ); bytes32 legacySegment1 = legacyOSP.getEndMachineHash( - MachineStatus.FINISHED, keccak256(abi.encodePacked("globalStateHashes[1]")) + MachineStatus.FINISHED, + keccak256(abi.encodePacked("globalStateHashes[1]")) ); /// new OSP @@ -72,10 +78,12 @@ contract ChallengeManagerTest is Test { // new hashes bytes32 newSegment0 = _newOSP.getStartMachineHash( - keccak256(abi.encodePacked("globalStateHash[0]")), randomRoot + keccak256(abi.encodePacked("globalStateHash[0]")), + randomRoot ); bytes32 newSegment1 = _newOSP.getEndMachineHash( - MachineStatus.FINISHED, keccak256(abi.encodePacked("new_globalStateHashes[1]")) + MachineStatus.FINISHED, + keccak256(abi.encodePacked("new_globalStateHashes[1]")) ); /// do upgrade @@ -83,7 +91,10 @@ contract ChallengeManagerTest is Test { TransparentUpgradeableProxy(payable(address(chalman))).upgradeToAndCall( address(chalmanImpl), abi.encodeWithSelector( - ChallengeManager.postUpgradeInit.selector, _newOSP, legacyRoot, legacyOSP + ChallengeManager.postUpgradeInit.selector, + _newOSP, + legacyRoot, + legacyOSP ) ); @@ -92,14 +103,16 @@ contract ChallengeManagerTest is Test { assertEq(address(_condOsp), address(legacyOSP), "Legacy osp not set"); assertEq( _condOsp.getStartMachineHash( - keccak256(abi.encodePacked("globalStateHash[0]")), legacyRoot + keccak256(abi.encodePacked("globalStateHash[0]")), + legacyRoot ), legacySegment0, "Unexpected start machine hash" ); assertEq( _condOsp.getEndMachineHash( - MachineStatus.FINISHED, keccak256(abi.encodePacked("globalStateHashes[1]")) + MachineStatus.FINISHED, + keccak256(abi.encodePacked("globalStateHashes[1]")) ), legacySegment1, "Unexpected end machine hash" @@ -110,14 +123,16 @@ contract ChallengeManagerTest is Test { assertEq(address(_newOsp), address(_newOSP), "New osp not set"); assertEq( _newOsp.getStartMachineHash( - keccak256(abi.encodePacked("globalStateHash[0]")), randomRoot + keccak256(abi.encodePacked("globalStateHash[0]")), + randomRoot ), newSegment0, "Unexpected start machine hash" ); assertEq( _newOsp.getEndMachineHash( - MachineStatus.FINISHED, keccak256(abi.encodePacked("new_globalStateHashes[1]")) + MachineStatus.FINISHED, + keccak256(abi.encodePacked("new_globalStateHashes[1]")) ), newSegment1, "Unexpected end machine hash" @@ -135,7 +150,10 @@ contract ChallengeManagerTest is Test { TransparentUpgradeableProxy(payable(address(chalman))).upgradeToAndCall( address(chalmanImpl), abi.encodeWithSelector( - ChallengeManager.postUpgradeInit.selector, newOsp, randomRoot, condOsp + ChallengeManager.postUpgradeInit.selector, + newOsp, + randomRoot, + condOsp ) ); diff --git a/test/foundry/DummyEigenDABlobVerifier.sol b/test/foundry/DummyEigenDABlobVerifier.sol index 8bcc5223..2c8b138b 100644 --- a/test/foundry/DummyEigenDABlobVerifier.sol +++ b/test/foundry/DummyEigenDABlobVerifier.sol @@ -3,10 +3,9 @@ pragma solidity ^0.8.9; import "../../src/bridge/IRollupManager.sol"; -contract DummyEigenDABlobVerifier is IRollupManager{ - +contract DummyEigenDABlobVerifier is IRollupManager { function verifyBlob( IEigenDAServiceManager.BlobHeader calldata blobHeader, EigenDARollupUtils.BlobVerificationProof calldata blobVerificationProof ) external view {} -} \ No newline at end of file +} diff --git a/test/foundry/ERC20Outbox.t.sol b/test/foundry/ERC20Outbox.t.sol index 165d1657..79e6b5a9 100644 --- a/test/foundry/ERC20Outbox.t.sol +++ b/test/foundry/ERC20Outbox.t.sol @@ -16,11 +16,16 @@ contract ERC20OutboxTest is AbsOutboxTest { // deploy token, bridge and outbox // hardcoded proof in tests assume that this contract is deployed at the repsective address - IERC20 nativeTokenCode = new ERC20PresetFixedSupply("Appchain Token", "App", 1_000_000, address(this)); + IERC20 nativeTokenCode = new ERC20PresetFixedSupply( + "Appchain Token", + "App", + 1_000_000, + address(this) + ); nativeToken = IERC20(0xFEfC6BAF87cF3684058D62Da40Ff3A795946Ab06); vm.etch(address(nativeToken), address(nativeTokenCode).code); deal(address(nativeToken), address(this), 1_000_000); - + bridge = IBridge(TestUtil.deployProxy(address(new ERC20Bridge()))); erc20Bridge = ERC20Bridge(address(bridge)); outbox = IOutbox(TestUtil.deployProxy(address(new ERC20Outbox()))); diff --git a/test/foundry/KZGbn254.t.sol b/test/foundry/KZGbn254.t.sol index 59a60329..26d0296e 100644 --- a/test/foundry/KZGbn254.t.sol +++ b/test/foundry/KZGbn254.t.sol @@ -12,16 +12,12 @@ contract VerifyKzgBN245Commitment is Test { } function testVerifyCommitment() public { - uint256 commitX = 19070058680970706162154662779699659917241938423048978712039328696898981234708; uint256 commitY = 11823711927945062212181456259672826202645633805996688691575607391116183704220; uint256 evaluationY = 124448554745810004944228143885327110275920855486363883336842102793103679599; - uint256[2] memory commit = [commitX, commitY]; - - uint256 proofX = 3494873036786265278705899204171091912768379376170087008335233101540628332609; uint256 proofY = 8608960508439403080401521741368234568803206554328273041427052980854260749148; @@ -49,7 +45,13 @@ contract VerifyKzgBN245Commitment is Test { uint256 bad_z = 69; assertFalse( - osp.VerifyKzgProofWithG1Equivalence(commit, evaluationY, proofArray, bad_z, alphaMinusZG2) + osp.VerifyKzgProofWithG1Equivalence( + commit, + evaluationY, + proofArray, + bad_z, + alphaMinusZG2 + ) ); } -} \ No newline at end of file +} diff --git a/test/foundry/Outbox.t.sol b/test/foundry/Outbox.t.sol index 8d38deb8..83eaba8c 100644 --- a/test/foundry/Outbox.t.sol +++ b/test/foundry/Outbox.t.sol @@ -61,10 +61,7 @@ contract OutboxTest is AbsOutboxTest { bytes32 root = outbox.calculateMerkleRoot(proof, index, itemHash); // store root vm.prank(rollup); - outbox.updateSendRoot( - root, - bytes32(uint256(1)) - ); + outbox.updateSendRoot(root, bytes32(uint256(1))); outbox.executeTransaction({ proof: proof, @@ -80,12 +77,16 @@ contract OutboxTest is AbsOutboxTest { uint256 bridgeBalanceAfter = address(bridge).balance; assertEq( - bridgeBalanceBefore - bridgeBalanceAfter, withdrawalAmount, "Invalid bridge balance" + bridgeBalanceBefore - bridgeBalanceAfter, + withdrawalAmount, + "Invalid bridge balance" ); uint256 targetBalanceAfter = address(target).balance; assertEq( - targetBalanceAfter - targetBalanceBefore, withdrawalAmount, "Invalid target balance" + targetBalanceAfter - targetBalanceBefore, + withdrawalAmount, + "Invalid target balance" ); /// check context was properly set during execution diff --git a/test/foundry/RollupCreator.t.sol b/test/foundry/RollupCreator.t.sol index c24d6f6c..ba3c57f3 100644 --- a/test/foundry/RollupCreator.t.sol +++ b/test/foundry/RollupCreator.t.sol @@ -126,22 +126,23 @@ contract RollupCreatorTest is Test { address[] memory validators = new address[](2); validators[0] = makeAddr("validator1"); validators[1] = makeAddr("validator2"); - + address eigenDASvcManager = makeAddr("eigenDASvcManager"); address eigenDARollupManager = makeAddr("rollupManager"); - RollupCreator.RollupDeploymentParams memory deployParams = RollupCreator.RollupDeploymentParams({ - config: config, - batchPosters: batchPosters, - validators: validators, - maxDataSize: MAX_DATA_SIZE, - nativeToken: address(0), - deployFactoriesToL2: true, - maxFeePerGasForRetryables: MAX_FEE_PER_GAS, - batchPosterManager: batchPosterManager, - eigenDARollupManager: eigenDARollupManager - }); - + RollupCreator.RollupDeploymentParams memory deployParams = RollupCreator + .RollupDeploymentParams({ + config: config, + batchPosters: batchPosters, + validators: validators, + maxDataSize: MAX_DATA_SIZE, + nativeToken: address(0), + deployFactoriesToL2: true, + maxFeePerGasForRetryables: MAX_FEE_PER_GAS, + batchPosterManager: batchPosterManager, + eigenDARollupManager: eigenDARollupManager + }); + address rollupAddress = rollupCreator.createRollup{value: factoryDeploymentFunds}( deployParams ); diff --git a/test/foundry/SequencerInbox.t.sol b/test/foundry/SequencerInbox.t.sol index 3b4089fc..1a0e7fda 100644 --- a/test/foundry/SequencerInbox.t.sol +++ b/test/foundry/SequencerInbox.t.sol @@ -46,12 +46,13 @@ contract SequencerInboxTest is Test { Random RAND = new Random(); address rollupOwner = address(137); uint256 maxDataSize = 10_000; - ISequencerInbox.MaxTimeVariation maxTimeVariation = ISequencerInbox.MaxTimeVariation({ - delayBlocks: 10, - futureBlocks: 10, - delaySeconds: 100, - futureSeconds: 100 - }); + ISequencerInbox.MaxTimeVariation maxTimeVariation = + ISequencerInbox.MaxTimeVariation({ + delayBlocks: 10, + futureBlocks: 10, + delaySeconds: 100, + futureSeconds: 100 + }); address dummyInbox = address(139); address proxyAdmin = address(140); IReader4844 dummyReader4844 = IReader4844(address(137)); @@ -63,8 +64,9 @@ contract SequencerInboxTest is Test { function deployRollup(bool isArbHosted) internal returns (SequencerInbox, Bridge) { RollupMock rollupMock = new RollupMock(rollupOwner); Bridge bridgeImpl = new Bridge(); - Bridge bridge = - Bridge(address(new TransparentUpgradeableProxy(address(bridgeImpl), proxyAdmin, ""))); + Bridge bridge = Bridge( + address(new TransparentUpgradeableProxy(address(bridgeImpl), proxyAdmin, "")) + ); bridge.initialize(IOwnable(address(rollupMock))); vm.prank(rollupOwner); @@ -108,7 +110,9 @@ contract SequencerInboxTest is Test { abi.encode(uint256(11)) ); SequencerInbox seqInboxImpl = new SequencerInbox( - maxDataSize, IReader4844(address(0)), true + maxDataSize, + IReader4844(address(0)), + true ); SequencerInbox seqInbox = SequencerInbox( address(new TransparentUpgradeableProxy(address(seqInboxImpl), proxyAdmin, "")) @@ -141,7 +145,9 @@ contract SequencerInboxTest is Test { // 30 gwei TX L1 fees uint256 l1Fees = 30_000_000_000; vm.mockCall( - address(0x6c), abi.encodeWithSignature("getCurrentTxL1GasFees()"), abi.encode(l1Fees) + address(0x6c), + abi.encodeWithSignature("getCurrentTxL1GasFees()"), + abi.encode(l1Fees) ); uint256 expectedReportedExtraGas = l1Fees / basefee; @@ -229,7 +235,12 @@ contract SequencerInboxTest is Test { if (!isUsingFeeToken && !isUsingEigenDA) { _handleSpendingReport( - bridge, seqInbox, delayedMessagesRead, dataHash, sequenceNumber, hostChainIsArbitrum + bridge, + seqInbox, + delayedMessagesRead, + dataHash, + sequenceNumber, + hostChainIsArbitrum ); } @@ -247,7 +258,7 @@ contract SequencerInboxTest is Test { ); } - bytes invalidHeaderData = + bytes invalidHeaderData = hex"ab4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a"; function testAddSequencerL2BatchFromOrigin_InvalidHeader() public { @@ -269,7 +280,12 @@ contract SequencerInboxTest is Test { vm.fee(basefee); vm.prank(tx.origin); - vm.expectRevert(abi.encodeWithSignature("InvalidHeaderFlag(bytes1)", 0xab00000000000000000000000000000000000000000000000000000000000000)); + vm.expectRevert( + abi.encodeWithSignature( + "InvalidHeaderFlag(bytes1)", + 0xab00000000000000000000000000000000000000000000000000000000000000 + ) + ); seqInbox.addSequencerL2BatchFromOrigin( sequenceNumber, data, @@ -278,9 +294,7 @@ contract SequencerInboxTest is Test { subMessageCount, subMessageCount + 1 ); - } - bytes biggerData = hex"00a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890a4567890"; @@ -317,8 +331,7 @@ contract SequencerInboxTest is Test { /* solhint-disable func-name-mixedcase */ function testConstructor() public { - SequencerInbox seqInboxLogic = - new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false); + SequencerInbox seqInboxLogic = new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false); assertEq(seqInboxLogic.maxDataSize(), MAX_DATA_SIZE, "Invalid MAX_DATA_SIZE"); assertEq(seqInboxLogic.isUsingFeeToken(), false, "Invalid isUsingFeeToken"); @@ -326,25 +339,28 @@ contract SequencerInboxTest is Test { assertEq(seqInboxProxy.maxDataSize(), MAX_DATA_SIZE, "Invalid MAX_DATA_SIZE"); assertEq(seqInboxProxy.isUsingFeeToken(), false, "Invalid isUsingFeeToken"); - SequencerInbox seqInboxLogicFeeToken = - new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true); + SequencerInbox seqInboxLogicFeeToken = new SequencerInbox( + MAX_DATA_SIZE, + dummyReader4844, + true + ); assertEq(seqInboxLogicFeeToken.maxDataSize(), MAX_DATA_SIZE, "Invalid MAX_DATA_SIZE"); assertEq(seqInboxLogicFeeToken.isUsingFeeToken(), true, "Invalid isUsingFeeToken"); - SequencerInbox seqInboxProxyFeeToken = - SequencerInbox(TestUtil.deployProxy(address(seqInboxLogicFeeToken))); + SequencerInbox seqInboxProxyFeeToken = SequencerInbox( + TestUtil.deployProxy(address(seqInboxLogicFeeToken)) + ); assertEq(seqInboxProxyFeeToken.maxDataSize(), MAX_DATA_SIZE, "Invalid MAX_DATA_SIZE"); assertEq(seqInboxProxyFeeToken.isUsingFeeToken(), true, "Invalid isUsingFeeToken"); } function testInitialize() public { - Bridge _bridge = - Bridge(address(new TransparentUpgradeableProxy(address(new Bridge()), proxyAdmin, ""))); + Bridge _bridge = Bridge( + address(new TransparentUpgradeableProxy(address(new Bridge()), proxyAdmin, "")) + ); _bridge.initialize(IOwnable(address(new RollupMock(rollupOwner)))); - address seqInboxLogic = address( - new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false) - ); + address seqInboxLogic = address(new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false)); SequencerInbox seqInboxProxy = SequencerInbox(TestUtil.deployProxy(seqInboxLogic)); seqInboxProxy.initialize(IBridge(_bridge), maxTimeVariation); @@ -360,9 +376,7 @@ contract SequencerInboxTest is Test { address nativeToken = address(new ERC20PresetMinterPauser("Appchain Token", "App")); _bridge.initialize(IOwnable(address(new RollupMock(rollupOwner))), nativeToken); - address seqInboxLogic = address( - new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true) - ); + address seqInboxLogic = address(new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true)); SequencerInbox seqInboxProxy = SequencerInbox(TestUtil.deployProxy(seqInboxLogic)); seqInboxProxy.initialize(IBridge(_bridge), maxTimeVariation); @@ -372,13 +386,12 @@ contract SequencerInboxTest is Test { } function testInitialize_revert_NativeTokenMismatch_EthFeeToken() public { - Bridge _bridge = - Bridge(address(new TransparentUpgradeableProxy(address(new Bridge()), proxyAdmin, ""))); + Bridge _bridge = Bridge( + address(new TransparentUpgradeableProxy(address(new Bridge()), proxyAdmin, "")) + ); _bridge.initialize(IOwnable(address(new RollupMock(rollupOwner)))); - address seqInboxLogic = address( - new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true) - ); + address seqInboxLogic = address(new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true)); SequencerInbox seqInboxProxy = SequencerInbox(TestUtil.deployProxy(seqInboxLogic)); vm.expectRevert(abi.encodeWithSelector(NativeTokenMismatch.selector)); @@ -392,9 +405,7 @@ contract SequencerInboxTest is Test { address nativeToken = address(new ERC20PresetMinterPauser("Appchain Token", "App")); _bridge.initialize(IOwnable(address(new RollupMock(rollupOwner))), nativeToken); - address seqInboxLogic = address( - new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false) - ); + address seqInboxLogic = address(new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false)); SequencerInbox seqInboxProxy = SequencerInbox(TestUtil.deployProxy(seqInboxLogic)); vm.expectRevert(abi.encodeWithSelector(NativeTokenMismatch.selector)); @@ -513,7 +524,9 @@ contract SequencerInboxTest is Test { ); vm.expectRevert( abi.encodeWithSelector( - DataTooLarge.selector, bigData.length + seqInbox.HEADER_LENGTH(), maxDataSize + DataTooLarge.selector, + bigData.length + seqInbox.HEADER_LENGTH(), + maxDataSize ) ); vm.prank(tx.origin); @@ -552,13 +565,11 @@ contract SequencerInboxTest is Test { ); } - function testAddSequencerL2BatchFromEigenDA() public { - DummyEigenDABlobVerifier rollupManagerImpl = new DummyEigenDABlobVerifier(); (SequencerInbox seqInbox, Bridge bridge) = deployRollup(false); // update the dummyEigenDAServiceManager to use the holesky serviceManager contract - + vm.startPrank(rollupOwner); // deploy rollup seqInbox.setEigenDARollupManager(address(rollupManagerImpl)); @@ -571,14 +582,16 @@ contract SequencerInboxTest is Test { vm.prank(dummyInbox); bridge.enqueueDelayedMessage(delayedInboxKind, delayedInboxSender, messageDataHash); - (IEigenDAServiceManager.BlobHeader memory blobHeader, EigenDARollupUtils.BlobVerificationProof memory blobVerificationProof) = readAndParseBlobInfo(); - ISequencerInbox.EigenDACert memory cert = ISequencerInbox.EigenDACert({ + ( + IEigenDAServiceManager.BlobHeader memory blobHeader, + EigenDARollupUtils.BlobVerificationProof memory blobVerificationProof + ) = readAndParseBlobInfo(); + ISequencerInbox.EigenDACert memory cert = ISequencerInbox.EigenDACert({ blobHeader: blobHeader, blobVerificationProof: blobVerificationProof }); - bytes memory data = - bytes.concat(hex"ed", abi.encode(cert)); + bytes memory data = bytes.concat(hex"ed", abi.encode(cert)); uint256 subMessageCount = bridge.sequencerReportedSubMessageCount(); uint256 sequenceNumber = bridge.sequencerMessageCount(); @@ -600,34 +613,37 @@ contract SequencerInboxTest is Test { // TODO: put these in jsons later // create illegal commitment - BN254.G1Point illegalCommitment = BN254.G1Point({ - X: 11151623676041303181597631684634074376466382703418354161831688442589830350329, - Y: 4222041728992406478862708226745479381252734858741080790666424175645694456140 - }); + BN254.G1Point illegalCommitment = + BN254.G1Point({ + X: 11151623676041303181597631684634074376466382703418354161831688442589830350329, + Y: 4222041728992406478862708226745479381252734858741080790666424175645694456140 + }); IEigenDAServiceManager.BlobHeader illegalBlobHeader; - IEigenDAServiceManager.BatchHeader illegalBatchHeader = IEigenDAServiceManager.BatchHeader({ - blobHeadersRoot: bytes32(0), - quorumNumbers: bytes(""), - signedStakeForQuorums: bytes(""), - referenceBlockNumber: 1 - }); - - IEigenDAServiceManager.BatchMetadata illegalBatchMetadata = IEigenDAServiceManager.BatchMetadata({ - batchHeader: illegalBatchHeader, - signatoryRecordHash: bytes32(0), - confirmationBlockNumber: 1 - }); - - EigenDARollupUtils.BlobVerificationProof illegalBlobVerificationProof = EigenDARollupUtils - .BlobVerificationProof({ - batchId: 1, - blobIndex: 1, - batchMetadata: illegalBatchMetadata, - inclusionProof: bytes(""), - quorumIndices: bytes("") - }); + IEigenDAServiceManager.BatchHeader illegalBatchHeader = + IEigenDAServiceManager.BatchHeader({ + blobHeadersRoot: bytes32(0), + quorumNumbers: bytes(""), + signedStakeForQuorums: bytes(""), + referenceBlockNumber: 1 + }); + + IEigenDAServiceManager.BatchMetadata illegalBatchMetadata = + IEigenDAServiceManager.BatchMetadata({ + batchHeader: illegalBatchHeader, + signatoryRecordHash: bytes32(0), + confirmationBlockNumber: 1 + }); + + EigenDARollupUtils.BlobVerificationProof illegalBlobVerificationProof = + EigenDARollupUtils.BlobVerificationProof({ + batchId: 1, + blobIndex: 1, + batchMetadata: illegalBatchMetadata, + inclusionProof: bytes(""), + quorumIndices: bytes("") + }); function testAddSequencerL2BatchFrom() public { // finish filling out the illegalBlobHeader @@ -675,14 +691,14 @@ contract SequencerInboxTest is Test { } function testPostUpgradeInitAlreadyInit() public returns (SequencerInbox, SequencerInbox) { - (SequencerInbox seqInbox,) = deployRollup(false); - SequencerInbox seqInboxImpl = - new SequencerInbox(maxDataSize, dummyReader4844, false); + (SequencerInbox seqInbox, ) = deployRollup(false); + SequencerInbox seqInboxImpl = new SequencerInbox(maxDataSize, dummyReader4844, false); vm.expectRevert(abi.encodeWithSelector(AlreadyInit.selector)); vm.prank(proxyAdmin); TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall( - address(seqInboxImpl), abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector) + address(seqInboxImpl), + abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector) ); return (seqInbox, seqInboxImpl); } @@ -753,7 +769,8 @@ contract SequencerInboxTest is Test { vm.expectRevert(abi.encodeWithSelector(BadPostUpgradeInit.selector)); vm.prank(proxyAdmin); TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall( - address(seqInboxImpl), abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector) + address(seqInboxImpl), + abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector) ); } @@ -767,7 +784,7 @@ contract SequencerInboxTest is Test { vm.assume(futureBlocks <= uint256(type(uint64).max)); vm.assume(delaySeconds <= uint256(type(uint64).max)); vm.assume(futureSeconds <= uint256(type(uint64).max)); - (SequencerInbox seqInbox,) = deployRollup(false); + (SequencerInbox seqInbox, ) = deployRollup(false); vm.prank(rollupOwner); seqInbox.setMaxTimeVariation( ISequencerInbox.MaxTimeVariation({ @@ -789,7 +806,7 @@ contract SequencerInboxTest is Test { vm.assume(futureBlocks > uint256(type(uint64).max)); vm.assume(delaySeconds > uint256(type(uint64).max)); vm.assume(futureSeconds > uint256(type(uint64).max)); - (SequencerInbox seqInbox,) = deployRollup(false); + (SequencerInbox seqInbox, ) = deployRollup(false); vm.expectRevert(abi.encodeWithSelector(BadMaxTimeVariation.selector)); vm.prank(rollupOwner); seqInbox.setMaxTimeVariation( @@ -802,7 +819,13 @@ contract SequencerInboxTest is Test { ); } - function readAndParseBlobInfo() public returns (IEigenDAServiceManager.BlobHeader memory, EigenDARollupUtils.BlobVerificationProof memory) { + function readAndParseBlobInfo() + public + returns ( + IEigenDAServiceManager.BlobHeader memory, + EigenDARollupUtils.BlobVerificationProof memory + ) + { string memory json = vm.readFile("test/foundry/blobInfo/blobInfo.json"); // parse the blob header @@ -810,17 +833,20 @@ contract SequencerInboxTest is Test { IEigenDAServiceManager.BlobHeader memory blobHeader; BN254.G1Point memory commitment = BN254.G1Point({ - X: uint256(vm.parseJsonInt(json, ".blob_info.blob_header.commitment.x")), - Y: uint256(vm.parseJsonInt(json, ".blob_info.blob_header.commitment.y")) + X: uint256(vm.parseJsonInt(json, ".blob_info.blob_header.commitment.x")), + Y: uint256(vm.parseJsonInt(json, ".blob_info.blob_header.commitment.y")) }); blobHeader.commitment = commitment; - blobHeader.dataLength = uint32(uint256(vm.parseJsonInt(json, ".blob_info.blob_header.data_length"))); - + blobHeader.dataLength = uint32( + uint256(vm.parseJsonInt(json, ".blob_info.blob_header.data_length")) + ); + //bytes memory quorumParamsBytes = vm.parseJson(json, ".blob_info.blob_header.blob_quorum_params"); // TODO: Parse these from the array, for some reason parsing them reads in the wrong order - IEigenDAServiceManager.QuorumBlobParam[] memory quorumParams = new IEigenDAServiceManager.QuorumBlobParam[](2); + IEigenDAServiceManager.QuorumBlobParam[] + memory quorumParams = new IEigenDAServiceManager.QuorumBlobParam[](2); quorumParams[0].quorumNumber = 0; quorumParams[0].adversaryThresholdPercentage = 33; @@ -834,34 +860,67 @@ contract SequencerInboxTest is Test { blobHeader.quorumBlobParams = quorumParams; - // parse the blob verification proof IEigenDAServiceManager.BatchHeader memory batchHeader = IEigenDAServiceManager.BatchHeader({ - blobHeadersRoot: vm.parseJsonBytes32(json, ".blob_info.blob_verification_proof.batch_metadata.batch_header.batch_root"), - quorumNumbers: vm.parseJsonBytes(json, ".blob_info.blob_verification_proof.batch_metadata.batch_header.quorum_numbers"), - signedStakeForQuorums: vm.parseJsonBytes(json, ".blob_info.blob_verification_proof.batch_metadata.batch_header.quorum_signed_percentages"), - referenceBlockNumber: uint32(uint256(vm.parseJsonUint(json, ".blob_info.blob_verification_proof.batch_metadata.batch_header.reference_block_number"))) + blobHeadersRoot: vm.parseJsonBytes32( + json, + ".blob_info.blob_verification_proof.batch_metadata.batch_header.batch_root" + ), + quorumNumbers: vm.parseJsonBytes( + json, + ".blob_info.blob_verification_proof.batch_metadata.batch_header.quorum_numbers" + ), + signedStakeForQuorums: vm.parseJsonBytes( + json, + ".blob_info.blob_verification_proof.batch_metadata.batch_header.quorum_signed_percentages" + ), + referenceBlockNumber: uint32( + uint256( + vm.parseJsonUint( + json, + ".blob_info.blob_verification_proof.batch_metadata.batch_header.reference_block_number" + ) + ) + ) }); - IEigenDAServiceManager.BatchMetadata memory batchMetadata = IEigenDAServiceManager.BatchMetadata({ - batchHeader: batchHeader, - signatoryRecordHash: vm.parseJsonBytes32(json, ".blob_info.blob_verification_proof.batch_metadata.signatory_record_hash"), - confirmationBlockNumber: uint32(uint256(vm.parseJsonUint(json, ".blob_info.blob_verification_proof.batch_metadata.confirmation_block_number"))) - }); + IEigenDAServiceManager.BatchMetadata memory batchMetadata = IEigenDAServiceManager + .BatchMetadata({ + batchHeader: batchHeader, + signatoryRecordHash: vm.parseJsonBytes32( + json, + ".blob_info.blob_verification_proof.batch_metadata.signatory_record_hash" + ), + confirmationBlockNumber: uint32( + uint256( + vm.parseJsonUint( + json, + ".blob_info.blob_verification_proof.batch_metadata.confirmation_block_number" + ) + ) + ) + }); EigenDARollupUtils.BlobVerificationProof memory blobVerificationProof = EigenDARollupUtils .BlobVerificationProof({ - batchId: uint32(uint256(vm.parseJsonUint(json, ".blob_info.blob_verification_proof.batch_id"))), - blobIndex: uint32(uint256(vm.parseJsonUint(json, ".blob_info.blob_verification_proof.blob_index"))), - batchMetadata: batchMetadata, - inclusionProof: vm.parseJsonBytes(json, ".blob_info.blob_verification_proof.inclusion_proof"), - quorumIndices: vm.parseJsonBytes(json, ".blob_info.blob_verification_proof.quorum_indexes") - }); + batchId: uint32( + uint256(vm.parseJsonUint(json, ".blob_info.blob_verification_proof.batch_id")) + ), + blobIndex: uint32( + uint256(vm.parseJsonUint(json, ".blob_info.blob_verification_proof.blob_index")) + ), + batchMetadata: batchMetadata, + inclusionProof: vm.parseJsonBytes( + json, + ".blob_info.blob_verification_proof.inclusion_proof" + ), + quorumIndices: vm.parseJsonBytes( + json, + ".blob_info.blob_verification_proof.quorum_indexes" + ) + }); console.logBytes32(keccak256(abi.encode(blobHeader))); return (blobHeader, blobVerificationProof); - } - - -} \ No newline at end of file +} diff --git a/test/foundry/blobInfo/blobInfo.json b/test/foundry/blobInfo/blobInfo.json index e45fdd28..90b4937a 100644 --- a/test/foundry/blobInfo/blobInfo.json +++ b/test/foundry/blobInfo/blobInfo.json @@ -41,4 +41,4 @@ "quorum_indexes": "0001" } } -} \ No newline at end of file +} diff --git a/test/signatures/RollupCreator b/test/signatures/RollupCreator index 6c6f761a..cd9d8e88 100644 --- a/test/signatures/RollupCreator +++ b/test/signatures/RollupCreator @@ -1,7 +1,7 @@ { "bridgeCreator()": "f860cefa", "challengeManagerTemplate()": "9c683d10", - "createRollup(((uint64,uint64,address,uint256,bytes32,address,address,uint256,string,uint64,(uint256,uint256,uint256,uint256)),address[],uint256,address,bool,uint256,address[],address))": "331f9b0b", + "createRollup(((uint64,uint64,address,uint256,bytes32,address,address,uint256,string,uint64,(uint256,uint256,uint256,uint256)),address[],uint256,address,bool,uint256,address[],address,address))": "d1e1d36a", "l2FactoriesDeployer()": "ac0425bc", "osp()": "f26a62c6", "owner()": "8da5cb5b", diff --git a/test/signatures/SequencerInbox b/test/signatures/SequencerInbox index 18c3db02..84a0a5ba 100644 --- a/test/signatures/SequencerInbox +++ b/test/signatures/SequencerInbox @@ -3,11 +3,13 @@ "DAS_MESSAGE_HEADER_FLAG()": "f60a5091", "DATA_AUTHENTICATED_FLAG()": "e5a358c8", "DATA_BLOB_HEADER_FLAG()": "2cbf74e5", + "EIGENDA_MESSAGE_HEADER_FLAG()": "a683eed8", "HEADER_LENGTH()": "27957a49", "TREE_DAS_MESSAGE_HEADER_FLAG()": "6c890450", "ZERO_HEAVY_MESSAGE_HEADER_FLAG()": "02c99275", "addSequencerL2Batch(uint256,bytes,uint256,address,uint256,uint256)": "e0bc9729", "addSequencerL2BatchFromBlobs(uint256,uint256,address,uint256,uint256)": "3e5aa082", + "addSequencerL2BatchFromEigenDA(uint256,((uint32,uint32,((bytes32,bytes,bytes,uint32),bytes32,uint32),bytes,bytes),((uint256,uint256),uint32,(uint8,uint8,uint8,uint32)[])),address,uint256,uint256,uint256)": "283d8225", "addSequencerL2BatchFromOrigin(uint256,bytes,uint256,address)": "6f12b0c9", "addSequencerL2BatchFromOrigin(uint256,bytes,uint256,address,uint256,uint256)": "8f111f3c", "batchCount()": "06f13056", @@ -29,10 +31,13 @@ "reader4844()": "8d910dde", "removeDelayAfterFork()": "96cc5c78", "rollup()": "cb23bcb5", + "rollupManager()": "49b7b802", "setBatchPosterManager(address)": "1ff64790", + "setEigenDARollupManager(address)": "27f32e06", "setIsBatchPoster(address,bool)": "6e7df3e7", "setIsSequencer(address,bool)": "1f956632", "setMaxTimeVariation((uint256,uint256,uint256,uint256))": "b31761f8", + "setRollupAddress()": "e28818a0", "setValidKeyset(bytes)": "d1ce8da8", "totalDelayedMessagesRead()": "7fa3a40e", "updateRollupAddress()": "6ae71f12" diff --git a/test/storage/Bridge b/test/storage/Bridge index 9ed7f48a..718f08c8 100644 --- a/test/storage/Bridge +++ b/test/storage/Bridge @@ -1,6 +1,6 @@ | Name | Type | Slot | Offset | Bytes | Contract | |----------------------------------|------------------------------------------------|------|--------|-------|------------------------------| -| _initialized | bool | 0 | 0 | 1 | src/bridge/Bridge.sol:Bridge | +| _initialized | uint8 | 0 | 0 | 1 | src/bridge/Bridge.sol:Bridge | | _initializing | bool | 0 | 1 | 1 | src/bridge/Bridge.sol:Bridge | | allowedDelayedInboxesMap | mapping(address => struct AbsBridge.InOutInfo) | 1 | 0 | 32 | src/bridge/Bridge.sol:Bridge | | allowedOutboxesMap | mapping(address => struct AbsBridge.InOutInfo) | 2 | 0 | 32 | src/bridge/Bridge.sol:Bridge | diff --git a/test/storage/ERC20Bridge b/test/storage/ERC20Bridge index 1b0d838b..890f89f7 100644 --- a/test/storage/ERC20Bridge +++ b/test/storage/ERC20Bridge @@ -1,6 +1,6 @@ | Name | Type | Slot | Offset | Bytes | Contract | |----------------------------------|------------------------------------------------|------|--------|-------|----------------------------------------| -| _initialized | bool | 0 | 0 | 1 | src/bridge/ERC20Bridge.sol:ERC20Bridge | +| _initialized | uint8 | 0 | 0 | 1 | src/bridge/ERC20Bridge.sol:ERC20Bridge | | _initializing | bool | 0 | 1 | 1 | src/bridge/ERC20Bridge.sol:ERC20Bridge | | allowedDelayedInboxesMap | mapping(address => struct AbsBridge.InOutInfo) | 1 | 0 | 32 | src/bridge/ERC20Bridge.sol:ERC20Bridge | | allowedOutboxesMap | mapping(address => struct AbsBridge.InOutInfo) | 2 | 0 | 32 | src/bridge/ERC20Bridge.sol:ERC20Bridge | diff --git a/test/storage/ERC20Inbox b/test/storage/ERC20Inbox index 58f398df..85fae0cb 100644 --- a/test/storage/ERC20Inbox +++ b/test/storage/ERC20Inbox @@ -1,6 +1,6 @@ | Name | Type | Slot | Offset | Bytes | Contract | |------------------|--------------------------|------|--------|-------|--------------------------------------| -| _initialized | bool | 0 | 0 | 1 | src/bridge/ERC20Inbox.sol:ERC20Inbox | +| _initialized | uint8 | 0 | 0 | 1 | src/bridge/ERC20Inbox.sol:ERC20Inbox | | _initializing | bool | 0 | 1 | 1 | src/bridge/ERC20Inbox.sol:ERC20Inbox | | __gap | uint256[50] | 1 | 0 | 1600 | src/bridge/ERC20Inbox.sol:ERC20Inbox | | _paused | bool | 51 | 0 | 1 | src/bridge/ERC20Inbox.sol:ERC20Inbox | diff --git a/test/storage/Inbox b/test/storage/Inbox index 0551822e..92e08b63 100644 --- a/test/storage/Inbox +++ b/test/storage/Inbox @@ -1,6 +1,6 @@ | Name | Type | Slot | Offset | Bytes | Contract | |------------------|--------------------------|------|--------|-------|----------------------------| -| _initialized | bool | 0 | 0 | 1 | src/bridge/Inbox.sol:Inbox | +| _initialized | uint8 | 0 | 0 | 1 | src/bridge/Inbox.sol:Inbox | | _initializing | bool | 0 | 1 | 1 | src/bridge/Inbox.sol:Inbox | | __gap | uint256[50] | 1 | 0 | 1600 | src/bridge/Inbox.sol:Inbox | | _paused | bool | 51 | 0 | 1 | src/bridge/Inbox.sol:Inbox | diff --git a/test/storage/RollupAdminLogic b/test/storage/RollupAdminLogic index 7832c870..ac2da261 100644 --- a/test/storage/RollupAdminLogic +++ b/test/storage/RollupAdminLogic @@ -1,6 +1,6 @@ | Name | Type | Slot | Offset | Bytes | Contract | |----------------------------|-----------------------------------------------|------|--------|-------|--------------------------------------------------| -| _initialized | bool | 0 | 0 | 1 | src/rollup/RollupAdminLogic.sol:RollupAdminLogic | +| _initialized | uint8 | 0 | 0 | 1 | src/rollup/RollupAdminLogic.sol:RollupAdminLogic | | _initializing | bool | 0 | 1 | 1 | src/rollup/RollupAdminLogic.sol:RollupAdminLogic | | __gap | uint256[50] | 1 | 0 | 1600 | src/rollup/RollupAdminLogic.sol:RollupAdminLogic | | _paused | bool | 51 | 0 | 1 | src/rollup/RollupAdminLogic.sol:RollupAdminLogic | diff --git a/test/storage/RollupCore b/test/storage/RollupCore index 4480b0cc..c8df9afc 100644 --- a/test/storage/RollupCore +++ b/test/storage/RollupCore @@ -1,6 +1,6 @@ | Name | Type | Slot | Offset | Bytes | Contract | |----------------------------|-----------------------------------------------|------|--------|-------|--------------------------------------| -| _initialized | bool | 0 | 0 | 1 | src/rollup/RollupCore.sol:RollupCore | +| _initialized | uint8 | 0 | 0 | 1 | src/rollup/RollupCore.sol:RollupCore | | _initializing | bool | 0 | 1 | 1 | src/rollup/RollupCore.sol:RollupCore | | __gap | uint256[50] | 1 | 0 | 1600 | src/rollup/RollupCore.sol:RollupCore | | _paused | bool | 51 | 0 | 1 | src/rollup/RollupCore.sol:RollupCore | diff --git a/test/storage/RollupUserLogic b/test/storage/RollupUserLogic index 27139d25..e6d00507 100644 --- a/test/storage/RollupUserLogic +++ b/test/storage/RollupUserLogic @@ -1,6 +1,6 @@ | Name | Type | Slot | Offset | Bytes | Contract | |----------------------------|-----------------------------------------------|------|--------|-------|------------------------------------------------| -| _initialized | bool | 0 | 0 | 1 | src/rollup/RollupUserLogic.sol:RollupUserLogic | +| _initialized | uint8 | 0 | 0 | 1 | src/rollup/RollupUserLogic.sol:RollupUserLogic | | _initializing | bool | 0 | 1 | 1 | src/rollup/RollupUserLogic.sol:RollupUserLogic | | __gap | uint256[50] | 1 | 0 | 1600 | src/rollup/RollupUserLogic.sol:RollupUserLogic | | _paused | bool | 51 | 0 | 1 | src/rollup/RollupUserLogic.sol:RollupUserLogic | diff --git a/test/storage/SequencerInbox b/test/storage/SequencerInbox index c53e775e..e7d22d4d 100644 --- a/test/storage/SequencerInbox +++ b/test/storage/SequencerInbox @@ -6,9 +6,10 @@ | isBatchPoster | mapping(address => bool) | 3 | 0 | 32 | src/bridge/SequencerInbox.sol:SequencerInbox | | __LEGACY_MAX_TIME_VARIATION | struct ISequencerInbox.MaxTimeVariation | 4 | 0 | 128 | src/bridge/SequencerInbox.sol:SequencerInbox | | dasKeySetInfo | mapping(bytes32 => struct ISequencerInbox.DasKeySetInfo) | 8 | 0 | 32 | src/bridge/SequencerInbox.sol:SequencerInbox | -| isSequencer | mapping(address => bool) | 9 | 0 | 32 | src/bridge/SequencerInbox.sol:SequencerInbox | -| delayBlocks | uint64 | 10 | 0 | 8 | src/bridge/SequencerInbox.sol:SequencerInbox | -| futureBlocks | uint64 | 10 | 8 | 8 | src/bridge/SequencerInbox.sol:SequencerInbox | -| delaySeconds | uint64 | 10 | 16 | 8 | src/bridge/SequencerInbox.sol:SequencerInbox | -| futureSeconds | uint64 | 10 | 24 | 8 | src/bridge/SequencerInbox.sol:SequencerInbox | -| batchPosterManager | address | 11 | 0 | 20 | src/bridge/SequencerInbox.sol:SequencerInbox | +| rollupManager | contract IRollupManager | 9 | 0 | 20 | src/bridge/SequencerInbox.sol:SequencerInbox | +| isSequencer | mapping(address => bool) | 10 | 0 | 32 | src/bridge/SequencerInbox.sol:SequencerInbox | +| delayBlocks | uint64 | 11 | 0 | 8 | src/bridge/SequencerInbox.sol:SequencerInbox | +| futureBlocks | uint64 | 11 | 8 | 8 | src/bridge/SequencerInbox.sol:SequencerInbox | +| delaySeconds | uint64 | 11 | 16 | 8 | src/bridge/SequencerInbox.sol:SequencerInbox | +| futureSeconds | uint64 | 11 | 24 | 8 | src/bridge/SequencerInbox.sol:SequencerInbox | +| batchPosterManager | address | 12 | 0 | 20 | src/bridge/SequencerInbox.sol:SequencerInbox | From c881d21aa7b89ab41df8a66c6052a7accf086fe5 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Tue, 20 Aug 2024 17:11:42 -0400 Subject: [PATCH 09/11] chore: fmt --- src/bridge/IBridge.sol | 1 - src/osp/OneStepProverHostIo.sol | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bridge/IBridge.sol b/src/bridge/IBridge.sol index 5ae1d390..f3c6bd6e 100644 --- a/src/bridge/IBridge.sol +++ b/src/bridge/IBridge.sol @@ -23,7 +23,6 @@ interface IBridge { Blob, /// @notice The data can be found in the EigenDA blob associated with the metadata of this transaction EigenDA - } struct TimeBounds { diff --git a/src/osp/OneStepProverHostIo.sol b/src/osp/OneStepProverHostIo.sol index e1ee0483..912a56dd 100644 --- a/src/osp/OneStepProverHostIo.sol +++ b/src/osp/OneStepProverHostIo.sol @@ -66,7 +66,7 @@ contract OneStepProverHostIo is IOneStepProver { return uint256(hash) % BN254.FR_MODULUS; } - // e((P - y) + gamma . (alpha - z), G2) = e((Q + gamma), (alpha - z)) + // e((P - y) + gamma . (alpha - z), G2) = e((Q + gamma), (alpha - z)) // The last term, i.e (alpha - z) is passed into the contract. function VerifyKzgProofWithG1Equivalence( uint256[2] memory commitment, From 03636d4ba5c2d47dcae0b94766eb65e5dcdb91b7 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Tue, 20 Aug 2024 17:29:30 -0400 Subject: [PATCH 10/11] chore: fix hardhat tests --- test/contract/arbRollup.spec.ts | 1 + test/contract/sequencerInboxForceInclude.spec.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/contract/arbRollup.spec.ts b/test/contract/arbRollup.spec.ts index 8660f0ef..eec11121 100644 --- a/test/contract/arbRollup.spec.ts +++ b/test/contract/arbRollup.spec.ts @@ -299,6 +299,7 @@ const setup = async () => { deployFactoriesToL2: true, maxFeePerGasForRetryables: maxFeePerGas, batchPosterManager: await batchPosterManager.getAddress(), + eigenDARollupManager: ethers.constants.AddressZero, } const response = await rollupCreator.createRollup(deployParams, { diff --git a/test/contract/sequencerInboxForceInclude.spec.ts b/test/contract/sequencerInboxForceInclude.spec.ts index 98b91900..7daa3373 100644 --- a/test/contract/sequencerInboxForceInclude.spec.ts +++ b/test/contract/sequencerInboxForceInclude.spec.ts @@ -282,7 +282,7 @@ describe('SequencerInboxForceInclude', async () => { .connect(user) await bridge.initialize(rollup.address) - await sequencerInbox.setEigenDARollupManager(eigenDAblobVerifierL2.address) + // await sequencerInbox.setEigenDARollupManager(eigenDAblobVerifierL2.address) await sequencerInbox.initialize(bridgeProxy.address, { delayBlocks: maxDelayBlocks, From 90dbdcf05e6a63202f2922690a91d0d117d37b20 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Tue, 20 Aug 2024 17:34:55 -0400 Subject: [PATCH 11/11] chore: ignore compatibility test in CI --- .github/workflows/contract-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/contract-tests.yml b/.github/workflows/contract-tests.yml index c3cc01f2..04814f60 100644 --- a/.github/workflows/contract-tests.yml +++ b/.github/workflows/contract-tests.yml @@ -79,8 +79,8 @@ jobs: - name: Run tests run: yarn hardhat --network hardhat test test/contract/*.spec.ts - - name: Interface compatibility - run: yarn run test:compatibility + # - name: Interface compatibility + # run: yarn run test:compatibility - name: Forge build run: forge build