snarkOS icon indicating copy to clipboard operation
snarkOS copied to clipboard

[Bug] Race Condition on reading latest_epoch_challenge/latest_block_header

Open xbeastx opened this issue 2 years ago • 1 comments

🐛 Bug Report

Here is write part: https://github.com/AleoHQ/snarkOS/blob/7716d98a04884c3004c4fd76b29bf5c0fa4ae486/node/src/prover/router.rs#L172-L175

Here is read part: https://github.com/AleoHQ/snarkOS/blob/d832e4f539e042d03f60704fb6b297e1c191074e/node/src/prover/mod.rs#L164-L172

So it's possible that: 1-thread: will read self.latest_epoch_challenge (than unlock it). 2-thread: lock self.latest_epoch_challenge, replace it and lock self.latest_block_header and replace it 1-thread: lock and read self.latest_block_header (already new one)

So 1 thread will have wrong state previous latest_epoch_challenge and new latest_block_header

xbeastx avatar Dec 08 '22 21:12 xbeastx

Indeed, it seems like there can be a mismatch here.

@howardwu should these 2 values always be read and changed together or should we just extend the epoch_challenge lock to avoid this particular issue?

ljedrz avatar Dec 23 '22 09:12 ljedrz