-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict PTBs that use Random (#16077)
## Description PTBs can only have `TransferObjects` or `MergeCoins` following a command that uses `Random`, enforced by validators when receiving a signed transaction. ## Test Plan New transactional tests --- If your changes are not user-facing and do not break anything, you can skip the following section. Otherwise, please briefly describe what has changed under the Release Notes section. ### Type of Change (Check all that apply) - [x] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [x] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes PTBs can only have `TransferObjects` or `MergeCoins` following a command that uses `Random`, enforced by validators when receiving a signed transaction.
- Loading branch information
Showing
18 changed files
with
282 additions
and
2 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
crates/sui-adapter-transactional-tests/tests/random/happy_flows.exp
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,34 @@ | ||
processed 8 tasks | ||
|
||
init: | ||
A: object(0,0), B: object(0,1) | ||
|
||
task 1 'publish'. lines 6-28: | ||
created: object(1,0) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 6209200, storage_rebate: 0, non_refundable_storage_fee: 0 | ||
|
||
task 2 'programmable'. lines 29-32: | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880 | ||
|
||
task 3 'programmable'. lines 33-37: | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880 | ||
|
||
task 4 'programmable'. lines 38-42: | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880 | ||
|
||
task 5 'programmable'. lines 43-49: | ||
created: object(5,0) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 1976000, storage_rebate: 978120, non_refundable_storage_fee: 9880 | ||
|
||
task 6 'programmable'. lines 50-56: | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880 | ||
|
||
task 7 'programmable'. lines 57-58: | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880 |
58 changes: 58 additions & 0 deletions
58
crates/sui-adapter-transactional-tests/tests/random/happy_flows.move
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,58 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish --sender A | ||
module test::random { | ||
use sui::clock::Clock; | ||
use sui::random::Random; | ||
use sui::transfer; | ||
use sui::object; | ||
use sui::tx_context:: TxContext; | ||
|
||
public struct Obj has key, store { | ||
id: object::UID, | ||
} | ||
|
||
public entry fun create(ctx: &mut TxContext) { | ||
transfer::public_share_object(Obj { id: object::new(ctx) }) | ||
} | ||
|
||
public fun use_clock(_clock: &Clock) {} | ||
public fun use_random(_random: &Random) {} | ||
public fun use_random_twice(_random1: &Random, _random2: &Random) {} | ||
public fun use_value(_value: u64) {} | ||
} | ||
|
||
// Good tx - use Random | ||
//# programmable --sender A --inputs immshared(8) | ||
//> test::random::use_random(Input(0)); | ||
|
||
// Good tx - use Clock and then Random | ||
//# programmable --sender A --inputs immshared(6) immshared(8) @A | ||
//> test::random::use_clock(Input(0)); | ||
//> test::random::use_random(Input(1)); | ||
|
||
// Good tx - use value and then Random | ||
//# programmable --sender A --inputs 10 immshared(8) @A | ||
//> test::random::use_value(Input(0)); | ||
//> test::random::use_random(Input(1)); | ||
|
||
// Good tx - use Clock, then Random, then transfer | ||
//# programmable --sender A --inputs 10 immshared(6) immshared(8) @B | ||
//> SplitCoins(Gas, [Input(0)]); | ||
//> test::random::use_clock(Input(1)); | ||
//> test::random::use_random(Input(2)); | ||
//> TransferObjects([Result(0)], Input(3)); | ||
|
||
// Good tx - use Clock, then Random, then merge | ||
//# programmable --sender A --inputs 10 immshared(6) immshared(8) @B | ||
//> SplitCoins(Gas, [Input(0)]); | ||
//> test::random::use_clock(Input(1)); | ||
//> test::random::use_random(Input(2)); | ||
//> MergeCoins(Gas, [Result(0)]); | ||
|
||
// Good tx - use Random twice in the same call | ||
//# programmable --sender A --inputs immshared(8) | ||
//> test::random::use_random_twice(Input(0), Input(0)); |
12 changes: 12 additions & 0 deletions
12
crates/sui-adapter-transactional-tests/tests/random/move_call_clock_after_random.exp
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,12 @@ | ||
processed 3 tasks | ||
|
||
init: | ||
A: object(0,0), B: object(0,1) | ||
|
||
task 1 'publish'. lines 6-15: | ||
created: object(1,0) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 4240800, storage_rebate: 0, non_refundable_storage_fee: 0 | ||
|
||
task 2 'programmable'. lines 16-18: | ||
Error: Error checking transaction input objects: PostRandomCommandRestrictions |
18 changes: 18 additions & 0 deletions
18
crates/sui-adapter-transactional-tests/tests/random/move_call_clock_after_random.move
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,18 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish --sender A | ||
module test::random { | ||
use sui::clock::Clock; | ||
use sui::random::Random; | ||
|
||
public fun use_clock(_clock: &Clock) {} | ||
public fun use_random(_random: &Random) {} | ||
} | ||
|
||
// bad tx - use_random, use_clock | ||
//# programmable --sender A --inputs immshared(8) immshared(6) @A | ||
//> test::random::use_random(Input(0)); | ||
//> test::random::use_clock(Input(1)) |
12 changes: 12 additions & 0 deletions
12
...ui-adapter-transactional-tests/tests/random/move_call_clock_after_random_and_transfer.exp
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,12 @@ | ||
processed 3 tasks | ||
|
||
init: | ||
A: object(0,0), B: object(0,1) | ||
|
||
task 1 'publish'. lines 6-15: | ||
created: object(1,0) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 4240800, storage_rebate: 0, non_refundable_storage_fee: 0 | ||
|
||
task 2 'programmable'. lines 16-20: | ||
Error: Error checking transaction input objects: PostRandomCommandRestrictions |
20 changes: 20 additions & 0 deletions
20
...i-adapter-transactional-tests/tests/random/move_call_clock_after_random_and_transfer.move
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,20 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish --sender A | ||
module test::random { | ||
use sui::clock::Clock; | ||
use sui::random::Random; | ||
|
||
public fun use_clock(_clock: &Clock) {} | ||
public fun use_random(_random: &Random) {} | ||
} | ||
|
||
// bad tx - use_random, transfer, use_clock | ||
//# programmable --sender A --inputs 10 immshared(8) immshared(6) @B | ||
//> SplitCoins(Gas, [Input(0)]); | ||
//> test::random::use_random(Input(1)); | ||
//> TransferObjects([Result(0)], Input(3)); | ||
//> test::random::use_clock(Input(0)) |
12 changes: 12 additions & 0 deletions
12
crates/sui-adapter-transactional-tests/tests/random/move_call_u64_after_random.exp
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,12 @@ | ||
processed 3 tasks | ||
|
||
init: | ||
A: object(0,0), B: object(0,1) | ||
|
||
task 1 'publish'. lines 6-14: | ||
created: object(1,0) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 4081200, storage_rebate: 0, non_refundable_storage_fee: 0 | ||
|
||
task 2 'programmable'. lines 15-17: | ||
Error: Error checking transaction input objects: PostRandomCommandRestrictions |
17 changes: 17 additions & 0 deletions
17
crates/sui-adapter-transactional-tests/tests/random/move_call_u64_after_random.move
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,17 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish --sender A | ||
module test::random { | ||
use sui::random::Random; | ||
|
||
public fun use_random(_random: &Random) {} | ||
public fun use_value(_value: u64) {} | ||
} | ||
|
||
// bad tx - use_random, use_value, | ||
//# programmable --sender A --inputs 16 immshared(8) | ||
//> test::random::use_random(Input(1)); | ||
//> test::random::use_value(Input(0)) |
12 changes: 12 additions & 0 deletions
12
crates/sui-adapter-transactional-tests/tests/random/two_move_calls_with_random.exp
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,12 @@ | ||
processed 3 tasks | ||
|
||
init: | ||
A: object(0,0), B: object(0,1) | ||
|
||
task 1 'publish'. lines 6-13: | ||
created: object(1,0) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 3898800, storage_rebate: 0, non_refundable_storage_fee: 0 | ||
|
||
task 2 'programmable'. lines 14-16: | ||
Error: Error checking transaction input objects: PostRandomCommandRestrictions |
16 changes: 16 additions & 0 deletions
16
crates/sui-adapter-transactional-tests/tests/random/two_move_calls_with_random.move
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,16 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//# init --accounts A B --addresses test=0x0 | ||
|
||
//# publish --sender A | ||
module test::random { | ||
use sui::random::Random; | ||
|
||
public fun use_random(_random: &Random) {} | ||
} | ||
|
||
// bad tx - use_random twice | ||
//# programmable --sender A --inputs immshared(8) @A | ||
//> test::random::use_random(Input(0)); | ||
//> test::random::use_random(Input(0)); |
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
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
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
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
Oops, something went wrong.