forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move-prover] fix crash in read/write set analysis
The transfer functions for read_ref used an outdated version of the assignment logic that predated support for addresses flowing into/out of structs. Using the modern version and deleting the old one. Added E2E test that exercises the crash + passes now. Closes: aptos-labs#9320
- Loading branch information
1 parent
99524bb
commit 7d53db4
Showing
5 changed files
with
203 additions
and
43 deletions.
There are no files selected for viewing
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
158 changes: 158 additions & 0 deletions
158
language/move-prover/bytecode/tests/read_write_set/copy_struct.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,158 @@ | ||
============ initial translation from Move ================ | ||
|
||
[variant baseline] | ||
public fun CopyStruct::g() { | ||
var $t0|s1: CopyStruct::S | ||
var $t1|s2: CopyStruct::S | ||
var $t2: address | ||
var $t3: CopyStruct::S | ||
var $t4: u64 | ||
var $t5: &CopyStruct::S | ||
var $t6: &address | ||
var $t7: address | ||
var $t8: &mut CopyStruct::G | ||
var $t9: &mut u64 | ||
var $t10: address | ||
var $t11: CopyStruct::S | ||
var $t12: u64 | ||
var $t13: &CopyStruct::S | ||
var $t14: &address | ||
var $t15: address | ||
var $t16: &mut CopyStruct::G | ||
var $t17: &mut u64 | ||
0: $t2 := 0x7 | ||
1: $t3 := CopyStruct::ret_struct_copy($t2) | ||
2: $t0 := $t3 | ||
3: $t4 := 1 | ||
4: $t5 := borrow_local($t0) | ||
5: $t6 := borrow_field<CopyStruct::S>.a($t5) | ||
6: $t7 := read_ref($t6) | ||
7: $t8 := borrow_global<CopyStruct::G>($t7) | ||
8: $t9 := borrow_field<CopyStruct::G>.f($t8) | ||
9: write_ref($t9, $t4) | ||
10: $t10 := 0x7 | ||
11: $t11 := CopyStruct::ret_struct($t10) | ||
12: $t1 := $t11 | ||
13: $t12 := 2 | ||
14: $t13 := borrow_local($t1) | ||
15: $t14 := borrow_field<CopyStruct::S>.a($t13) | ||
16: $t15 := read_ref($t14) | ||
17: $t16 := borrow_global<CopyStruct::G>($t15) | ||
18: $t17 := borrow_field<CopyStruct::G>.f($t16) | ||
19: write_ref($t17, $t12) | ||
20: return () | ||
} | ||
|
||
|
||
[variant baseline] | ||
public fun CopyStruct::ret_struct($t0|a: address): CopyStruct::S { | ||
var $t1: address | ||
var $t2: CopyStruct::S | ||
0: $t1 := copy($t0) | ||
1: $t2 := pack CopyStruct::S($t1) | ||
2: return $t2 | ||
} | ||
|
||
|
||
[variant baseline] | ||
public fun CopyStruct::ret_struct_copy($t0|a: address): CopyStruct::S { | ||
var $t1|s: CopyStruct::S | ||
var $t2: address | ||
var $t3: CopyStruct::S | ||
var $t4: &CopyStruct::S | ||
var $t5: CopyStruct::S | ||
0: $t2 := copy($t0) | ||
1: $t3 := pack CopyStruct::S($t2) | ||
2: $t1 := $t3 | ||
3: $t4 := borrow_local($t1) | ||
4: $t5 := read_ref($t4) | ||
5: return $t5 | ||
} | ||
|
||
============ after pipeline `read_write_set` ================ | ||
|
||
[variant baseline] | ||
public fun CopyStruct::g() { | ||
var $t0|s1: CopyStruct::S | ||
var $t1|s2: CopyStruct::S | ||
var $t2: address | ||
var $t3: CopyStruct::S | ||
var $t4: u64 | ||
var $t5: &CopyStruct::S | ||
var $t6: &address | ||
var $t7: address | ||
var $t8: &mut CopyStruct::G | ||
var $t9: &mut u64 | ||
var $t10: address | ||
var $t11: CopyStruct::S | ||
var $t12: u64 | ||
var $t13: &CopyStruct::S | ||
var $t14: &address | ||
var $t15: address | ||
var $t16: &mut CopyStruct::G | ||
var $t17: &mut u64 | ||
# Accesses: | ||
# 0x7/0x1::CopyStruct::G/f: Write | ||
# | ||
# Locals: | ||
# | ||
0: $t2 := 0x7 | ||
1: $t3 := CopyStruct::ret_struct_copy($t2) | ||
2: $t0 := $t3 | ||
3: $t4 := 1 | ||
4: $t5 := borrow_local($t0) | ||
5: $t6 := borrow_field<CopyStruct::S>.a($t5) | ||
6: $t7 := read_ref($t6) | ||
7: $t8 := borrow_global<CopyStruct::G>($t7) | ||
8: $t9 := borrow_field<CopyStruct::G>.f($t8) | ||
9: write_ref($t9, $t4) | ||
10: $t10 := 0x7 | ||
11: $t11 := CopyStruct::ret_struct($t10) | ||
12: $t1 := $t11 | ||
13: $t12 := 2 | ||
14: $t13 := borrow_local($t1) | ||
15: $t14 := borrow_field<CopyStruct::S>.a($t13) | ||
16: $t15 := read_ref($t14) | ||
17: $t16 := borrow_global<CopyStruct::G>($t15) | ||
18: $t17 := borrow_field<CopyStruct::G>.f($t16) | ||
19: write_ref($t17, $t12) | ||
20: return () | ||
} | ||
|
||
|
||
[variant baseline] | ||
public fun CopyStruct::ret_struct($t0|a: address): CopyStruct::S { | ||
var $t1: address | ||
var $t2: CopyStruct::S | ||
# Accesses: | ||
# Formal(0): Read | ||
# | ||
# Locals: | ||
# Ret(0)/a: Formal(0) | ||
# | ||
0: $t1 := copy($t0) | ||
1: $t2 := pack CopyStruct::S($t1) | ||
2: return $t2 | ||
} | ||
|
||
|
||
[variant baseline] | ||
public fun CopyStruct::ret_struct_copy($t0|a: address): CopyStruct::S { | ||
var $t1|s: CopyStruct::S | ||
var $t2: address | ||
var $t3: CopyStruct::S | ||
var $t4: &CopyStruct::S | ||
var $t5: CopyStruct::S | ||
# Accesses: | ||
# Formal(0): Read | ||
# | ||
# Locals: | ||
# Ret(0)/a: Formal(0) | ||
# | ||
0: $t2 := copy($t0) | ||
1: $t3 := pack CopyStruct::S($t2) | ||
2: $t1 := $t3 | ||
3: $t4 := borrow_local($t1) | ||
4: $t5 := read_ref($t4) | ||
5: return $t5 | ||
} |
23 changes: 23 additions & 0 deletions
23
language/move-prover/bytecode/tests/read_write_set/copy_struct.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,23 @@ | ||
module 0x1::CopyStruct { | ||
struct S has copy, drop { a: address } | ||
|
||
struct G has key { f: u64 } | ||
|
||
public fun ret_struct(a: address): S { | ||
S { a } | ||
} | ||
|
||
// returning a copy of S should behave the same as returning S | ||
public fun ret_struct_copy(a: address): S { | ||
let s = S { a }; | ||
*&s | ||
} | ||
|
||
public fun g() acquires G { | ||
let s1 = ret_struct_copy(@0x7); | ||
borrow_global_mut<G>(s1.a).f = 1; | ||
|
||
let s2 = ret_struct(@0x7); | ||
borrow_global_mut<G>(s2.a).f = 2; | ||
} | ||
} |
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