Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix failing SequencerInbox test #8

Merged
merged 9 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/contract-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
version: nightly-5b7e4cb3c882b28f3c32ba580de27ce7381f415a

- name: Setup node/yarn
uses: actions/setup-node@v3
Expand All @@ -34,7 +34,7 @@ jobs:
run: yarn

- name: Build
run: forge test
run: forge test --fork-url https://rpc.holesky.ethpandaops.io/
tests:
name: Contract tests
runs-on: ubuntu-8
Expand Down
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ optimizer = true
optimizer_runs = 100
via_ir = false
solc_version = '0.8.12'
fs_permissions = [{ access = "read", path = "./"}]

[profile.yul]
src = 'yul'
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@
"postinstall": "patch-package",
"deploy-factory": "hardhat run scripts/deployment.ts",
"deploy-eth-rollup": "hardhat run scripts/createEthRollup.ts",
"deploy-erc20-rollup": "hardhat run scripts/createERC20Rollup.ts"
"deploy-erc20-rollup": "hardhat run scripts/createERC20Rollup.ts",
"deploy-blob": "yarn ts-node scripts/disperseBlob.ts"
},
"dependencies": {
"@eigenda/eigenda-utils": "2.0.0",
"@grpc/grpc-js": "^1.8.22",
"@grpc/proto-loader": "^0.7.13",
"@offchainlabs/upgrade-executor": "1.1.0-beta.0",
"@openzeppelin-upgrades/contracts": "npm:@openzeppelin/contracts-upgradeable@4.7",
"@openzeppelin/contracts": "4.7",
"@openzeppelin/contracts-upgradeable": "4.7",
"google-protobuf": "^3.21.2",
"patch-package": "^6.4.7"
},
"private": false,
Expand All @@ -62,6 +66,7 @@
"@typechain/ethers-v5": "^10.0.0",
"@typechain/hardhat": "^6.0.0",
"@types/chai": "^4.3.0",
"@types/google-protobuf": "^3.15.12",
"@types/mocha": "^9.0.0",
"@types/node": "^17.0.5",
"@typescript-eslint/eslint-plugin": "^5.14.0",
Expand Down
3 changes: 3 additions & 0 deletions src/bridge/ISequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ interface ISequencerInbox is IDelayedMessageProvider {

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

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

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

Expand Down
8 changes: 7 additions & 1 deletion src/bridge/SequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {IERC20Bridge} from "./IERC20Bridge.sol";
import {IRollupManager} from "./RollupManager.sol";
import {IEigenDAServiceManager} from "@eigenda/eigenda-utils/interfaces/IEigenDAServiceManager.sol";


/**
* @title Accepts batches from the sequencer and adds them to the rollup inbox.
* @notice Contains the inbox accumulator which is the ordering of all data and transactions to be processed by the rollup.
Expand Down Expand Up @@ -424,7 +425,6 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
) external {
if (!isBatchPoster[msg.sender]) revert NotBatchPoster();

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

// NOTE: to retrieve need the following
Expand Down Expand Up @@ -798,6 +798,12 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
emit OwnerFunctionCalled(31);
}

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

function isValidKeysetHash(bytes32 ksHash) external view returns (bool) {
return dasKeySetInfo[ksHash].isValidKeyset;
}
Expand Down
13 changes: 11 additions & 2 deletions test/foundry/ERC20Outbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ contract ERC20OutboxTest is AbsOutboxTest {

function setUp() public {
// deploy token, bridge and outbox
nativeToken = new ERC20PresetFixedSupply("Appchain Token", "App", 1_000_000, address(this));

// 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));
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())));
Expand Down Expand Up @@ -51,7 +57,10 @@ contract ERC20OutboxTest is AbsOutboxTest {
);

// create msg receiver on L1
ERC20L2ToL1Target target = new ERC20L2ToL1Target();
// hardcoded proof in tests assume that this contract is deployed at the repsective address
ERC20L2ToL1Target targetCode = new ERC20L2ToL1Target();
ERC20L2ToL1Target target = ERC20L2ToL1Target(0x87B2d08110B7D50861141D7bBDd49326af3Ecb31);
vm.etch(address(target), address(targetCode).code);
target.setOutbox(address(outbox));

//// execute transaction
Expand Down
138 changes: 79 additions & 59 deletions test/foundry/SequencerInbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol"

import {EigenDARollupUtils} from "@eigenda/eigenda-utils/libraries/EigenDARollupUtils.sol";
import {IEigenDAServiceManager} from "@eigenda/eigenda-utils/interfaces/IEigenDAServiceManager.sol";
import {EigenDARollupManager} from "../../src/bridge/RollupManager.sol";
import {BN254} from "@eigenda/eigenda-utils/libraries/BN254.sol";

contract RollupMock {
Expand Down Expand Up @@ -590,75 +591,31 @@ contract SequencerInboxTest is Test {
);
}

// TODO: put these in jsons later
// grpcurl \
// -import-path ./api/proto \
// -proto ./api/proto/disperser/disperser.proto \
// -d '{"request_id": "NmQ2ODZiOWY4YzcwOGQ0YjhhNDJiN2FiOGRjYmI2MDAzOTk2NDk4NTU5Nzk0OWZkNjQ3ZGE4N2I2NDViZGUxNS0zMTM3MzEzMjM4MzQzNTMyMzgzNjMzMzkzODM5MzYzOTM3MzMzNDJmMzAyZjMzMzMyZjMxMmYzMzMzMmZlM2IwYzQ0Mjk4ZmMxYzE0OWFmYmY0Yzg5OTZmYjkyNDI3YWU0MWU0NjQ5YjkzNGNhNDk1OTkxYjc4NTJiODU1"}' \
// disperser-holesky.eigenda.xyz:443 disperser.Disperser/GetBlobStatus
BN254.G1Point commitment = BN254.G1Point({
X: 11973800683352706081745043032492841023821816921595457420358142752350183450007,
Y: 2805225659489681354691976220137232537594717765057043399317547797368322962514
});

IEigenDAServiceManager.BlobHeader blobHeader;

IEigenDAServiceManager.BatchHeader batchHeader = IEigenDAServiceManager.BatchHeader({
blobHeadersRoot: 0x2f3d0afe00f1a3eccb2a77a053c9fa850d4809913ece2f6a5dcdc9ecb5347c8b,
quorumNumbers: hex"0001",
signedStakeForQuorums: hex"4d4f", // quorum_signed_percentages
referenceBlockNumber: 1325741
});

IEigenDAServiceManager.BatchMetadata batchMetadata = IEigenDAServiceManager.BatchMetadata({
batchHeader: batchHeader,
signatoryRecordHash: 0x9c2295a45e69a5369008e65fa2afc40eccb8e8be2f453998207e9b0a8d3bc72b,
confirmationBlockNumber: 1325845
});

EigenDARollupUtils.BlobVerificationProof blobVerificationProof = EigenDARollupUtils
.BlobVerificationProof({
batchId: 9869,
blobIndex: 570,
batchMetadata: batchMetadata,
inclusionProof: hex"86d042bea74e8fc60ce55410490d2e8bf312ff03aca9d369296d8cb25cd622096d79ebf24023971807ca680bfeac081bca250544e65147ffc0f7fdd3f3f973b885c252331c8385b767138702b5ba6155ae518fd98ebb966c5d2dfc2364ee0d49c203f38ebd01f85755bd59903ad850ea040fb94611fd554deb03c35ce43453f616866b1248350c1f1af7f3ce0f9b1beb712de850ce4e9cdfee6073fd54b8bca69011c9eca7800d59e6831f055972ae7430b8b52423cf455c2e0a3b11343890c713b16d87b5458476d589dd0f2146b14b9380f69aa8b1b546c75de4bfe925167204dd92138a76c02a4854973ed7016c6c110d41563acbc8cafefbe5d2f0ff490a83cd05a84bdfdd1542ebbbf20ca8b8968407a993919ffe5e159faf5941a95ae878a69d797b170a7a375d88b92c000c70871ae9ed5042f481743a27e97cf8665e8ebdea8f3dc226cc4c9a1cf3863ab4e60900a600fbfe5381cc0912f7aab88686",
quorumIndices: hex"0001"
});

function testAddSequencerL2BatchFromEigenDA() public {
blobHeader.commitment = commitment;
blobHeader.dataLength = 1;
blobHeader.quorumBlobParams.push(
IEigenDAServiceManager.QuorumBlobParam({
quorumNumber: 0,
adversaryThresholdPercentage: 33,
confirmationThresholdPercentage: 55,
chunkLength: 1
})
);
blobHeader.quorumBlobParams.push(
IEigenDAServiceManager.QuorumBlobParam({
quorumNumber: 1,
adversaryThresholdPercentage: 33,
confirmationThresholdPercentage: 55,
chunkLength: 1
})
);

EigenDARollupManager rollupManagerImpl = new EigenDARollupManager();
(SequencerInbox seqInbox, Bridge bridge) = deployRollup(false);
// update the dummyEigenDAServiceManager to use the holesky serviceManager contract
vm.prank(rollupOwner);

vm.startPrank(rollupOwner);
// deploy rollup
seqInbox.updateEigenDARollupManager(address(rollupManagerImpl));
seqInbox.updateEigenDAServiceManager(0xD4A7E1Bd8015057293f0D0A557088c286942e84b);
vm.stopPrank();

address delayedInboxSender = address(140);
uint8 delayedInboxKind = 3;
bytes32 messageDataHash = RAND.Bytes32();

vm.prank(dummyInbox);
bridge.enqueueDelayedMessage(delayedInboxKind, delayedInboxSender, messageDataHash);

(IEigenDAServiceManager.BlobHeader memory blobHeader, EigenDARollupUtils.BlobVerificationProof memory blobVerificationProof) = readAndParseBlobInfo();

// ed is EIGEN_DA_MESSAGE_HEADER_FLAG rest is abi.encodePacked(blobHeader.commitment.X, blobHeader.commitment.Y, blobHeader.dataLength)
bytes memory data =
hex"ed1a78ee576b0026de661b72106bf447f5bb70881f24a3fa8b1f312992c8e165970633b392b3d3f66407d912aafcc2f0231c31918f0485e8476975edc710fcb45200000001";
abi.encodePacked(hex"ed",blobHeader.commitment.X, blobHeader.commitment.Y, blobHeader.dataLength);

uint256 subMessageCount = bridge.sequencerReportedSubMessageCount();
uint256 sequenceNumber = bridge.sequencerMessageCount();
Expand Down Expand Up @@ -710,7 +667,7 @@ contract SequencerInboxTest is Test {
quorumIndices: bytes("")
});

function testAddSequencerL2BatchFromEigenDARevert() public {
function testAddSequencerL2BatchFrom() public {
// finish filling out the illegalBlobHeader
illegalBlobHeader.commitment = illegalCommitment;
illegalBlobHeader.dataLength = 20;
Expand Down Expand Up @@ -781,10 +738,10 @@ contract SequencerInboxTest is Test {
);

// IMPORTANT: slots have moved down by one because we have added additional variables for eigenDA
vm.store(address(seqInbox), bytes32(uint256(5)), bytes32(uint256(delayBlocks))); // slot 5: delayBlocks
vm.store(address(seqInbox), bytes32(uint256(6)), bytes32(uint256(futureBlocks))); // slot 6: futureBlocks
vm.store(address(seqInbox), bytes32(uint256(7)), bytes32(uint256(delaySeconds))); // slot 7: delaySeconds
vm.store(address(seqInbox), bytes32(uint256(8)), bytes32(uint256(futureSeconds))); // slot 8: futureSeconds
vm.store(address(seqInbox), bytes32(uint256(6)), bytes32(uint256(delayBlocks))); // slot 6: delayBlocks
vm.store(address(seqInbox), bytes32(uint256(7)), bytes32(uint256(futureBlocks))); // slot 7: futureBlocks
vm.store(address(seqInbox), bytes32(uint256(8)), bytes32(uint256(delaySeconds))); // slot 8: delaySeconds
vm.store(address(seqInbox), bytes32(uint256(9)), bytes32(uint256(futureSeconds))); // slot 9: futureSeconds
vm.prank(proxyAdmin);
TransparentUpgradeableProxy(payable(address(seqInbox))).upgradeToAndCall(
address(seqInboxImpl), abi.encodeWithSelector(SequencerInbox.postUpgradeInit.selector)
Expand Down Expand Up @@ -872,4 +829,67 @@ contract SequencerInboxTest is Test {
})
);
}

function readAndParseBlobInfo() public returns (IEigenDAServiceManager.BlobHeader memory, EigenDARollupUtils.BlobVerificationProof memory) {
string memory json = vm.readFile("test/foundry/blobInfo/blobInfo.json");

// parse the blob header

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"))
});

blobHeader.commitment = commitment;
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);

quorumParams[0].quorumNumber = 0;
quorumParams[0].adversaryThresholdPercentage = 33;
quorumParams[0].confirmationThresholdPercentage = 55;
quorumParams[0].chunkLength = 1;

quorumParams[1].quorumNumber = 1;
quorumParams[1].adversaryThresholdPercentage = 33;
quorumParams[1].confirmationThresholdPercentage = 55;
quorumParams[1].chunkLength = 1;

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")))
});

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")
});
console.logBytes32(keccak256(abi.encode(blobHeader)));
return (blobHeader, blobVerificationProof);

}


}
44 changes: 44 additions & 0 deletions test/foundry/blobInfo/blobInfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"request_id": "316638323561613266303032306566376366393164666133306461343636386437393163356434383234666338653431333534623839656330353739356162332d33313337333133393335333233373333333633303336333133363333333533303330333133363266333032663333333332663331326633333333326665336230633434323938666331633134396166626634633839393666623932343237616534316534363439623933346361343935393931623738353262383535",
"blob_info": {
"blob_header": {
"commitment": {
"x": "0x2569a1994232d43b210e860d876c0bbc8d7f22dc0b8ae17d4c369ce7c2d33c26",
"y": "0x14f8198412fea43aaeb4a5355600d0fe3f175ea2f5d7246a7c6472c453fcde53"
},
"data_length": 1,
"blob_quorum_params": [
{
"quorum_number": 0,
"adversary_threshold_percentage": 33,
"confirmation_threshold_percentage": 55,
"chunk_length": 1
},
{
"quorum_number": 1,
"adversary_threshold_percentage": 33,
"confirmation_threshold_percentage": 55,
"chunk_length": 1
}
]
},
"blob_verification_proof": {
"batch_id": 21103,
"blob_index": 1905,
"batch_metadata": {
"batch_header": {
"batch_root": "d627b55c1f307c37d0543562cdb2e1faf907dd98c1e5f94be62785ac30cca851",
"quorum_numbers": "0001",
"quorum_signed_percentages": "6362",
"reference_block_number": 1820787
},
"signatory_record_hash": "390703dea190bab4fc41037a72055dfe8ad3df2cf359a15dca3ebe601c4a0bd9",
"fee": "00",
"confirmation_block_number": 1820926,
"batch_header_hash": "f38003c8fed893238c3e8712efe1149333ed86a163fffdb77c98595fa76454aa"
},
"inclusion_proof": "75ad90fbbde05f97f78dd7908f85a45c4e851cc29b796b70f78cf704a6e32815089c0d4db7fafbb64881a16d7f85e0e8c87129295a31a33e496cde48b1d08c8355754e58189833af2acd177159cd5f433420f335089f657643b85bef9d5701972354f1d752a9d31fce3ca7773c341b8aa729c88a2b3a2bb678c166f563b33f622c587b69c2ec92c998385010f08dc4170a08747c42e23ef429b67cf505a471d0eed3f79adb6a4d781e242ff800c29214f8fbf4f57d7d57ea48082f54e52d7f759afd178572e6986ba7ef6e9050184332eebd04cec473279188ae2a0f780d2ed69a0b17cfa3962bc09162db8b469ae8a38e3db31042338457f765c77f6b28cdd7e14df7b2c40f27f32bd7d4907816fb2655e06414a5b180ade4ebe295662c007428e2141faccaee62f177305df72d1f3b0f8dfc90235272f9a741af4eae6af6dc7bce2ce5f9c820c78fe436beaeef9b6734702cfc3d7863fac39ed52dc3061a1cf4f895c0797e6aff0a6076044102b00663e5e74f5ec53e4621312b98f4c74a7e",
"quorum_indexes": "0001"
}
}
}
Loading
Loading