Created
August 16, 2024 03:11
-
-
Save yacademy/1883784c1771b3f47271413ede7d8b52 to your computer and use it in GitHub Desktop.
Blockchain timestamp anomaly testing script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
# Set these parameters specific to the chain you are testing | |
oldest_block = 19522700 | |
newest_block = 19523700 | |
rpc_url = "https://eth.llamarpc.com" | |
max_seconds_diff_trigger = 12 | |
first_timestamp = int(subprocess.run(["cast", "block", "-f", "timestamp", str(oldest_block), "--rpc-url", rpc_url], capture_output=True, text = True).stdout) | |
for next_block in range(oldest_block + 1, newest_block): | |
next_timestamp = int(subprocess.run(["cast", "block", "-f", "timestamp", str(next_block), "--rpc-url", rpc_url], capture_output=True, text = True).stdout) | |
if (timestamp_diff := next_timestamp - first_timestamp) > max_seconds_diff_trigger: # normally observe 12 seconds block spacing on mainnet Ethereum | |
print("ANOMALY DETECTED! Block ", str(oldest_block), " to block ", str(next_block), " has diff of ", str(timestamp_diff)) | |
# step forward in time before next loop | |
oldest_block = next_block | |
first_timestamp = next_timestamp | |
if oldest_block % 100 == 0: | |
print(oldest_block) # for debugging |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment