Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replay attack test #10463

Merged
merged 39 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0d5ef35
write out sending payment with raw sig in kube network
QuiteStochastic Mar 11, 2022
12a25b5
i think i made the replay attack
QuiteStochastic Mar 16, 2022
efe1811
get rid of the redundant txn
QuiteStochastic Mar 16, 2022
37f3b9b
fix must send payment with raw sig
QuiteStochastic Mar 17, 2022
32de781
non blank memo
QuiteStochastic Mar 18, 2022
e497e8d
hopefully base58 works now, also write out the actual replay attack i…
QuiteStochastic Mar 18, 2022
368fccc
do math to make sure balances are right
QuiteStochastic Mar 19, 2022
ef1c916
get nonce
QuiteStochastic Mar 19, 2022
9982153
dont use the dontfailwith
QuiteStochastic Mar 19, 2022
e3a21ba
fix memo, explicitly give user command input a nonce
QuiteStochastic Mar 21, 2022
81581a5
use a nonce map
QuiteStochastic Mar 22, 2022
d9bbd96
add printout
QuiteStochastic Mar 22, 2022
3811d0d
remove query printout
QuiteStochastic Mar 22, 2022
0ddad11
Add Signed_command_memo.to_raw_bytes_exn etc., use for replay test
mrmr1993 Mar 23, 2022
1035efd
Fixup copy-paste error
mrmr1993 Mar 23, 2022
bcfa162
error string
QuiteStochastic Mar 23, 2022
66cadab
fix math
QuiteStochastic Mar 23, 2022
91bbc86
print out
QuiteStochastic Mar 23, 2022
40d5eba
increase txn amount to avoid coinbase making a difference
QuiteStochastic Mar 23, 2022
c6910d6
add a bad signature section
QuiteStochastic Mar 23, 2022
50894fb
Invalid_signature
QuiteStochastic Mar 23, 2022
18d786e
remove comments
QuiteStochastic Mar 23, 2022
f744f46
lowercase
QuiteStochastic Mar 24, 2022
f6c0c37
get account data
QuiteStochastic Mar 24, 2022
4aaaed6
fix the accidental submodule change
QuiteStochastic Mar 25, 2022
7b40a45
10x all currency amounts to seriously avoid coinbase problems
QuiteStochastic Mar 25, 2022
fd9f688
try to fix the timed node stuff again
QuiteStochastic Mar 25, 2022
1e16aa8
oop
QuiteStochastic Mar 26, 2022
4851f51
Update payments_test.ml
QuiteStochastic Mar 26, 2022
6bc0f91
10x yet again
QuiteStochastic Mar 26, 2022
ed33f2d
5 coinbases
QuiteStochastic Mar 26, 2022
9984bc0
clarification
QuiteStochastic Mar 26, 2022
0061adf
try to count the number of blocks produced
QuiteStochastic Mar 28, 2022
3640ae2
change state hash
QuiteStochastic Mar 29, 2022
455df37
trying to fix things
QuiteStochastic Mar 29, 2022
fd976f5
hardcode timeouts
QuiteStochastic Mar 29, 2022
2f9f7c4
wait condition for signed command to be node specific
QuiteStochastic Mar 29, 2022
e12e60d
remove fee calculation
QuiteStochastic Mar 29, 2022
fd1751a
mitigate race condi
QuiteStochastic Mar 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/test_executive/delegation_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
(Wait_condition.signed_command_to_be_included_in_frontier
~sender_pub_key:delegation_sender_pub_key
~receiver_pub_key:delegation_receiver_pub_key ~amount ~nonce
~command_type:Send_delegation))
~command_type:Send_delegation ~node_included_in:`Any_node))
in
Malleable_error.return ()
end
2 changes: 1 addition & 1 deletion src/app/test_executive/gossip_consistency.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
wait_for dsl
(Wait_condition.signed_command_to_be_included_in_frontier
~sender_pub_key ~receiver_pub_key ~amount ~nonce
~command_type:Send_payment)
~command_type:Send_payment ~node_included_in:`Any_node)
in
[%log info]
"gossip_consistency test: payment #%d with nonce %d successfully \
Expand Down
336 changes: 307 additions & 29 deletions src/app/test_executive/payments_test.ml

Large diffs are not rendered by default.

117 changes: 102 additions & 15 deletions src/lib/integration_test_cloud_engine/kubernetes_network.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,38 @@ module Node = struct
}
|}]

module Send_payment_with_raw_sig =
[%graphql
{|
mutation (
$sender: PublicKey!,
$receiver: PublicKey!,
$amount: UInt64!,
$token: UInt64!,
$fee: UInt64!,
$nonce: UInt32!,
$memo: String!,
$validUntil: UInt32!,
$rawSignature: String!
)
{
sendPayment(
input:
{
from: $sender, to: $receiver, amount: $amount, token: $token, fee: $fee, nonce: $nonce, memo: $memo, validUntil: $validUntil
},
signature: {rawSignature: $rawSignature}
)
{
payment {
id
nonce
hash
}
}
}
|}]

module Send_delegation =
[%graphql
{|
Expand All @@ -160,11 +192,12 @@ module Node = struct
}
|}]

module Get_balance =
module Get_account_data =
[%graphql
{|
query ($public_key: PublicKey, $token: UInt64) {
account(publicKey: $public_key, token: $token) {
query ($public_key: PublicKey) {
account(publicKey: $public_key) {
nonce
balance {
total @bsDecoder(fn: "Decoders.balance")
}
Expand Down Expand Up @@ -330,18 +363,21 @@ module Node = struct
get_best_chain ?max_length ~logger t
|> Deferred.bind ~f:Malleable_error.or_hard_error

let get_balance ~logger t ~account_id =
type account_data =
{ nonce : Unsigned.uint32; total_balance : Currency.Balance.t }

let get_account_data ~logger t ~public_key =
let open Deferred.Or_error.Let_syntax in
[%log info] "Getting account balance"
~metadata:
( ("account_id", Mina_base.Account_id.to_yojson account_id)
( ("pub_key", Signature_lib.Public_key.Compressed.to_yojson public_key)
:: logger_metadata t ) ;
let pk = Mina_base.Account_id.public_key account_id in
let token = Mina_base.Account_id.token_id account_id in
(* let pk = Mina_base.Account_id.public_key account_id in *)
(* let token = Mina_base.Account_id.token_id account_id in *)
let get_balance_obj =
Graphql.Get_balance.make
~public_key:(Graphql_lib.Encoders.public_key pk)
~token:(Graphql_lib.Encoders.token token)
Graphql.Get_account_data.make
~public_key:(Graphql_lib.Encoders.public_key public_key)
(* ~token:(Graphql_lib.Encoders.token token) *)
()
in
let%bind balance_obj =
Expand All @@ -351,13 +387,19 @@ module Node = struct
match balance_obj#account with
| None ->
Deferred.Or_error.errorf
!"Account with %{sexp:Mina_base.Account_id.t} not found"
account_id
!"Account with public_key %s not found"
(Signature_lib.Public_key.Compressed.to_string public_key)
| Some acc ->
return acc#balance#total
return
{ nonce =
acc#nonce
|> Option.value_exn ~message:"the nonce from get_balance is None"
|> Unsigned.UInt32.of_string
; total_balance = acc#balance#total
}

let must_get_balance ~logger t ~account_id =
get_balance ~logger t ~account_id
let must_get_account_data ~logger t ~public_key =
get_account_data ~logger t ~public_key
|> Deferred.bind ~f:Malleable_error.or_hard_error

type signed_command_result =
Expand Down Expand Up @@ -461,6 +503,51 @@ module Node = struct
] ;
res

let send_payment_with_raw_sig ~logger t ~sender_pub_key ~receiver_pub_key
~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature =
[%log info] "Sending a payment with raw signature"
~metadata:(logger_metadata t) ;
let open Deferred.Or_error.Let_syntax in
let send_payment_graphql () =
let send_payment_obj =
Graphql.Send_payment_with_raw_sig.make
~sender:(Graphql_lib.Encoders.public_key sender_pub_key)
~receiver:(Graphql_lib.Encoders.public_key receiver_pub_key)
~amount:(Graphql_lib.Encoders.amount amount)
~token:(Graphql_lib.Encoders.token token)
~fee:(Graphql_lib.Encoders.fee fee)
~nonce:(Graphql_lib.Encoders.nonce nonce)
~memo
~validUntil:(Graphql_lib.Encoders.uint32 valid_until)
~rawSignature:raw_signature ()
in
[%log info] "send_payment_obj with $variables "
~metadata:[ ("variables", send_payment_obj#variables) ] ;
exec_graphql_request ~logger ~node:t
~query_name:"Send_payment_with_raw_sig_graphql" send_payment_obj
in
let%map sent_payment_obj = send_payment_graphql () in
let (`UserCommand return_obj) = sent_payment_obj#sendPayment#payment in
let res =
{ id = return_obj#id
; hash = return_obj#hash
; nonce = Unsigned.UInt32.of_int return_obj#nonce
}
in
[%log info] "Sent payment"
~metadata:
[ ("user_command_id", `String res.id)
; ("hash", `String res.hash)
; ("nonce", `Int (Unsigned.UInt32.to_int res.nonce))
] ;
res

let must_send_payment_with_raw_sig ~logger t ~sender_pub_key ~receiver_pub_key
~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature =
send_payment_with_raw_sig ~logger t ~sender_pub_key ~receiver_pub_key
~amount ~fee ~nonce ~memo ~token ~valid_until ~raw_signature
|> Deferred.bind ~f:Malleable_error.or_hard_error

let must_send_delegation ~logger t ~sender_pub_key ~receiver_pub_key ~amount
~fee =
send_delegation ~logger t ~sender_pub_key ~receiver_pub_key ~amount ~fee
Expand Down
15 changes: 14 additions & 1 deletion src/lib/integration_test_lib/event_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ module Block_produced = struct
; epoch : int
; global_slot : int
; snarked_ledger_generated : bool
; state_hash : State_hash.t
}
[@@deriving to_yojson]

Expand Down Expand Up @@ -179,6 +180,18 @@ module Block_produced = struct
let open Json_parsing in
let open Or_error.Let_syntax in
let%bind breadcrumb = get_metadata message "breadcrumb" in
let%bind state_hash_str =
find string breadcrumb [ "validated_transition"; "hash"; "state_hash" ]
in
let%bind state_hash =
State_hash.of_yojson (`String state_hash_str)
|> fun res ->
match res with
| Ok hash ->
Or_error.return hash
| Error str ->
Or_error.error_string str
in
let%bind snarked_ledger_generated =
find bool breadcrumb [ "just_emitted_a_proof" ]
in
Expand All @@ -198,7 +211,7 @@ module Block_produced = struct
find int breadcrumb_consensus_state [ "curr_global_slot"; "slot_number" ]
in
let%map epoch = find int breadcrumb_consensus_state [ "epoch_count" ] in
{ block_height; global_slot; epoch; snarked_ledger_generated }
{ block_height; global_slot; epoch; snarked_ledger_generated; state_hash }

let parse = From_daemon_log (structured_event_id, parse_func)
end
Expand Down
1 change: 1 addition & 0 deletions src/lib/integration_test_lib/event_type.mli
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module Block_produced : sig
; epoch : int
; global_slot : int
; snarked_ledger_generated : bool
; state_hash : State_hash.t
}

include Event_type_intf with type t := t
Expand Down
45 changes: 39 additions & 6 deletions src/lib/integration_test_lib/intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ module Engine = struct
-> fee:Currency.Fee.t
-> signed_command_result Malleable_error.t

val send_payment_with_raw_sig :
logger:Logger.t
-> t
-> sender_pub_key:Signature_lib.Public_key.Compressed.t
-> receiver_pub_key:Signature_lib.Public_key.Compressed.t
-> amount:Currency.Amount.t
-> fee:Currency.Fee.t
-> nonce:Mina_numbers.Account_nonce.t
-> memo:string
-> token:Token_id.t
-> valid_until:Mina_numbers.Global_slot.t
-> raw_signature:string
-> signed_command_result Deferred.Or_error.t

val must_send_payment_with_raw_sig :
logger:Logger.t
-> t
-> sender_pub_key:Signature_lib.Public_key.Compressed.t
-> receiver_pub_key:Signature_lib.Public_key.Compressed.t
-> amount:Currency.Amount.t
-> fee:Currency.Fee.t
-> nonce:Mina_numbers.Account_nonce.t
-> memo:string
-> token:Token_id.t
-> valid_until:Mina_numbers.Global_slot.t
-> raw_signature:string
-> signed_command_result Malleable_error.t

val send_delegation :
logger:Logger.t
-> t
Expand Down Expand Up @@ -100,17 +128,20 @@ module Engine = struct
-> fee:Currency.Fee.t
-> unit Malleable_error.t

val get_balance :
type account_data =
{ nonce : Unsigned.uint32; total_balance : Currency.Balance.t }

val get_account_data :
logger:Logger.t
-> t
-> account_id:Mina_base.Account_id.t
-> Currency.Balance.t Async_kernel.Deferred.Or_error.t
-> public_key:Signature_lib.Public_key.Compressed.t
-> account_data Async_kernel.Deferred.Or_error.t

val must_get_balance :
val must_get_account_data :
logger:Logger.t
-> t
-> account_id:Mina_base.Account_id.t
-> Currency.Balance.t Malleable_error.t
-> public_key:Signature_lib.Public_key.Compressed.t
-> account_data Malleable_error.t

val get_peer_id :
logger:Logger.t
Expand Down Expand Up @@ -262,6 +293,7 @@ module Dsl = struct
; node_initialization : bool String.Map.t
; gossip_received : Gossip_state.t String.Map.t
; best_tips_by_node : State_hash.t String.Map.t
; blocks_produced_by_node : State_hash.t list String.Map.t
}

val listen :
Expand Down Expand Up @@ -304,6 +336,7 @@ module Dsl = struct
-> amount:Amount.t
-> nonce:Unsigned.uint32
-> command_type:command_type
-> node_included_in:[ `Any_node | `Node of Engine.Network.Node.t ]
-> t
end

Expand Down
15 changes: 15 additions & 0 deletions src/lib/integration_test_lib/network_state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module Make
[@to_yojson map_to_yojson ~f:Gossip_state.to_yojson]
; best_tips_by_node : State_hash.t String.Map.t
[@to_yojson map_to_yojson ~f:State_hash.to_yojson]
; blocks_produced_by_node : State_hash.t list String.Map.t
[@to_yojson
map_to_yojson ~f:(fun ls ->
`List (List.map State_hash.to_yojson ls))]
}
[@@deriving to_yojson]

Expand All @@ -38,6 +42,7 @@ module Make
; node_initialization = String.Map.empty
; gossip_received = String.Map.empty
; best_tips_by_node = String.Map.empty
; blocks_produced_by_node = String.Map.empty
}

let listen ~logger event_router =
Expand All @@ -62,6 +67,15 @@ module Make
let snarked_ledgers_generated =
if block_produced.snarked_ledger_generated then 1 else 0
in
let blocks_produced_by_node_map =
Core.String.Map.update state.blocks_produced_by_node
(Node.id node) ~f:(fun ls_opt ->
match ls_opt with
| None ->
[ block_produced.state_hash ]
| Some ls ->
List.cons block_produced.state_hash ls)
in
{ state with
epoch = block_produced.global_slot
; global_slot = block_produced.global_slot
Expand All @@ -70,6 +84,7 @@ module Make
; snarked_ledgers_generated =
state.snarked_ledgers_generated
+ snarked_ledgers_generated
; blocks_produced_by_node = blocks_produced_by_node_map
}
else state))
: _ Event_router.event_subscription ) ;
Expand Down
Loading