-
Notifications
You must be signed in to change notification settings - Fork 583
Feature/timing update requires signature #11006
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
Merged
deepthiskumar
merged 13 commits into
develop
from
feature/timing-update-requires-signature
May 26, 2022
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
87c8677
add set_timing
ghost-not-in-the-shell b62dbcd
modify parties_logic to check for permissions of timing
ghost-not-in-the-shell de1f680
Revert "modify parties_logic to check for permissions of timing"
ghost-not-in-the-shell 667be5a
Revert "add set_timing"
ghost-not-in-the-shell d41a2f9
hard-code the check for signature
ghost-not-in-the-shell e7acfe9
clean up the test
ghost-not-in-the-shell 52a0c12
address matthew's comment
ghost-not-in-the-shell 5eab1a9
Merge branch 'develop' of github.com:MinaProtocol/mina into feature/t…
ghost-not-in-the-shell cedb32f
adding checks for set untimed account to timed
ghost-not-in-the-shell e394bb5
Merge branch 'develop' of github.com:MinaProtocol/mina into feature/t…
ghost-not-in-the-shell dcfffd2
add tests for update timing_info
ghost-not-in-the-shell babeb5e
Merge branch 'develop' of github.com:MinaProtocol/mina into feature/t…
ghost-not-in-the-shell 43e1464
address deepthi's comment
ghost-not-in-the-shell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -1563,4 +1563,242 @@ let%test_module "account timing check" = | |
~state_view ledger parties | ||
in | ||
check_zkapp_failure Transaction_status.Failure.Overflow result ) ) | ||
|
||
let%test_unit "zkApp command, create timed account with wrong authorization" | ||
= | ||
let ledger_init_state = | ||
List.map keypairs ~f:(fun keypair -> | ||
let balance = Currency.Amount.of_int 100_000_000_000_000 in | ||
let nonce = Mina_numbers.Account_nonce.zero in | ||
(keypair, balance, nonce, Account_timing.Untimed) ) | ||
|> Array.of_list | ||
in | ||
let sender_keypair = List.hd_exn keypairs in | ||
let zkapp_keypair = Signature_lib.Keypair.create () in | ||
let (create_timed_account_spec : Transaction_snark.For_tests.Spec.t) = | ||
{ sender = (sender_keypair, Account.Nonce.zero) | ||
; fee = Currency.Fee.of_int 1_000_000 | ||
; fee_payer = None | ||
; receivers = [] | ||
; amount = Currency.Amount.of_int 50_000_000_000_000 | ||
; zkapp_account_keypairs = [ zkapp_keypair ] | ||
; memo = | ||
Signed_command_memo.create_from_string_exn | ||
"zkApp create timed account" | ||
; new_zkapp_account = true | ||
; snapp_update = | ||
(let timing = | ||
Zkapp_basic.Set_or_keep.Set | ||
( { initial_minimum_balance = | ||
Currency.Balance.of_int 1_000_000_000 | ||
; cliff_time = Mina_numbers.Global_slot.of_int 10 | ||
; cliff_amount = Currency.Amount.of_int 1_000_000_000 | ||
; vesting_period = Mina_numbers.Global_slot.of_int 10 | ||
; vesting_increment = Currency.Amount.of_int 1_000_000_000 | ||
} | ||
: Party.Update.Timing_info.value ) | ||
in | ||
{ Party.Update.dummy with timing } ) | ||
; current_auth = Permissions.Auth_required.Proof | ||
; call_data = Snark_params.Tick.Field.zero | ||
; events = [] | ||
; sequence_events = [] | ||
; protocol_state_precondition = None | ||
; account_precondition = None | ||
} | ||
in | ||
let timing_account_id = | ||
Account_id.create | ||
(zkapp_keypair.public_key |> Signature_lib.Public_key.compress) | ||
Token_id.default | ||
in | ||
let create_timed_account_parties, _, _, _ = | ||
( Transaction_snark.For_tests.deploy_snapp ~no_auth:true | ||
~constraint_constants create_timed_account_spec | ||
, timing_account_id | ||
, create_timed_account_spec.snapp_update | ||
, zkapp_keypair ) | ||
in | ||
let gen = | ||
Quickcheck.Generator.return | ||
(ledger_init_state, create_timed_account_parties) | ||
in | ||
Quickcheck.test | ||
~seed: | ||
(`Deterministic | ||
"zkapp command, create timed account with wrong authorization" ) | ||
~sexp_of:[%sexp_of: Mina_ledger.Ledger.init_state * Parties.t] ~trials:1 | ||
gen ~f:(fun (ledger_init_state, create_timed_account_parties) -> | ||
Mina_ledger.Ledger.with_ephemeral_ledger | ||
~depth:constraint_constants.ledger_depth ~f:(fun ledger -> | ||
Mina_ledger.Ledger.apply_initial_ledger_state ledger | ||
ledger_init_state ; | ||
let state_view = | ||
Transaction_snark_tests.Util.genesis_state_view | ||
in | ||
let result = | ||
Mina_ledger.Ledger.apply_parties_unchecked ~state_view | ||
~constraint_constants ledger create_timed_account_parties | ||
in | ||
check_zkapp_failure | ||
Transaction_status.Failure | ||
.Update_not_permitted_timing_existing_account result ) ) | ||
|
||
let%test_unit "zkApp command, change untimed account to timed" = | ||
Async.Thread_safe.block_on_async_exn (fun () -> | ||
let ledger_init_state = | ||
List.map keypairs ~f:(fun keypair -> | ||
let balance = Currency.Amount.of_int 100_000_000_000_000 in | ||
let nonce = Mina_numbers.Account_nonce.zero in | ||
(keypair, balance, nonce, Account_timing.Untimed) ) | ||
|> Array.of_list | ||
in | ||
let sender_keypair = List.hd_exn keypairs in | ||
let zkapp_keypair = List.nth_exn keypairs 1 in | ||
let (update_timing_spec : Transaction_snark.For_tests.Spec.t) = | ||
{ sender = (sender_keypair, Account.Nonce.zero) | ||
; fee = Currency.Fee.of_int 1_000_000 | ||
; fee_payer = None | ||
; receivers = [] | ||
; amount = Currency.Amount.zero | ||
; zkapp_account_keypairs = [ zkapp_keypair ] | ||
; memo = | ||
Signed_command_memo.create_from_string_exn "zkApp update timing" | ||
; new_zkapp_account = false | ||
; snapp_update = | ||
(let timing = | ||
Zkapp_basic.Set_or_keep.Set | ||
( { initial_minimum_balance = | ||
Currency.Balance.of_int 1_000_000_000 | ||
; cliff_time = Mina_numbers.Global_slot.of_int 10 | ||
; cliff_amount = Currency.Amount.of_int 1_000_000_000 | ||
; vesting_period = Mina_numbers.Global_slot.of_int 10 | ||
; vesting_increment = | ||
Currency.Amount.of_int 1_000_000_000 | ||
} | ||
: Party.Update.Timing_info.value ) | ||
in | ||
{ Party.Update.dummy with timing } ) | ||
; current_auth = Permissions.Auth_required.Signature | ||
; call_data = Snark_params.Tick.Field.zero | ||
; events = [] | ||
; sequence_events = [] | ||
; protocol_state_precondition = None | ||
; account_precondition = None | ||
} | ||
in | ||
let open Async.Deferred.Let_syntax in | ||
let%map update_timing_parties = | ||
Transaction_snark.For_tests.update_states ~constraint_constants | ||
update_timing_spec | ||
in | ||
let gen = | ||
Quickcheck.Generator.return | ||
(ledger_init_state, update_timing_parties) | ||
in | ||
Quickcheck.test | ||
~seed: | ||
(`Deterministic | ||
"zkapp command, change untimed account to timed account" ) | ||
~sexp_of:[%sexp_of: Mina_ledger.Ledger.init_state * Parties.t] | ||
~trials:1 gen ~f:(fun (ledger_init_state, update_timing_parties) -> | ||
Mina_ledger.Ledger.with_ephemeral_ledger | ||
~depth:constraint_constants.ledger_depth ~f:(fun ledger -> | ||
Mina_ledger.Ledger.apply_initial_ledger_state ledger | ||
ledger_init_state ; | ||
let state_view = | ||
Transaction_snark_tests.Util.genesis_state_view | ||
in | ||
match | ||
Mina_ledger.Ledger.apply_parties_unchecked ~state_view | ||
~constraint_constants ledger update_timing_parties | ||
with | ||
| Ok _ -> | ||
() | ||
| Error e -> | ||
failwith (Error.to_string_hum e) ) ) ) | ||
|
||
let%test_unit "zkApp command, invalid update for timed account" = | ||
Async.Thread_safe.block_on_async_exn (fun () -> | ||
let ledger_init_state = | ||
List.mapi keypairs ~f:(fun i keypair -> | ||
let balance = Currency.Amount.of_int 100_000_000_000_000 in | ||
let nonce = Mina_numbers.Account_nonce.zero in | ||
( keypair | ||
, balance | ||
, nonce | ||
, if i = 1 then | ||
Account_timing.Timed | ||
{ initial_minimum_balance = | ||
Currency.Balance.of_int 10_000_000_000 | ||
; cliff_time = Mina_numbers.Global_slot.of_int 10_000 | ||
; cliff_amount = Currency.Amount.zero | ||
; vesting_period = Mina_numbers.Global_slot.of_int 1 | ||
; vesting_increment = Currency.Amount.of_int 100_000 | ||
} | ||
else Account_timing.Untimed ) ) | ||
|> Array.of_list | ||
in | ||
let sender_keypair = List.hd_exn keypairs in | ||
let zkapp_keypair = List.nth_exn keypairs 1 in | ||
let (update_timing_spec : Transaction_snark.For_tests.Spec.t) = | ||
{ sender = (sender_keypair, Account.Nonce.zero) | ||
; fee = Currency.Fee.of_int 1_000_000 | ||
; fee_payer = None | ||
; receivers = [] | ||
; amount = Currency.Amount.zero | ||
; zkapp_account_keypairs = [ zkapp_keypair ] | ||
; memo = | ||
Signed_command_memo.create_from_string_exn "zkApp update timing" | ||
; new_zkapp_account = false | ||
; snapp_update = | ||
(let timing = | ||
Zkapp_basic.Set_or_keep.Set | ||
( { initial_minimum_balance = | ||
Currency.Balance.of_int 1_000_000_000 | ||
; cliff_time = Mina_numbers.Global_slot.of_int 10 | ||
; cliff_amount = Currency.Amount.of_int 1_000_000_000 | ||
; vesting_period = Mina_numbers.Global_slot.of_int 10 | ||
; vesting_increment = | ||
Currency.Amount.of_int 1_000_000_000 | ||
} | ||
: Party.Update.Timing_info.value ) | ||
in | ||
{ Party.Update.dummy with timing } ) | ||
; current_auth = Permissions.Auth_required.Signature | ||
; call_data = Snark_params.Tick.Field.zero | ||
; events = [] | ||
; sequence_events = [] | ||
; protocol_state_precondition = None | ||
; account_precondition = None | ||
} | ||
in | ||
let open Async.Deferred.Let_syntax in | ||
let%map update_timing_parties = | ||
Transaction_snark.For_tests.update_states ~constraint_constants | ||
update_timing_spec | ||
in | ||
let gen = | ||
Quickcheck.Generator.return | ||
(ledger_init_state, update_timing_parties) | ||
in | ||
Quickcheck.test | ||
~seed: | ||
(`Deterministic "zkapp command, invalid update for timed account") | ||
~sexp_of:[%sexp_of: Mina_ledger.Ledger.init_state * Parties.t] | ||
~trials:1 gen ~f:(fun (ledger_init_state, update_timing_parties) -> | ||
Mina_ledger.Ledger.with_ephemeral_ledger | ||
~depth:constraint_constants.ledger_depth ~f:(fun ledger -> | ||
Mina_ledger.Ledger.apply_initial_ledger_state ledger | ||
ledger_init_state ; | ||
let state_view = | ||
Transaction_snark_tests.Util.genesis_state_view | ||
in | ||
let result = | ||
|
||
Mina_ledger.Ledger.apply_parties_unchecked ~state_view | ||
~constraint_constants ledger update_timing_parties | ||
in | ||
check_zkapp_failure | ||
Transaction_status.Failure | ||
.Update_not_permitted_timing_existing_account result ) ) ) | ||
end ) |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you write a test for correct authorization and a test for the new case (fails when the account is already timed)?