-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 715-record-transaction-consensus-history-in-…
…database
- Loading branch information
Showing
27 changed files
with
1,556 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; | ||
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; | ||
|
||
library RandomnessUtils { | ||
using ECDSA for bytes32; | ||
|
||
/** | ||
* @dev Updates a random seed by verifying a VRF proof signature and generating a new seed. | ||
* @param vrfProof The signature proof provided by the signer | ||
* @param currentSeed The current seed value to be used for verification | ||
* @param signer The address that should have signed the message | ||
* @return newSeed The newly generated random seed | ||
*/ | ||
function updateRandomSeed( | ||
bytes memory vrfProof, | ||
uint256 currentSeed, | ||
address signer | ||
) internal pure returns (uint256) { | ||
// Convert seed to bytes32 and create ethereum signed message hash | ||
bytes32 seed = bytes32(currentSeed); | ||
bytes32 hash = MessageHashUtils.toEthSignedMessageHash(seed); | ||
|
||
// Verify the signature | ||
address recoveredSigner = hash.recover(vrfProof); | ||
// Comment next check if you want to skip signature verification | ||
require( | ||
recoveredSigner == signer, | ||
"RandomnessUtils: Invalid signature" | ||
); | ||
|
||
// Generate and return new seed | ||
return uint256(keccak256(vrfProof)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; | ||
|
||
contract Appeals is | ||
Initializable, | ||
Ownable2StepUpgradeable, | ||
ReentrancyGuardUpgradeable, | ||
AccessControlUpgradeable | ||
{ | ||
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); | ||
bytes32 public constant VALIDATOR_ROLE = keccak256("VALIDATOR_ROLE"); | ||
|
||
receive() external payable {} | ||
|
||
function initialize() public initializer { | ||
__Ownable2Step_init(); | ||
__ReentrancyGuard_init(); | ||
__AccessControl_init(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; | ||
import "./interfaces/ITransactions.sol"; | ||
import "./interfaces/IQueues.sol"; | ||
import "./interfaces/IConsensusMain.sol"; | ||
import "./interfaces/IMessages.sol"; | ||
|
||
contract ConsensusData is | ||
Initializable, | ||
Ownable2StepUpgradeable, | ||
ReentrancyGuardUpgradeable, | ||
AccessControlUpgradeable | ||
{ | ||
ITransactions public transactions; | ||
IQueues public queues; | ||
IConsensusMain public consensusMain; | ||
struct TransactionData { | ||
// Basic transaction info | ||
address sender; | ||
address recipient; | ||
uint256 numOfInitialValidators; | ||
uint256 txSlot; | ||
uint256 timestamp; | ||
uint256 lastVoteTimestamp; | ||
bytes32 randomSeed; | ||
ITransactions.ResultType result; | ||
bytes txData; | ||
bytes txReceipt; | ||
IMessages.SubmittedMessage[] messages; | ||
// // Validator info | ||
address[] validators; | ||
bytes32[] validatorVotesHash; | ||
ITransactions.VoteType[] validatorVotes; | ||
// Queue info | ||
IQueues.QueueType queueType; | ||
uint256 queuePosition; | ||
// // Status info | ||
address activator; | ||
address leader; | ||
ITransactions.TransactionStatus status; | ||
uint256 committedVotesCount; | ||
uint256 revealedVotesCount; | ||
} | ||
|
||
receive() external payable {} | ||
|
||
function initialize( | ||
address _consensusMain, | ||
address _transactions, | ||
address _queues | ||
) public initializer { | ||
__Ownable2Step_init(); | ||
__ReentrancyGuard_init(); | ||
__AccessControl_init(); | ||
|
||
transactions = ITransactions(_transactions); | ||
queues = IQueues(_queues); | ||
consensusMain = IConsensusMain(_consensusMain); | ||
} | ||
|
||
function getTransactionData( | ||
bytes32 _tx_id | ||
) external view returns (TransactionData memory) { | ||
ITransactions.Transaction memory transaction = transactions | ||
.getTransaction(_tx_id); | ||
|
||
address activator = consensusMain.txActivator(_tx_id); | ||
uint validatorsCount = consensusMain.validatorsCountForTx(_tx_id); | ||
address[] memory validators = consensusMain.getValidatorsForTx(_tx_id); | ||
uint leaderIndex = consensusMain.txLeaderIndex(_tx_id); | ||
address leader = validatorsCount > 0 | ||
? validators[leaderIndex] | ||
: address(0); | ||
|
||
TransactionData memory txData = TransactionData({ | ||
// Basic transaction info | ||
sender: transaction.sender, | ||
recipient: transaction.recipient, | ||
numOfInitialValidators: transaction.numOfInitialValidators, | ||
txSlot: transaction.txSlot, | ||
timestamp: transaction.timestamp, | ||
lastVoteTimestamp: transaction.lastVoteTimestamp, | ||
randomSeed: transaction.randomSeed, | ||
result: transaction.result, | ||
txData: transaction.txData, | ||
txReceipt: transaction.txReceipt, | ||
messages: transaction.messages, | ||
// // Validator info | ||
validators: transaction.validators, | ||
validatorVotesHash: transaction.validatorVotesHash, | ||
validatorVotes: transaction.validatorVotes, | ||
// Queue info | ||
queueType: queues.getTransactionQueueType(_tx_id), | ||
queuePosition: queues.getTransactionQueuePosition(_tx_id), | ||
// // Status info | ||
activator: activator, | ||
leader: leader, | ||
status: consensusMain.txStatus(_tx_id), | ||
committedVotesCount: consensusMain.voteCommittedCountForTx(_tx_id), | ||
revealedVotesCount: consensusMain.voteRevealedCountForTx(_tx_id) | ||
}); | ||
|
||
return txData; | ||
} | ||
|
||
// Setter functions | ||
function setTransactions(address _transactions) external onlyOwner { | ||
transactions = ITransactions(_transactions); | ||
} | ||
|
||
function setQueues(address _queues) external onlyOwner { | ||
queues = IQueues(_queues); | ||
} | ||
|
||
function setConsensusMain(address _consensusMain) external onlyOwner { | ||
consensusMain = IConsensusMain(_consensusMain); | ||
} | ||
} |
Oops, something went wrong.