Skip to content

Conversation

Sjors
Copy link
Member

@Sjors Sjors commented Jan 23, 2025

Adjust the timewarp test to better illustrate the griefing attack discussed here: https://delvingbitcoin.org/t/timewarp-attack-600-second-grace-period/1326/19

Changing MAX_TIMEWARP to something > MAX_FUTURE_BLOCK_TIME in consensus.h and mining_basic.py will cause the updated test to fail. I'm not proposing such a change here of course. The new test should be useful guidance for pool software developers, for why they really should use curtime, or least not ignore mintime.

Additionally, if the proposal is changed to make MAX_TIMEWARP > MAX_FUTURE_BLOCK_TIME then this test will break, which could be used to demonstrate there's no such griefing attack anymore.

Originally part of #31600.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 23, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31725.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK Prabhat1308

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@Sjors
Copy link
Member Author

Sjors commented Feb 1, 2025

#31600 landed, ready for review

Copy link
Contributor

@Prabhat1308 Prabhat1308 left a comment

Choose a reason for hiding this comment

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

ACK 6065b78

self.generate(self.wallet, 1, sync_fun=self.no_op)

self.log.info("Create block two hours in the future")
self.nodes[0].setmocktime(t + MAX_FUTURE_BLOCK_TIME)
self.log.info("Create block MAX_TIMEWARP < t < MAX_FUTURE_BLOCK_TIME in the future")
Copy link
Contributor

Choose a reason for hiding this comment

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

The log mentions t to be strictly less than MAX_FUTURE_BLOCK_TIME. But in line 165 , the assert statement is for future<=MAX_FUTURE_BLOCK_TIME.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed the log statement to <=

# timestamp to MTP + 1, but doesn't take the new timewarp rule into
# account (and ignores mintime).
mtp = node.getblock(node.getbestblockhash())["mediantime"] + 1
bad_block.nTime = mtp + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

on previous line 199 , mtp is set to node.getblock(node.getbestblockhash())["mediantime"] + 1 . from the rpc commands , shouldnt mtp be just node.getblock(node.getbestblockhash())["mediantime"] ? and then nTime is correct with mtp + 1. Have checked it locally and the test passes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, fixed.

tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
assert_greater_than_or_equal(tmpl['curtime'], t + MAX_FUTURE_BLOCK_TIME - MAX_TIMEWARP)
assert_equal(tmpl['curtime'], future - MAX_TIMEWARP)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is introducing a more stricter equality. Is it because we now have the liberty to choose future as we wish whereas previously it was t + MAX_FUTURE_BLOCK_TIME which not necessarily be equal to template's curtime ?

Copy link
Member Author

Choose a reason for hiding this comment

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

more stricter equality.

Stricter than what? I don't fully remember what the original test was trying to do here. But we know the exact value to expect.

curtime is equal to nTime of the template, which is controlled by UpdateTime() in node/miner.cpp. It starts with the actual current time, but then increases if needed to account for the MTP+1 rule and timewarp - and no more than that.

@Sjors Sjors force-pushed the 2025/01/timewarp-grief branch from 6065b78 to d016d4f Compare February 12, 2025 09:19
@DrahtBot
Copy link
Contributor

There hasn't been much activity lately. What is the status here?

Finding reviewers may take time. However, if the patch is no longer relevant, please close this pull request. If the author lost interest or time to work on this, please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

1 similar comment
@DrahtBot
Copy link
Contributor

There hasn't been much activity lately. What is the status here?

Finding reviewers may take time. However, if the patch is no longer relevant, please close this pull request. If the author lost interest or time to work on this, please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

On testnet4 with the timewarp mitigation active, when pool software
ignores the curtime and mintime fields provided by the getblocktemplate
RPC or by createNewBlock() in the Mining interface, they are vulnerable
to a griefing attack.

The test is expanded to illustrate this.
@Sjors Sjors force-pushed the 2025/01/timewarp-grief branch from d016d4f to 37d2246 Compare August 25, 2025 12:13
@Sjors
Copy link
Member Author

Sjors commented Aug 25, 2025

@Prabhat1308 can you update your review to the latest version?

I've rebased it just in case.

@Prabhat1308
Copy link
Contributor

re-ACK 37d2246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants