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

fix dao snapshot deserialize when some option field is empty #82

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: BA57D9321DEFA9F6B6A7EA79596390061013B6D6E468A682CC3EFAD862776F97
source_digest: 909CE74C85980EFA85EC499713FA015307F578F64A8BB1B25942B9F63440DBA4
build_flags:
dev_mode: false
test_mode: false
Expand Down
12 changes: 6 additions & 6 deletions sources/daospace/DAOSpace.move
Original file line number Diff line number Diff line change
Expand Up @@ -1389,18 +1389,18 @@ module StarcoinFramework::DAOSpace {
let (account_state_option, offset) = BCS::deserialize_option_bytes(snpashot_raw_proofs, offset);

let (account_proof_leaf1_option, account_proof_leaf2_option, offset) = BCS::deserialize_option_tuple(snpashot_raw_proofs, offset);
let account_proof_leaf1 = Option::extract(&mut account_proof_leaf1_option);
let account_proof_leaf2 = Option::extract(&mut account_proof_leaf2_option);
let account_proof_leaf1 = Option::get_with_default(&mut account_proof_leaf1_option, Vector::empty());
let account_proof_leaf2 = Option::get_with_default(&mut account_proof_leaf2_option, Vector::empty());
let (account_proof_siblings, offset) = BCS::deserialize_bytes_vector(snpashot_raw_proofs, offset);

let (account_state_proof_leaf1_option, account_state_proof_leaf2_option, offset) = BCS::deserialize_option_tuple(snpashot_raw_proofs, offset);
let account_state_proof_leaf1 = Option::extract(&mut account_state_proof_leaf1_option);
let account_state_proof_leaf2 = Option::extract(&mut account_state_proof_leaf2_option);
let account_state_proof_leaf1 = Option::get_with_default(&mut account_state_proof_leaf1_option, Vector::empty());
let account_state_proof_leaf2 = Option::get_with_default(&mut account_state_proof_leaf2_option, Vector::empty());
let (account_state_proof_siblings, _offset) = BCS::deserialize_bytes_vector(snpashot_raw_proofs, offset);

SnapshotProof {
state: Option::extract(&mut state_option),
account_state: Option::extract(&mut account_state_option),
state: Option::get_with_default(&mut state_option, Vector::empty()),
account_state: Option::get_with_default(&mut account_state_option, Vector::empty()),
account_proof_leaf: HashNode {
hash1: account_proof_leaf1,
hash2: account_proof_leaf2,
Expand Down
26 changes: 19 additions & 7 deletions sources/daospace/SnapshotUtil.move
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ module StarcoinFramework::SnapshotUtil{

let offset = 0;
let (state_option, offset) = BCS::deserialize_option_bytes(&snpashot_raw_proofs, offset);
let state = Option::extract(&mut state_option);
let state = Option::get_with_default(&mut state_option, Vector::empty());
Debug::print(&state);
Debug::print(&x"016bfb460477adf9dd0455d3de2fc7f21101000000000000000664616f313031000a69616d67655f6461746100570400000000000064000000000000000000000000000000");
// Debug::print(&x"016bfb460477adf9dd0455d3de2fc7f21101000000000000000664616f313031000a69616d67655f6461746100570400000000000064000000000000000000000000000000");
Debug::print(&offset);
let (_account_state_option, offset) = BCS::deserialize_option_bytes(&snpashot_raw_proofs, offset);
let _account_state = Option::extract(&mut _account_state_option);
let _account_state = Option::get_with_default(&mut _account_state_option, Vector::empty());
Debug::print(&110110);
Debug::print(&_account_state);
Debug::print(&offset);

let (_account_proof_leaf1_option, _account_proof_leaf2_option, offset) = BCS::deserialize_option_tuple(&snpashot_raw_proofs, offset);
let _account_proof_leaf1 = Option::extract(&mut _account_proof_leaf1_option);
let _account_proof_leaf2 = Option::extract(&mut _account_proof_leaf2_option);
let _account_proof_leaf1 = Option::get_with_default(&mut _account_proof_leaf1_option, Vector::empty());
let _account_proof_leaf2 = Option::get_with_default(&mut _account_proof_leaf2_option, Vector::empty());
Debug::print(&offset);

let account_proof_leaf_nodes = Vector::empty<vector<u8>>();
Expand All @@ -43,8 +43,8 @@ module StarcoinFramework::SnapshotUtil{
let (_account_proof_siblings, offset) = BCS::deserialize_bytes_vector(&snpashot_raw_proofs, offset);

let (_account_state_proof_leaf1_option, _account_state_proof_leaf2_option, offset) = BCS::deserialize_option_tuple(&snpashot_raw_proofs, offset);
let _account_state_proof_leaf1 = Option::extract(&mut _account_state_proof_leaf1_option);
let _account_state_proof_leaf2 = Option::extract(&mut _account_state_proof_leaf2_option);
let _account_state_proof_leaf1 = Option::get_with_default(&mut _account_state_proof_leaf1_option, Vector::empty());
let _account_state_proof_leaf2 = Option::get_with_default(&mut _account_state_proof_leaf2_option, Vector::empty());
Debug::print(&_account_state_proof_leaf1);
Debug::print(&_account_state_proof_leaf2);
let (_account_state_proof_siblings, _offset) = BCS::deserialize_bytes_vector(&snpashot_raw_proofs, offset);
Expand All @@ -53,6 +53,18 @@ module StarcoinFramework::SnapshotUtil{
Debug::print(&_offset);
}

#[test]
fun test_snapshot_proof_deserialize_with_empty_state() {
let snpashot_raw_proofs = x"00012402000120161d07d221d7b31df7d29d45926b6444fa07e8b5f1021dd704fc1def6738011d0120e76e5b4bcf07c7e3864b399cfca72b0863678487813a1cfe8df48cf35729def820f135bf4b03034b8a3c21950231d3c4fe8136442064c9809d593e78ed4775f0b6042072659a01138c59e84e8e608e0d1908be7289c47f8f4080a14eaa852d1ace35f420bb3f0cc0cde2e05ba56a26bbc15161a930af6f66a65091b285870c557e8bc07a205350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000204bb30b63b4c41126a2f8c98a3d66f351160732481ae633da47d647976004942e000420fbd31ef1cbaf26c37259325e5ee71625e67f7ecf8311cbf67758431d65ae8f5c205350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000207460a35efdba40ce6ec4442b32e0bf39fee59a69887e18f118f49b325434fda820417ddaf2cf3fce9b50dd9b16e1ea545d65d480b855bfd0aed0a819a6a7d0f641";

let offset = 0;
let (state_option, offset) = BCS::deserialize_option_bytes(&snpashot_raw_proofs, offset);
Debug::print(&state_option);
let state = Option::get_with_default(&mut state_option, Vector::empty());
Debug::print(&state);
Debug::print(&offset);
}

/// Struct Tag which identify a unique Struct.
struct StructTag0 has drop,copy,store {
addr: address,
Expand Down