Skip to content

Commit

Permalink
dynmaic chain id
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Jul 17, 2024
1 parent ec98fe7 commit 990b338
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/HdpExecutionStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ contract HdpExecutionStore is AccessControl {
/// @notice interface to the facts registry of SHARP
IFactsRegistry public immutable SHARP_FACTS_REGISTRY;

/// @notice constant representing the chain id of Sepolia
uint256 public constant SEPOLIA_CHAIN_ID = 11155111;
/// @notice immutable representing the chain id
uint256 public immutable CHAIN_ID;

/// @notice interface to the aggregators factory
IAggregatorsFactory public immutable AGGREGATORS_FACTORY;
Expand All @@ -85,6 +85,7 @@ contract HdpExecutionStore is AccessControl {
SHARP_FACTS_REGISTRY = factsRegistry;
AGGREGATORS_FACTORY = aggregatorsFactory;
PROGRAM_HASH = programHash;
CHAIN_ID = block.chainid;

_setRoleAdmin(OPERATOR_ROLE, OPERATOR_ROLE);
_grantRole(OPERATOR_ROLE, _msgSender());
Expand All @@ -101,7 +102,7 @@ contract HdpExecutionStore is AccessControl {
function cacheMmrRoot(uint256 mmrId) public {
ISharpFactsAggregator aggregator = AGGREGATORS_FACTORY.aggregatorsById(mmrId);
ISharpFactsAggregator.AggregatorState memory aggregatorState = aggregator.aggregatorState();
cachedMMRsRoots[SEPOLIA_CHAIN_ID][mmrId][aggregatorState.mmrSize] = aggregatorState.poseidonMmrRoot;
cachedMMRsRoots[CHAIN_ID][mmrId][aggregatorState.mmrSize] = aggregatorState.poseidonMmrRoot;

emit MmrRootCached(mmrId, aggregatorState.mmrSize, aggregatorState.poseidonMmrRoot);
}
Expand Down Expand Up @@ -172,7 +173,7 @@ contract HdpExecutionStore is AccessControl {
bytes32[] calldata taskCommitments,
bytes32[] calldata taskResults
) external onlyOperator {
assert (mmrIds.length == mmrSizes.length);
assert(mmrIds.length == mmrSizes.length);

// Initialize an array of uint256 to store the program output
uint256[] memory programOutput = new uint256[](4 + mmrIds.length * 4);
Expand All @@ -187,7 +188,7 @@ contract HdpExecutionStore is AccessControl {
bytes32 usedMmrRoot = loadMmrRoot(mmrIds[i], mmrSizes[i]);
programOutput[4 + i * 4] = mmrIds[i];
programOutput[4 + i * 4 + 1] = mmrSizes[i];
programOutput[4 + i * 4 + 2] = SEPOLIA_CHAIN_ID;
programOutput[4 + i * 4 + 2] = CHAIN_ID;
programOutput[4 + i * 4 + 3] = uint256(usedMmrRoot);
}

Expand Down Expand Up @@ -240,7 +241,7 @@ contract HdpExecutionStore is AccessControl {

/// @notice Load MMR root from cache with given mmrId and mmrSize
function loadMmrRoot(uint256 mmrId, uint256 mmrSize) public view returns (bytes32) {
return cachedMMRsRoots[SEPOLIA_CHAIN_ID][mmrId][mmrSize];
return cachedMMRsRoots[CHAIN_ID][mmrId][mmrSize];
}

/// @notice Returns the result of a finalized task
Expand Down
6 changes: 4 additions & 2 deletions test/BlockSampledHdpExecutionStore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ contract HdpExecutionStoreTest is Test {
});

function setUp() public {
vm.chainId(11155111);
// Registery for facts that has been processed through SHARP
factsRegistry = new MockFactsRegistry();
// Factory for creating SHARP facts aggregators
Expand Down Expand Up @@ -135,7 +136,7 @@ contract HdpExecutionStoreTest is Test {
Uint256Splitter.split128(uint256(bytes32(fetchedResultsMerkleRoot)));

// Cache MMR root
for(uint i = 0; i < fetchedMmrIds.length; i++) {
for (uint256 i = 0; i < fetchedMmrIds.length; i++) {
hdp.cacheMmrRoot(fetchedMmrIds[i]);
}
// Compute fact hash from PIE file
Expand Down Expand Up @@ -245,7 +246,8 @@ contract HdpExecutionStoreTest is Test {
tasksCommitments,
taskResults
) = abi.decode(
abiEncoded, (uint256[], uint256[], bytes32[], bytes32, bytes32, bytes32[][], bytes32[][], bytes32[], bytes32[])
abiEncoded,
(uint256[], uint256[], bytes32[], bytes32, bytes32, bytes32[][], bytes32[][], bytes32[], bytes32[])
);
}
}
6 changes: 4 additions & 2 deletions test/TransactionsInBlockHdpExecutionStore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ contract HdpExecutionStoreTest is Test {
ComputationalTask({aggregateFnId: AggregateFn.SLR, operatorId: Operator.NONE, valueToCompare: uint256(50)});

function setUp() public {
vm.chainId(11155111);
// Registery for facts that has been processed through SHARP
factsRegistry = new MockFactsRegistry();
// Factory for creating SHARP facts aggregators
Expand Down Expand Up @@ -137,7 +138,7 @@ contract HdpExecutionStoreTest is Test {
Uint256Splitter.split128(uint256(bytes32(fetchedResultsMerkleRoot)));

// Cache MMR roots
for(uint i = 0; i < fetchedMmrIds.length; i++) {
for (uint256 i = 0; i < fetchedMmrIds.length; i++) {
hdp.cacheMmrRoot(fetchedMmrIds[i]);
}

Expand Down Expand Up @@ -248,7 +249,8 @@ contract HdpExecutionStoreTest is Test {
tasksCommitments,
taskResults
) = abi.decode(
abiEncoded, (uint256[], uint256[], bytes32[], bytes32, bytes32, bytes32[][], bytes32[][], bytes32[], bytes32[])
abiEncoded,
(uint256[], uint256[], bytes32[], bytes32, bytes32, bytes32[][], bytes32[][], bytes32[], bytes32[])
);
}
}

0 comments on commit 990b338

Please sign in to comment.