Skip to content

Commit

Permalink
Avoid introducing a virtual into CChainParams
Browse files Browse the repository at this point in the history
Treat fSkipProofOfWorkCheck the same as other parameters.
  • Loading branch information
laanwj committed Sep 29, 2014
1 parent 5e2e7fc commit 4705902
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/chainparams.cpp
Expand Up @@ -115,6 +115,7 @@ class CMainParams : public CChainParams {
fAllowMinDifficultyBlocks = false;
fRequireStandard = true;
fMineBlocksOnDemand = false;
fSkipProofOfWorkCheck = false;
}
};
static CMainParams mainParams;
Expand Down Expand Up @@ -231,11 +232,7 @@ class CUnitTestParams : public CMainParams, public CModifiableParams {
fDefaultCheckMemPool = true;
fAllowMinDifficultyBlocks = false;
fMineBlocksOnDemand = true;
fSkipProofOfWorkCheck = false;
}
virtual bool SkipProofOfWorkCheck() const { return fSkipProofOfWorkCheck; }
protected:
bool fSkipProofOfWorkCheck;
public:
// Published setters to allow changing values in unit test cases
virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) { nSubsidyHalvingInterval=anSubsidyHalvingInterval; }
Expand Down
3 changes: 2 additions & 1 deletion src/chainparams.h
Expand Up @@ -62,7 +62,7 @@ class CChainParams
/* Allow mining of a min-difficulty block */
bool AllowMinDifficultyBlocks() const { return fAllowMinDifficultyBlocks; }
/* Skip proof-of-work check: allow mining of any difficulty block */
virtual bool SkipProofOfWorkCheck() const { return false; }
bool SkipProofOfWorkCheck() const { return fSkipProofOfWorkCheck; }
/* Make standard checks */
bool RequireStandard() const { return fRequireStandard; }
int64_t TargetTimespan() const { return nTargetTimespan; }
Expand Down Expand Up @@ -105,6 +105,7 @@ class CChainParams
bool fAllowMinDifficultyBlocks;
bool fRequireStandard;
bool fMineBlocksOnDemand;
bool fSkipProofOfWorkCheck;
};

/** Modifiable parameters interface is used by test cases to adapt the parameters in order
Expand Down

4 comments on commit 4705902

@SergioDemianLerner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. But the reason I did write the virtual function returning false was to prevent any possibility of the flag being turned on on the MAIN network by mistake. This was requested by (I think) GMaxwell.
It was a protective measure...

@laanwj
Copy link
Member Author

@laanwj laanwj commented on 4705902 Sep 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrupting any of the other parameters will have bad consequences as well.

@SergioDemianLerner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. There are plenty of global variables an attacker could corrupt if he has access to write arbitrary bytes in process memory. So remove it if you wish...

@laanwj
Copy link
Member Author

@laanwj laanwj commented on 4705902 Sep 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Virtual pointers also provide a single place that can be overwritten to make the object point to a different class. It's a bit more difficult as you have to know what address to write, but still no rocket science...

The most extreme form of making these parameters static would be to provide the chain parameters to a template class implementing the consensus code, then compile/instantiate that for each network separately. Then at start-up, load only the code for the network that is selected.

Then again -- it may be pointless, I don't think there is any realistic protection against attackers that already have write access to your memory space.

Please sign in to comment.