Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
Implement multi proposal accusation (#16)
Browse files Browse the repository at this point in the history
* wip

* dapp install ds-auth

* dapp install ds-math

* dapp install ds-stop

* dapp install ds-test

* dapp install ds-token

* Updated for Solidity 0.6.x

* Removed misplaced contract

* Snapshot facet with tests

* Develop (#2)

* dapp install ds-auth

* dapp install ds-math

* dapp install ds-stop

* dapp install ds-test

* dapp install ds-token

* Updated for Solidity 0.6.x

* Updated to Solidity 0.7.4

* Updated to Solidity 0.7.x and added AccessControl

* Updates for events

* Rebuilding Staking contract.

* Added staking to validators diamond along with shared storage.

* Changed type in assert to appease linter

* Removed commented code

* Removed commented code

* Add ownerOrOperator modifier for access control

* Added currentEpoch methods to staking for compatibility.

* Removed commented code. Added participants modifier for snapshots.

* Recompiled and generated bindings.

* Restricted facet for diamond maintenance

* wip

* Added admin functions to interface

* Added missing majorFine()/minorFine()

* wip

* Adding migration contracts/facets

* Moved event definitions

* ETHDKG migrator + test

* Fixed loop index for members

* Switch from a manual call() to a cast

* Added snapshot failure test for bad signature

* Added test for migration of snapshot

* Added staking test case

* Create constant for minimum stake. Added testing for immediately adding/removing validator

* Turned off test tracing and generated bindings

* Put the owner only requirement back

* Regenerated bindings

* Renamed overloaded function deposit() to depositFor()

* Minor style updates to match recommendations

* Feature complete ETHDKG replacement with diamond pattern

* Complete unit tests

* Put missing access controls back

* Finished splitting ETHDKG

* Added restart of ETHDKG if final completion detects issue

* Made validator queueing consistently require staking. Restored snapshot rewards.

* Phase length admin exposed

* Consolidated EthDKG constants into Library. Updated abicoder to v2.

* Removed commented code.

* Renamed utility token

* Brought over TODOs from Chris

* latest

* wip

* mod tidy

* wip

* wip

* wip

* go mod tidy

* Regenerated bindings

* Add initial README with installation instructions

* wip

* wip

* wip

* WIP implementation of parser for base types and RClaim

programmed with @vtleonardo

* Change the file structure of the parsers

* Change the file structure of the parsers

* Optimized bytes extraction with assembly

- The first implementation of `BaseParserLibrary.extract_bytes` used ~14035 gas, while this assembly implementation only uses ~7828
- Added more utility functions to BaseParserLibrary
- Added test to extract_rclaims
- Fixed tests to have `actual` and `expected` vars as the correct argument to asserts
- Added docs

* Add the base for the other parser contracts

* Clean up the tests

* Remove Parsers that will be added in a later PR

* Push missing files

* Clean makefile

* Implemented extract_bytes32

- Added implementation of extract_bytes32 (~439 gas)
- Changed RClaimsParserLibrary.Rclaims.prevBlock from bytes to bytes32
- Added require() guards
- Added tests to reverse, extract_bytes and extract_bytes32

* Refactor code to use name convection

* Add RCerts partial implementation

* Refactor and clean up the code

* WIP implementation of parser for base types and RClaim

programmed with @vtleonardo

* Change the file structure of the parsers

* Optimized bytes extraction with assembly

- The first implementation of `BaseParserLibrary.extract_bytes` used ~14035 gas, while this assembly implementation only uses ~7828
- Added more utility functions to BaseParserLibrary
- Added test to extract_rclaims
- Fixed tests to have `actual` and `expected` vars as the correct argument to asserts
- Added docs

Change the file structure of the parsers

Add the base for the other parser contracts

* Clean up the tests

* Remove Parsers that will be added in a later PR

* Push missing files

* Clean makefile

* Implemented extract_bytes32

- Added implementation of extract_bytes32 (~439 gas)
- Changed RClaimsParserLibrary.Rclaims.prevBlock from bytes to bytes32
- Added require() guards
- Added tests to reverse, extract_bytes and extract_bytes32

* Refactor code to use name convection

* Add RCerts partial implementation

* Refactor and clean up the code

* Refactor the tests

* Build a new dapp.sol.json to exclude unit test contracts

* Fix Typo with RClaims

* Fix more typos

* Docs

Added docs to BaseParserLibrary functions

* Add PClaims and BClaims parsers

* Restore BaseParser file that got wrong due to merge conflicts

* Add initial logic for the multi proposal accusation

* Fix conflicts with bridge and dapp.sol.json

* Fix conflicts with bridge and dapp.sol.json

* Add the logic to retrieve the madnet signatures

* Add new bindings after merge conflict

* Make all test pass

* FInished implementation of AccusationMuleipleProposal

* Merge latest main

* Clean up the code

* Update src/facets/AccusationMultipleProposalFacet.sol

Co-authored-by: anthony <[email protected]>
Co-authored-by: anthony <[email protected]>
Co-authored-by: Ricardo Pinto <[email protected]>
Co-authored-by: Leonardo Viana <[email protected]>
  • Loading branch information
5 people authored Sep 3, 2021
1 parent f1f9795 commit 0e08534
Show file tree
Hide file tree
Showing 11 changed files with 45,860 additions and 41,468 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.vscode/*

# Local History for Visual Studio Code
.history/
.history/

# dapp debug folders
./hevm/*
86,802 changes: 45,376 additions & 41,426 deletions bindings/bridge.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion out/dapp.sol.json

Large diffs are not rendered by default.

75 changes: 60 additions & 15 deletions src/facets/AccusationLibrary.sol
Original file line number Diff line number Diff line change
@@ -1,40 +1,76 @@
// SPDX-License-Identifier: MIT-open-group
pragma solidity >= 0.5.15;

import "../parsers/PClaimsParserLibrary.sol";
import "./ParticipantsLibrary.sol";
import "./SnapshotsLibrary.sol";

library AccusationLibrary {

//
// Storage code to support diamond pattern
//
/// @dev Storage code to support diamond pattern
bytes32 constant STORAGE_LOCATION = keccak256("accusation.storage");

struct AccusationStorage {
// Not sure exactly what storage is needed yet
mapping(address => int) accusations;
mapping(address => uint256) accusations;
}

/// @dev function to support the diamond pattern
function accusationStorage() internal pure returns (AccusationStorage storage s) {
bytes32 position = STORAGE_LOCATION;
assembly { // solium-disable-line
s.slot := position
}
}

//
//
//

/// @notice This function validates an accusation of multiple proposals.
/// @param _signature0 The signature of pclaims0
/// @param _pClaims0 The PClaims of the accusation
/// @param _signature1 The signature of pclaims1
/// @param _pClaims1 The PClaims of the accusation
/// @return the address of the signer
function AccuseMultipleProposal(
bytes calldata _signatureGroup0,
bytes calldata _signature0,
bytes calldata _pClaims0,
bytes calldata _signatureGroup1,
bytes calldata _signature1,
bytes calldata _pClaims1
) internal {

) internal view returns(address) {
// ecrecover sig0/1 and ensure both are valid and accounts are equal
address signerAccount0 = recoverMadNetSigner(_signature0, _pClaims0);
address signerAccount1 = recoverMadNetSigner(_signature1, _pClaims1);

require(signerAccount0 == signerAccount1, "Invalid multiple proposal accusation, the signers of the proposals are different!");

// ensure the hashes of blob0/1 are different
require(keccak256(_pClaims0) != keccak256(_pClaims1), "Invalid multiple proposal accusation, the PClaims are equal!");

PClaimsParserLibrary.PClaims memory pClaims0 = PClaimsParserLibrary.extractPClaims(_pClaims0, PClaimsParserLibrary.CAPNPROTO_HEADER_SIZE);
PClaimsParserLibrary.PClaims memory pClaims1 = PClaimsParserLibrary.extractPClaims(_pClaims1, PClaimsParserLibrary.CAPNPROTO_HEADER_SIZE);

// ensure the height of blob0/1 are equal using RCert sub object of PClaims
require(pClaims0.rCert.rClaims.height == pClaims1.rCert.rClaims.height, "Invalid multiple proposal accusation, the block heights between the proposals are different!");

// ensure the round of blob0/1 are equal using RCert sub object of PClaims
require(pClaims0.rCert.rClaims.round == pClaims1.rCert.rClaims.round, "Invalid multiple proposal accusation, the round between the proposals are different!");

// ensure the chainid of blob0/1 are equal using RCert sub object of PClaims
require(pClaims0.rCert.rClaims.chainId == pClaims1.rCert.rClaims.chainId, "Invalid multiple proposal accusation, the chainId between the proposals are different!");

// ensure the chainid of blob0 is correct for this chain using RCert sub object of PClaims
uint32 chainId = ParticipantsLibrary.participantsStorage().chainId;
require(pClaims0.rCert.rClaims.chainId == chainId, "Invalid multiple proposal accusation, the chainId is invalid for this chain!");

// ensure both accounts are applicable to a currently locked validator - Note<may be done in different layer?>
require(ParticipantsLibrary.isValidator(signerAccount0), "Invalid multiple proposal accusation, the signer of these proposals is not a valid validator!");

return signerAccount0;
}

//
//
//
/// @notice Recovers the signer of a message
/// @param signature The ECDSA signature
/// @param prefix The prefix of the message
/// @param message The message
/// @return the address of the signer
function recoverSigner(bytes memory signature, bytes memory prefix, bytes memory message) internal pure returns (address) {

require(signature.length==65, "Signature should be 65 bytes");
Expand All @@ -58,4 +94,13 @@ library AccusationLibrary {
return ecrecover(hashedMessage, v, r, s);
}


/// @notice Recovers the signer of a message in MadNet
/// @param signature The ECDSA signature
/// @param message The message
/// @return the address of the signer
function recoverMadNetSigner(bytes memory signature, bytes memory message) internal pure returns (address) {
return recoverSigner(signature, "Proposal" , message);
}

}
Loading

0 comments on commit 0e08534

Please sign in to comment.