nano-node icon indicating copy to clipboard operation
nano-node copied to clipboard

Validation needed on custom test network difficulty parameters

Open zhyatt opened this issue 2 years ago • 0 comments

Summary

When using the custom test network parameters introduced in https://github.com/nanocurrency/nano-node/pull/3037, the difficulty values NANO_TEST_EPOCH_1, NANO_TEST_EPOCH_2, NANO_TEST_EPOCH_2_RECV do not appear to have proper validation done on them and incorrect values either crash the node (values too long) or cause unexpected results (values too short).

Node version

V23.0

Build details

Docker image

OS and version

macOS running Docker daemon

Steps to reproduce the behavior

Define test network parameters NANO_TEST_EPOCH_1, NANO_TEST_EPOCH_2, NANO_TEST_EPOCH_2_RECV on a node targeting --network test with the following parameters:

Case 1

  • Set any value is 0xfffffc00000000000 (this is too long at 0x + 17 characters)
  • After starting the node crashes with error terminate called after throwing an instance of 'boost::wrapexcept<boost::bad_lexical_cast>'

Case 2

  • Set one value is 0xfffffc000000000 (this is too short at 0x + 15 characters)
  • After starting the node will ignore this value and replace it with another valid one

Case 3

  • Set all values as 0xfffffc000000000 (this is too short at 0x + 15 characters)
  • After starting the node will no longer use a valid value, but instead use one with a leading 0 which effectively sets difficulty thresholds to nothing

Expected behavior

When attempting to use incorrectly formatted values (0x followed by 16 hex characters) the node should refuse to startup, logging an appropriate error.

Actual behavior

Node either crashes or gives unexpected values. See Steps to reproduce above

Possible solution

No response

Supporting files

No response

zhyatt avatar May 11 '22 00:05 zhyatt