Skip to content

Commit

Permalink
Merge pull request #23 from hermeznetwork/feature/realProver
Browse files Browse the repository at this point in the history
first integration with real prover
  • Loading branch information
krlosMata authored Feb 3, 2022
2 parents a4fa3cc + 554fa34 commit 1c3516a
Show file tree
Hide file tree
Showing 16 changed files with 715 additions and 30 deletions.
81 changes: 66 additions & 15 deletions contracts/mocks/ProofOfEfficiencyMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ contract ProofOfEfficiencyMock is ProofOfEfficiency {
* @param numBatch Batch number that the aggregator intends to verify, used as a sanity check
*/
function getNextCircuitInput(
bytes32 newStateRoot,
bytes32 newLocalExitRoot,
bytes32 newStateRoot,
uint32 numBatch
) public view returns (uint256) {
// sanity check
Expand All @@ -81,15 +81,6 @@ contract ProofOfEfficiencyMock is ProofOfEfficiency {

// Calculate Circuit Input
BatchData memory currentBatch = sentBatches[numBatch];
address sequencerAddress = currentBatch.sequencerAddress;

uint32 batchChainID;
if (sequencers[sequencerAddress].chainID != 0) {
batchChainID = sequencers[sequencerAddress].chainID;
} else {
// If the sequencer is not registered use the default chainID
batchChainID = DEFAULT_CHAIN_ID;
}

uint256 input = uint256(
keccak256(
Expand All @@ -98,29 +89,62 @@ contract ProofOfEfficiencyMock is ProofOfEfficiency {
currentLocalExitRoot,
newStateRoot,
newLocalExitRoot,
sequencerAddress,
currentBatch.sequencerAddress,
currentBatch.batchHashData,
batchChainID,
currentBatch.chainID,
numBatch
)
)
) % _RFIELD;
return input;
}

/**
* @notice Return the input hash parameters
* @param newStateRoot New State root once the batch is processed
* @param newLocalExitRoot New local exit root once the batch is processed
* @param numBatch Batch number that the aggregator intends to verify, used as a sanity check
*/
function returnInputHashParameters(
bytes32 newLocalExitRoot,
bytes32 newStateRoot,
uint32 numBatch
) public view returns (bytes memory) {
// sanity check
require(
numBatch == lastVerifiedBatch + 1,
"ProofOfEfficiency::verifyBatch: BATCH_DOES_NOT_MATCH"
);

// Calculate Circuit Input
BatchData memory currentBatch = sentBatches[numBatch];

return
abi.encodePacked(
currentStateRoot,
currentLocalExitRoot,
newStateRoot,
newLocalExitRoot,
currentBatch.sequencerAddress,
currentBatch.batchHashData,
currentBatch.chainID,
numBatch
);
}

/**
* @notice Set state root
* @param newStateRoot New State root ¡
*/
function setStateRoot(bytes32 newStateRoot) public {
function setStateRoot(bytes32 newStateRoot) public onlyOwner {
currentStateRoot = newStateRoot;
}

/**
* @notice Set Sequencer
* @param newLocalExitRoot New exit root ¡
*/
function setExitRoot(bytes32 newLocalExitRoot) public {
function setExitRoot(bytes32 newLocalExitRoot) public onlyOwner {
currentLocalExitRoot = newLocalExitRoot;
}

Expand All @@ -132,8 +156,35 @@ contract ProofOfEfficiencyMock is ProofOfEfficiency {
address sequencer,
string memory sequencerURL,
uint32 chainID
) public {
) public onlyOwner {
sequencers[sequencer].sequencerURL = sequencerURL;
sequencers[sequencer].chainID = chainID;
}

/**
* @notice VerifyBatchMock
*/
function verifyBatchMock() public onlyOwner {
// Update state
lastVerifiedBatch++;
// Interact with bridge
bridge.updateRollupExitRoot(currentLocalExitRoot);
emit VerifyBatch(lastVerifiedBatch, msg.sender);
}

/**
* @notice Allows to set Batch
*/
function setBatch(
bytes32 batchHashData,
uint256 maticCollateral,
address sequencer,
uint32 chainID,
uint32 batchNum
) public onlyOwner {
sentBatches[batchNum].batchHashData = batchHashData;
sentBatches[batchNum].maticCollateral = maticCollateral;
sentBatches[batchNum].sequencerAddress = sequencer;
sentBatches[batchNum].chainID = chainID;
}
}
Loading

0 comments on commit 1c3516a

Please sign in to comment.