Last active
June 15, 2022 23:19
-
-
Save michaelsproul/0fc363a5a5e031b3fa9451352a36e30f to your computer and use it in GitHub Desktop.
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
# Attempt to slash validators from https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4036000 | |
import requests | |
def get_attestations(slot): | |
res = requests.get("https://beaconcha.in/api/v1/block/{}/attestations".format(slot)) | |
res.raise_for_status() | |
return res.json() | |
def get_validator_att(atts, validator): | |
return [att for att in atts["data"] if validator in att["validators"]][0] | |
def make_indexed(att): | |
attesting_indices = sorted(att["validators"]) | |
data = { | |
"slot": att["slot"], | |
"index": att["committeeindex"], | |
"beacon_block_root": att["block_root"], | |
"source": { "root": att["source_root"], "epoch": att["source_epoch"] }, | |
"target": { "root": att["target_root"], "epoch": att["target_epoch"] }, | |
} | |
signature = att["signature"] | |
indexed_att = { | |
"attesting_indices": attesting_indices, | |
"data": data, | |
"signature": signature | |
} | |
return indexed_att | |
def make_slashing(indexed1, indexed2): | |
return { | |
"attestation_1": indexed1, | |
"attestation_2": indexed2 | |
} | |
def post_to_bn(slashing): | |
res = requests.post("http://localhost:5052/eth/v1/beacon/pool/attester_slashings", json=slashing) | |
print(res.json()) | |
res.raise_for_status() | |
def main(): | |
validator = 3644 | |
slot1 = 1267818 | |
slot2 = 1267822 | |
atts1 = get_attestations(slot1) | |
atts2 = get_attestations(slot2) | |
att1 = get_validator_att(atts1, validator) | |
att2 = get_validator_att(atts2, validator) | |
indexed1 = make_indexed(att1) | |
indexed2 = make_indexed(att2) | |
slashing = make_slashing(indexed1, indexed2) | |
post_to_bn(slashing) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment