diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- refutation game timeout.out b/tezt/tests/expected/sc_rollup.ml/Alpha- refutation game timeout.out new file mode 100644 index 0000000000000000000000000000000000000000..3e4a3c91236f6dc837f27c164085e01e0dcc2b71 --- /dev/null +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- refutation game timeout.out @@ -0,0 +1,326 @@ + +./tezos-client --wait none originate sc rollup from bootstrap1 of kind arith of type unit booting with --burn-cap 9999999 +Node is bootstrapped. +Estimated gas: 3110.429 units (will add 100 for safety) +Estimated storage: 6651 bytes added (will add 20 for safety) +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000674 + Expected counter: 1 + Gas limit: 3211 + Storage limit: 6671 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000674 + payload fees(the block proposer) ....... +ꜩ0.000674 + Smart contract rollup origination: + Kind: arith + Parameter type: unit + Boot sector: '' + This smart contract rollup origination was successfully applied + Consumed gas: 3110.429 + Storage size: 6651 bytes + Address: [SC_ROLLUP_HASH] + Genesis commitment hash: [SC_ROLLUP_COMMITMENT_HASH] + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ1.66275 + storage fees ........................... +ꜩ1.66275 + + +./tezos-client --wait none publish commitment from '[PUBLIC_KEY_HASH]' for sc rollup '[SC_ROLLUP_HASH]' with compressed state scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf at inbox level 5 and predecessor '[SC_ROLLUP_COMMITMENT_HASH]' and number of ticks 1 +Node is bootstrapped. +Estimated gas: 5781.683 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000926 + Expected counter: 2 + Gas limit: 5882 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000926 + payload fees(the block proposer) ....... +ꜩ0.000926 + Smart contract rollup commitment publishing: + Address: [SC_ROLLUP_HASH] + Commitment: + compressed_state: scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf + inbox_level: 5 + predecessor: [SC_ROLLUP_COMMITMENT_HASH] + number_of_ticks: 1 + This smart contract rollup commitment publishing was successfully applied + Consumed gas: 5781.683 + Hash of commit: [SC_ROLLUP_COMMITMENT_HASH] + Commitment published at level: 6 + Balance updates: + [PUBLIC_KEY_HASH] ....................................................... -ꜩ10000 + Frozen_bonds([PUBLIC_KEY_HASH],[SC_ROLLUP_HASH]) ... +ꜩ10000 + + +./tezos-client --wait none publish commitment from '[PUBLIC_KEY_HASH]' for sc rollup '[SC_ROLLUP_HASH]' with compressed state scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf at inbox level 8 and predecessor '[SC_ROLLUP_COMMITMENT_HASH]' and number of ticks 2 +Node is bootstrapped. +Estimated gas: 4245.511 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000772 + Expected counter: 3 + Gas limit: 4346 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000772 + payload fees(the block proposer) ....... +ꜩ0.000772 + Smart contract rollup commitment publishing: + Address: [SC_ROLLUP_HASH] + Commitment: + compressed_state: scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf + inbox_level: 8 + predecessor: [SC_ROLLUP_COMMITMENT_HASH] + number_of_ticks: 2 + This smart contract rollup commitment publishing was successfully applied + Consumed gas: 4245.511 + Hash of commit: [SC_ROLLUP_COMMITMENT_HASH] + Commitment published at level: 9 + + +./tezos-client --wait none publish commitment from '[PUBLIC_KEY_HASH]' for sc rollup '[SC_ROLLUP_HASH]' with compressed state scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf at inbox level 11 and predecessor '[SC_ROLLUP_COMMITMENT_HASH]' and number of ticks 31 +Node is bootstrapped. +Estimated gas: 4245.511 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000772 + Expected counter: 4 + Gas limit: 4346 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000772 + payload fees(the block proposer) ....... +ꜩ0.000772 + Smart contract rollup commitment publishing: + Address: [SC_ROLLUP_HASH] + Commitment: + compressed_state: scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf + inbox_level: 11 + predecessor: [SC_ROLLUP_COMMITMENT_HASH] + number_of_ticks: 31 + This smart contract rollup commitment publishing was successfully applied + Consumed gas: 4245.511 + Hash of commit: [SC_ROLLUP_COMMITMENT_HASH] + Commitment published at level: 12 + + +./tezos-client --wait none publish commitment from '[PUBLIC_KEY_HASH]' for sc rollup '[SC_ROLLUP_HASH]' with compressed state scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf at inbox level 11 and predecessor '[SC_ROLLUP_COMMITMENT_HASH]' and number of ticks 32 +Node is bootstrapped. +Estimated gas: 8082.023 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.001156 + Expected counter: 1 + Gas limit: 8183 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.001156 + payload fees(the block proposer) ....... +ꜩ0.001156 + Smart contract rollup commitment publishing: + Address: [SC_ROLLUP_HASH] + Commitment: + compressed_state: scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf + inbox_level: 11 + predecessor: [SC_ROLLUP_COMMITMENT_HASH] + number_of_ticks: 32 + This smart contract rollup commitment publishing was successfully applied + Consumed gas: 8082.023 + Hash of commit: [SC_ROLLUP_COMMITMENT_HASH] + Commitment published at level: 13 + Balance updates: + [PUBLIC_KEY_HASH] ....................................................... -ꜩ10000 + Frozen_bonds([PUBLIC_KEY_HASH],[SC_ROLLUP_HASH]) ... +ꜩ10000 + + +./tezos-client --wait none publish commitment from '[PUBLIC_KEY_HASH]' for sc rollup '[SC_ROLLUP_HASH]' with compressed state scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf at inbox level 14 and predecessor '[SC_ROLLUP_COMMITMENT_HASH]' and number of ticks 311 +Node is bootstrapped. +Estimated gas: 4245.511 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000772 + Expected counter: 5 + Gas limit: 4346 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000772 + payload fees(the block proposer) ....... +ꜩ0.000772 + Smart contract rollup commitment publishing: + Address: [SC_ROLLUP_HASH] + Commitment: + compressed_state: scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf + inbox_level: 14 + predecessor: [SC_ROLLUP_COMMITMENT_HASH] + number_of_ticks: 311 + This smart contract rollup commitment publishing was successfully applied + Consumed gas: 4245.511 + Hash of commit: [SC_ROLLUP_COMMITMENT_HASH] + Commitment published at level: 15 + + +./tezos-client --wait none publish commitment from '[PUBLIC_KEY_HASH]' for sc rollup '[SC_ROLLUP_HASH]' with compressed state scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf at inbox level 14 and predecessor '[SC_ROLLUP_COMMITMENT_HASH]' and number of ticks 321 +Node is bootstrapped. +Estimated gas: 4245.511 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000772 + Expected counter: 2 + Gas limit: 4346 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000772 + payload fees(the block proposer) ....... +ꜩ0.000772 + Smart contract rollup commitment publishing: + Address: [SC_ROLLUP_HASH] + Commitment: + compressed_state: scs11VNjWyZw4Tgbvsom8epQbox86S2CKkE1UAZkXMM7Pj8MQMLzMf + inbox_level: 14 + predecessor: [SC_ROLLUP_COMMITMENT_HASH] + number_of_ticks: 321 + This smart contract rollup commitment publishing was successfully applied + Consumed gas: 4245.511 + Hash of commit: [SC_ROLLUP_COMMITMENT_HASH] + Commitment published at level: 16 + + +./tezos-client --wait none cement commitment '[SC_ROLLUP_COMMITMENT_HASH]' from bootstrap1 for sc rollup '[SC_ROLLUP_HASH]' +Node is bootstrapped. +Estimated gas: 4115.508 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000719 + Expected counter: 6 + Gas limit: 4216 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000719 + payload fees(the block proposer) ....... +ꜩ0.000719 + Smart contract rollup commitment cementing: + Address: [SC_ROLLUP_HASH] + Commitment: [SC_ROLLUP_COMMITMENT_HASH] + This smart contract rollup commitment cementing was successfully applied + Consumed gas: 4115.508 + Inbox level: 5 + + +./tezos-client --wait none cement commitment '[SC_ROLLUP_COMMITMENT_HASH]' from bootstrap1 for sc rollup '[SC_ROLLUP_HASH]' +Node is bootstrapped. +Estimated gas: 4575.654 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000765 + Expected counter: 7 + Gas limit: 4676 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000765 + payload fees(the block proposer) ....... +ꜩ0.000765 + Smart contract rollup commitment cementing: + Address: [SC_ROLLUP_HASH] + Commitment: [SC_ROLLUP_COMMITMENT_HASH] + This smart contract rollup commitment cementing was successfully applied + Consumed gas: 4575.654 + Inbox level: 8 + + +./tezos-client --wait none timeout dispute on sc rollup '[SC_ROLLUP_HASH]' with '[PUBLIC_KEY_HASH]' from bootstrap1 +Node is bootstrapped. +Estimated gas: 8210.850 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + tezos-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.001139 + Expected counter: 8 + Gas limit: 8311 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.001139 + payload fees(the block proposer) ....... +ꜩ0.001139 + Smart contract rollup refutation timeout: + Address: [SC_ROLLUP_HASH] + First staker (Alice): [PUBLIC_KEY_HASH] + Second staker (Bob): [PUBLIC_KEY_HASH] + This smart contract rollup refutation timeout was successfully applied + Consumed gas: 8210.850 + Refutation game status: Game ended due to timeout, [PUBLIC_KEY_HASH] loses their stake + Balance updates: + Frozen_bonds([PUBLIC_KEY_HASH],[SC_ROLLUP_HASH]) ... -ꜩ10000 + sc rollup refutation punishments ........................................................... +ꜩ10000 + diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index 262d6d84572a241c9243b7f5f4d99db4df16e31a..c04abf4f28431f17bdd31ae1b85f4c5b5ada6dd1 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -1,7 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs *) +(* Copyright (c) 2021-2022 Nomadic Labs *) (* Copyright (c) 2022 TriliTech *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) @@ -57,6 +57,7 @@ type sc_rollup_constants = { max_active_outbox_levels : int32; max_outbox_messages_per_level : int; number_of_sections_in_dissection : int; + timeout_period_in_blocks : int; } (** [boot_sector_of k] returns a valid boot sector for a PVM of @@ -95,6 +96,9 @@ let get_sc_rollup_constants client = let number_of_sections_in_dissection = json |-> "sc_rollup_number_of_sections_in_dissection" |> as_int in + let timeout_period_in_blocks = + json |-> "sc_rollup_timeout_period_in_blocks" |> as_int + in return { origination_size; @@ -106,6 +110,7 @@ let get_sc_rollup_constants client = max_active_outbox_levels; max_outbox_messages_per_level; number_of_sections_in_dissection; + timeout_period_in_blocks; } (* List of scoru errors messages used in tests below. *) @@ -2511,7 +2516,10 @@ let test_forking_scenario ~title ~scenario protocols = of [mk_forking_commitments] is cementable without further bakes. *) let commitment_period = 3 in let challenge_window = commitment_period * 7 in - setup ~commitment_period ~challenge_window ~protocol + (* Completely arbitrary as we decide when to trigger timeouts in tests. + Making it a lot smaller than the default value to speed up tests. *) + let timeout = 10 in + setup ~commitment_period ~challenge_window ~timeout ~protocol @@ fun node client _bootstrap1_key -> (* Originate a Sc rollup. *) let* sc_rollup = originate_sc_rollup client ~parameters_ty:"unit" in @@ -2539,6 +2547,10 @@ let test_forking_scenario ~title ~scenario protocols = level1) protocols +(* A more convenient wrapper around [cement_commitment]. *) +let cement_commitments client sc_rollup ?fail = + Lwt_list.iter_s (fun hash -> cement_commitment client ~sc_rollup ~hash ?fail) + (** Given a commitment tree constructed by {test_forking_scenario}, this function: - tests different (failing and non-failing) cementation of commitments and checks the returned error for each situation (in case of failure); @@ -2555,12 +2567,7 @@ let test_no_cementation_if_parent_not_lcc_or_if_disputed_commit protocols = let* constants = get_sc_rollup_constants client in let challenge_window = constants.challenge_window_in_blocks in - (* More convenient Wrapper around cement_commitment for the tests below *) - let cement ?fail l = - Lwt_list.iter_s - (fun hash -> cement_commitment client ~sc_rollup ~hash ?fail) - l - in + let cement = cement_commitments client sc_rollup in let missing_blocks_to_cement = level0 + challenge_window - level1 in let* () = if missing_blocks_to_cement <= 0 then unit (* We can already cement *) @@ -2624,12 +2631,7 @@ let test_valid_dispute_dissection protocols = ~scenario: (fun client _node ~sc_rollup ~operator1 ~operator2 commits _level0 _level1 -> let c1, c2, c31, c32, _c311, _c321 = commits in - (* More convenient wrapper around cement_commitment for the tests below *) - let cement ?fail l = - Lwt_list.iter_s - (fun hash -> cement_commitment client ~sc_rollup ~hash ?fail) - l - in + let cement = cement_commitments client sc_rollup in let* constants = get_sc_rollup_constants client in let challenge_window = constants.challenge_window_in_blocks in let commitment_period = constants.commitment_period_in_blocks in @@ -2702,6 +2704,66 @@ let test_late_rollup_node = let* _status = Sc_rollup_node.wait_for_level ~timeout:2. sc_rollup_node 95 in return () +let timeout ?expect_failure ~sc_rollup ~staker client = + let*! () = + Client.Sc_rollup.timeout + ~hooks + ~dst:sc_rollup + ~src:"bootstrap1" + ~staker + client + ?expect_failure + in + Client.bake_for_and_wait client + +(* Testing the timeout to record gas consumption in a regression trace and + detect when the value changes. + For functional tests on timing-out a dispute, see unit tests in + [lib_protocol]. + + For this test, we rely on [test_forking_scenario] to create a tree structure + of commitments and we start a dispute. + The first player is not even going to play, we'll simply bake enough blocks + to get to the point where we can timeout. *) +let test_timeout protocols = + test_forking_scenario + ~title:"refutation game timeout" + ~scenario: + (fun client _node ~sc_rollup ~operator1 ~operator2 commits level0 level1 -> + (* These are the commitments on the rollup. See [test_forking_scenario] to + visualize the tree structure. *) + let c1, c2, _c31, _c32, _c311, _c321 = commits in + (* A helper function to cement a sequence of commitments. *) + let cement = cement_commitments client sc_rollup in + let* constants = get_sc_rollup_constants client in + let challenge_window = constants.challenge_window_in_blocks in + let timeout_period = constants.timeout_period_in_blocks in + + (* Bake enough blocks to cement the commitments up to the divergence. *) + let* () = + repeat + (* There are [level0 - level1 - 1] blocks between [level1] and + [level0], plus the challenge window for [c1] and the one for [c2]. + *) + (level0 - level1 - 1 + (2 * challenge_window)) + (fun () -> Client.bake_for_and_wait client) + in + let* () = cement [c1; c2] in + + let module M = Operation.Manager in + (* [operator2] starts a dispute. Its opponent, [operator1], won't play. *) + let* () = + bake_operation_via_rpc client + @@ M.make ~source:operator2 + @@ M.sc_rollup_refute ~sc_rollup ~opponent:operator1.public_key_hash () + in + (* Get exactly to the block where we are able to timeout. *) + let* () = + repeat (timeout_period + 1) (fun () -> Client.bake_for_and_wait client) + in + timeout ~sc_rollup ~staker:operator2.public_key_hash client) + protocols + let register ~kind ~protocols = test_origination ~kind protocols ; test_rollup_node_running ~kind protocols ; @@ -2822,4 +2884,5 @@ let register ~protocols = register ~kind:"wasm_2_0_0" ~protocols ; register ~kind:"arith" ~protocols ; test_no_cementation_if_parent_not_lcc_or_if_disputed_commit protocols ; - test_valid_dispute_dissection protocols + test_valid_dispute_dissection protocols ; + test_timeout protocols