Change commit.salted_hash to be hash, reorder salt in tests, still failing
This commit is contained in:
parent
3a320c26c8
commit
62a4482ff3
@ -1,6 +1,6 @@
|
|||||||
type commit = {
|
type commit = {
|
||||||
date: timestamp;
|
date: timestamp;
|
||||||
hashed: bytes;
|
salted_hash: bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
type commit_set = (address, commit) big_map
|
type commit_set = (address, commit) big_map
|
||||||
@ -23,7 +23,7 @@ type parameter =
|
|||||||
(* We use hash-commit so that a baker can't steal *)
|
(* We use hash-commit so that a baker can't steal *)
|
||||||
let commit ((p,s): unit * storage) : operation list * storage =
|
let commit ((p,s): unit * storage) : operation list * storage =
|
||||||
let salted: bytes = Bytes.concat s.hashed (Bytes.pack sender) in
|
let salted: bytes = Bytes.concat s.hashed (Bytes.pack sender) in
|
||||||
let commit: commit = {date = Current.time + 86400; hashed = salted;} in
|
let commit: commit = {date = Current.time + 86400; salted_hash = Crypto.sha256 salted;} in
|
||||||
let updated_map: commit_set = Big_map.update sender (Some commit) s.commits in
|
let updated_map: commit_set = Big_map.update sender (Some commit) s.commits in
|
||||||
let s = {hashed = s.hashed; unused = s.unused; commits = updated_map} in
|
let s = {hashed = s.hashed; unused = s.unused; commits = updated_map} in
|
||||||
(([]: operation list), s)
|
(([]: operation list), s)
|
||||||
@ -38,7 +38,7 @@ let reveal ((p,s): reveal * storage) : operation list * storage =
|
|||||||
then (failwith "It hasn't been 24 hours since your commit yet.": operation list * storage)
|
then (failwith "It hasn't been 24 hours since your commit yet.": operation list * storage)
|
||||||
else
|
else
|
||||||
let salted = Bytes.concat (Crypto.sha256 p.hashable) (Bytes.pack sender) in
|
let salted = Bytes.concat (Crypto.sha256 p.hashable) (Bytes.pack sender) in
|
||||||
if ((Crypto.sha256 salted) = commit.hashed) && s.unused
|
if ((Crypto.sha256 salted) = commit.salted_hash) && s.unused
|
||||||
then
|
then
|
||||||
let s: storage = {hashed = s.hashed; unused = false; commits = s.commits} in
|
let s: storage = {hashed = s.hashed; unused = false; commits = s.commits} in
|
||||||
((p.message ()), s)
|
((p.message ()), s)
|
||||||
|
@ -39,9 +39,9 @@ let mk_time st =
|
|||||||
| Some s -> ok s
|
| Some s -> ok s
|
||||||
| None -> simple_fail "bad timestamp notation"
|
| None -> simple_fail "bad timestamp notation"
|
||||||
let to_sec t = Tezos_utils.Time.Protocol.to_seconds t
|
let to_sec t = Tezos_utils.Time.Protocol.to_seconds t
|
||||||
let storage hashed commits =
|
let storage hashed used commits =
|
||||||
e_ez_record [("hashed", hashed);
|
e_ez_record [("hashed", hashed);
|
||||||
("unused", e_bool false);
|
("unused", e_bool used);
|
||||||
("commits", commits)]
|
("commits", commits)]
|
||||||
|
|
||||||
let (first_committer , first_contract) =
|
let (first_committer , first_contract) =
|
||||||
@ -54,26 +54,25 @@ let commit () =
|
|||||||
let%bind program,_ = get_program () in
|
let%bind program,_ = get_program () in
|
||||||
let%bind predecessor_timestamp = mk_time "2000-01-01T00:10:10Z" in
|
let%bind predecessor_timestamp = mk_time "2000-01-01T00:10:10Z" in
|
||||||
let%bind lock_time = mk_time "2000-01-02T00:10:11Z" in
|
let%bind lock_time = mk_time "2000-01-02T00:10:11Z" in
|
||||||
let test_hash = e_bytes_raw (sha_256_hash (Bytes.of_string "hello world")) in
|
let test_hash_raw = sha_256_hash (Bytes.of_string "hello world") in
|
||||||
|
let test_hash = e_bytes_raw test_hash_raw in
|
||||||
|
let%bind packed_sender = pack_payload program (e_bytes_string first_committer) in
|
||||||
let salted_hash = e_bytes_raw (sha_256_hash
|
let salted_hash = e_bytes_raw (sha_256_hash
|
||||||
(Bytes.concat
|
(Bytes.concat Bytes.empty [test_hash_raw;
|
||||||
Bytes.empty
|
packed_sender]))
|
||||||
[Bytes.of_string first_committer;
|
|
||||||
(sha_256_hash (Bytes.of_string "hello world"))]
|
|
||||||
))
|
|
||||||
in
|
in
|
||||||
let pre_commits = e_typed_big_map [] t_address (t_record_ez [("date", t_timestamp);
|
let pre_commits = e_typed_big_map [] t_address (t_record_ez [("date", t_timestamp);
|
||||||
("hashed", t_bytes)])
|
("salted_hash", t_bytes)])
|
||||||
in
|
in
|
||||||
let init_storage = storage test_hash pre_commits in
|
let init_storage = storage test_hash true pre_commits in
|
||||||
let commit =
|
let commit =
|
||||||
e_ez_record [("date", e_timestamp
|
e_ez_record [("date", e_timestamp
|
||||||
(Int64.to_int (to_sec lock_time)));
|
(Int64.to_int (to_sec lock_time)));
|
||||||
("hashed", salted_hash)]
|
("salted_hash", salted_hash)]
|
||||||
in
|
in
|
||||||
let post_commits = e_big_map [((e_address first_committer), commit)]
|
let post_commits = e_big_map [((e_address first_committer), commit)]
|
||||||
in
|
in
|
||||||
let post_storage = storage salted_hash post_commits in
|
let post_storage = storage salted_hash true post_commits in
|
||||||
let options =
|
let options =
|
||||||
Proto_alpha_utils.Memory_proto_alpha.make_options
|
Proto_alpha_utils.Memory_proto_alpha.make_options
|
||||||
~predecessor_timestamp
|
~predecessor_timestamp
|
||||||
|
Loading…
Reference in New Issue
Block a user