-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(builtins): ecdsa_recover_pk with recid out of range (#1134)
This caused the most recent mainnet stall
- Loading branch information
Anton Trunov
committed
Aug 4, 2022
1 parent
1b6ae41
commit c7719c9
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
let ecrecover : ByStr -> ByStr64 -> Uint32 -> ByStr20 = | ||
fun (msg : ByStr) => | ||
fun (sig : ByStr64) => | ||
fun (recid : Uint32) => | ||
let pk = builtin ecdsa_recover_pk msg sig recid in | ||
let pos = Uint32 1 in | ||
let len = Uint32 64 in | ||
let pk_bs = builtin to_bystr pk in | ||
let pk_ = builtin substr pk_bs pos len in | ||
let pkHash = builtin keccak256hash pk_ in | ||
let pkHash_bs = builtin to_bystr pkHash in | ||
let pos = Uint32 12 in | ||
let len = Uint32 20 in | ||
let addr_bs = builtin substr pkHash_bs pos len in | ||
let addr_opt = builtin to_bystr20 addr_bs in | ||
match addr_opt with | ||
| Some addr => | ||
addr | ||
| None => | ||
let zero = Uint32 0 in | ||
let ignore = builtin div zero zero in | ||
0x0000000000000000000000000000000000000000 | ||
end | ||
in | ||
|
||
let header_hash = | ||
fun (header : ByStr) => | ||
let h1 = builtin sha256hash header in | ||
let h2 = builtin sha256hash h1 in | ||
builtin to_bystr h2 | ||
in | ||
|
||
let sig = 0x7d588d79ac9f0931c69150de6bfe5289f0147893781bffbcc32b5e07bd687d1048dda039ffc1e87de2e98610dc876e97411d604948473904b12b64bed8880bcc in | ||
let msg = 0x000000009b91561700000000f48a4057bef268cc3fdb034e69dc2e942907e08ac4a420d1b196b8c28ebf5bf2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a8be0a1605a63a31704aec4eb4f1023f1ecc2934bd86f119ab77526f9477af9a57e1a5f508e0000410782720ab189fffd84057b226c6561646572223a332c227672665f76616c7565223a22424f4f336f58796b32524970655651593338547133714a423832737a4a68366e4f6f724a55702f4a4d582b474c707a347a497347394c4a6c34784a6f34657448674f56357169364d484b6674714f69724f755a495a69593d222c227672665f70726f6f66223a22635953525746506f69394748414247526255646836612b35506f4f317776354a557a53417457786845637071757430536a595873344c7453353574534a74334174493059616d4c67524a797a524f68564756626d34673d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a33363433322c226e65775f636861696e5f636f6e666967223a7b2276657273696f6e223a312c2276696577223a342c226e223a382c2263223a322c22626c6f636b5f6d73675f64656c6179223a31303030303030303030302c22686173685f6d73675f64656c6179223a31303030303030303030302c22706565725f68616e647368616b655f74696d656f7574223a31303030303030303030302c227065657273223a5b7b22696e646578223a312c226964223a2231323035303238313732393138353430623262353132656165313837326132613265336132386439383963363064393564616238383239616461376437646437303664363538227d2c7b22696e646578223a342c226964223a2231323035303236373939333061343261616633633639373938636138613366313265313334633031393430353831386437383364313137343865303339646538353135393838227d2c7b22696e646578223a332c226964223a2231323035303234383261636236353634623139623930363533663665396338303632393265386161383366373865376139333832613234613665666534316330633036663339227d2c7b22696e646578223a352c226964223a2231323035303234363864643138393965643264316363326238323938383261313635613065636236613734356166306337326562323938326436366234333131623465663733227d2c7b22696e646578223a382c226964223a2231323035303339333432313434356239343231626434636339306437626338386339333031353538303437613736623230633539653763353131656537643232393938326231227d2c7b22696e646578223a322c226964223a2231323035303338623861663632313065636664636263616232323535326566386438636634316336663836663963663961623533643836353734316366646238333366303662227d2c7b22696e646578223a372c226964223a2231323035303331653037373966356335636362323631323335326665346132303066393964336537373538653730626135336636303763353966663232613330663637386666227d2c7b22696e646578223a362c226964223a2231323035303265623162616162363032633538393932383235363163646161613761616262636464306363666362633365373937393361633234616366393037373866333561227d5d2c22706f735f7461626c65223a5b322c382c352c352c382c372c312c342c352c362c352c342c372c372c332c332c342c362c312c322c342c382c352c342c372c342c362c362c322c322c312c312c382c382c362c362c362c372c382c372c342c382c352c312c332c332c382c352c332c362c332c362c372c352c362c322c332c312c322c362c352c322c312c342c322c312c382c342c382c332c382c372c372c352c312c372c342c342c312c352c322c352c362c312c322c382c332c332c312c332c312c342c312c372c382c362c382c322c352c312c342c352c332c322c322c322c382c332c332c332c362c372c342c372c342c322c372c352c362c375d2c226d61785f626c6f636b5f6368616e67655f76696577223a36303030307d7df8fc7a1f6a856313c591a3a747f4eca7218a820b in | ||
|
||
let addr_gold = 0xa42a4e85034d5bebc225743da400cc4c0e43727a in | ||
let msg_bs = builtin to_bystr msg in | ||
let msg_hashed = header_hash msg_bs in | ||
(* incorrect recid (must be 0,1,2 or 3) *) | ||
let recid = Uint32 28 in | ||
|
||
let addr_computed = ecrecover msg_hashed sig recid in | ||
builtin eq addr_computed addr_gold |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"gas_remaining": "4001696", | ||
"errors": [ | ||
{ | ||
"error_message": "Sign.read_recoverable_exn: recid must be 0, 1, 2 or 3", | ||
"start_location": { "file": "", "line": 0, "column": 0 }, | ||
"end_location": { "file": "", "line": 0, "column": 0 } | ||
} | ||
], | ||
"warnings": [] | ||
} |