Conversation
kapke
left a comment
There was a problem hiding this comment.
Mostly minor comments. Overall looks good!
| private def newConfig[C <: AnyRef](c: C): FullConsensusConfig[C] = | ||
| FullConsensusConfig(consensusConfig, c) | ||
|
|
||
| //TODO refactor configs to avoid possibility of running mocked or restricted-ethash consensus on real network like ETC or Mordor |
| blockchainConfig = blockchainConfig, | ||
| consensusConfig = config.generic, | ||
| blockPreparator = blockPreparator, | ||
| difficultyCalculator, |
There was a problem hiding this comment.
minor - use named parameters all the way down?
| blockchainConfig = blockchainConfig, | ||
| consensusConfig = config.generic, | ||
| blockPreparator = blockPreparator, | ||
| difficultyCalculator |
| pubKeyBytes <- sig.publicKey(headerHash) | ||
| } yield ByteString.fromArrayUnsafe(pubKeyBytes) | ||
|
|
||
| maybePubKey.fold(false)(pubKey => allowedMiners.contains(pubKey)) |
| def validateSignature(blockHeader: BlockHeader, allowedMiners: Set[ByteString]): Boolean = { | ||
| val signature = blockHeader.extraData.takeRight(ECDSASignature.EncodedLength) | ||
| val blockHeaderWithoutSig = | ||
| blockHeader.copy(extraData = blockHeader.extraData.dropRight(ECDSASignature.EncodedLength)) |
There was a problem hiding this comment.
should these .copy calls in this file be methods on BlockHeader?
| with ObjectGenerators | ||
| with SecureRandomBuilder { | ||
| "RestrictedEthashSigner" should "sign and validate correct header" in { | ||
| forAll(blockHeaderGen, genKey(secureRandom)) { (header, key) => |
There was a problem hiding this comment.
should similar tests be written against RestrictedEthashHeaderValidator?
There was a problem hiding this comment.
tbh i am not sure that is possible (or desirable) as RestrictedEthashBlockHeaderValidator inherits from EthashBlockHeaderValidator which mean method validate validates proof of work therefore to property test it one should mine valid blocks which would take too much time.
Thats why I had split that way:
- property test for signing and validating to test various different inputs
RestrictedEthashBlockHeaderValidatorSpecwhich tests differentif-elseparts fromRestrictedEthashBlockHeaderValidatorplus the case which test against someone who would try to re-sign header after pow is mined
There was a problem hiding this comment.
On the BlockHeaderValidatorSpec we used:
class BlockValidatorWithPowMocked(blockchainConfig: BlockchainConfig)
extends BlockHeaderValidatorSkeleton(blockchainConfig) {
override protected def difficulty: DifficultyCalculator = difficultyCalculator
override def validateEvenMore(
blockHeader: BlockHeader,
parentHeader: BlockHeader
): Either[BlockHeaderError, BlockHeaderValid] = Right(BlockHeaderValid)
}
Something like that might be useful for what you are saying
| "RestrictedEthashSigner" should "sign and validate correct header" in { | ||
| forAll(blockHeaderGen, genKey(secureRandom)) { (header, key) => | ||
| val signedHeader = RestrictedEthashSigner.signHeader(header, key) | ||
| val keyAsBytes = ByteString.fromArrayUnsafe( |
There was a problem hiding this comment.
io.iohk.ethereum.crypto#keyPairToByteArrays and friends instead?
|
|
||
| it should "fail to validate header with invalid key" in new TestSetup { | ||
| val allowedKey = crypto.generateKeyPair(secureRandom) | ||
| val keyBytes = ByteString.fromArrayUnsafe( |
| it should "fail to validate header signed with wrong key" in { | ||
| forAll(blockHeaderGen, genKey(secureRandom), genKey(secureRandom)) { (header, correctKey, wrongKey) => | ||
| val signedHeader = RestrictedEthashSigner.signHeader(header, correctKey) | ||
| val wrongKeyAsBytes = ByteString.fromArrayUnsafe( |
|
|
||
| it should "fail to validate header re-signed by valid signer" in new TestSetup { | ||
| val allowedKey = crypto.generateKeyPair(secureRandom) | ||
| val keyBytes = ByteString.fromArrayUnsafe( |
Simplify RestrictedEthash validator Few re-namings Use crypto.utils instead of manual key conversions
ntallar
left a comment
There was a problem hiding this comment.
Only some minor comments, worked well while testing it! Will take a look at the tests next week
ntallar
left a comment
There was a problem hiding this comment.
Only a minor comment, apart from which LGTM!
| with ObjectGenerators | ||
| with SecureRandomBuilder { | ||
| "RestrictedEthashSigner" should "sign and validate correct header" in { | ||
| forAll(blockHeaderGen, genKey(secureRandom)) { (header, key) => |
There was a problem hiding this comment.
On the BlockHeaderValidatorSpec we used:
class BlockValidatorWithPowMocked(blockchainConfig: BlockchainConfig)
extends BlockHeaderValidatorSkeleton(blockchainConfig) {
override protected def difficulty: DifficultyCalculator = difficultyCalculator
override def validateEvenMore(
blockHeader: BlockHeader,
parentHeader: BlockHeader
): Either[BlockHeaderError, BlockHeaderValid] = Right(BlockHeaderValid)
}
Something like that might be useful for what you are saying
Remove allowed keys option from etc-chain.conf Add additional validation error Add comments to special headers in test
71dbcd5 to
78209f3
Compare
ntallar
left a comment
There was a problem hiding this comment.
LGTM!
.\\ //.
. \ \ / /.
.\ ,\ /` /,.-
-. \ /'/ / .
` - `-' \ -
'. /.\`
- .-
:`//.'
.`.'
.' BP
Description
Non-standard ethereum PoW consensus protocol, which allows restricting list of possible miners.
Main differences from basic PoW consensus protocol:
Each miner, signs header data before mining i.e prepared header without mixHash and Nonce, and appends this
signature to blockheader.extraData field. Only such prepared header is mined upon.
Each validator, checks (in addition to standard blockheader validations):