diff --git a/vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs b/vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs index 4870aa89b0..057bf9b81d 100644 --- a/vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs +++ b/vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs @@ -153,7 +153,8 @@ pub enum EntryFunctionCall { AssetMappingAssignToAccountWithProof { receiper: AccountAddress, old_token_str: Vec, - proof_path: Vec, + proof_path_hash: Vec, + proof_value_hash: Vec, proof_siblings: Vec, amount: u64, }, @@ -654,13 +655,15 @@ impl EntryFunctionCall { AssetMappingAssignToAccountWithProof { receiper, old_token_str, - proof_path, + proof_path_hash, + proof_value_hash, proof_siblings, amount, } => asset_mapping_assign_to_account_with_proof( receiper, old_token_str, - proof_path, + proof_path_hash, + proof_value_hash, proof_siblings, amount, ), @@ -1281,7 +1284,8 @@ pub fn account_rotate_authentication_key_with_rotation_capability( pub fn asset_mapping_assign_to_account_with_proof( receiper: AccountAddress, old_token_str: Vec, - proof_path: Vec, + proof_path_hash: Vec, + proof_value_hash: Vec, proof_siblings: Vec, amount: u64, ) -> TransactionPayload { @@ -1295,7 +1299,8 @@ pub fn asset_mapping_assign_to_account_with_proof( vec![ bcs::to_bytes(&receiper).unwrap(), bcs::to_bytes(&old_token_str).unwrap(), - bcs::to_bytes(&proof_path).unwrap(), + bcs::to_bytes(&proof_path_hash).unwrap(), + bcs::to_bytes(&proof_value_hash).unwrap(), bcs::to_bytes(&proof_siblings).unwrap(), bcs::to_bytes(&amount).unwrap(), ], @@ -2578,9 +2583,10 @@ mod decoder { Some(EntryFunctionCall::AssetMappingAssignToAccountWithProof { receiper: bcs::from_bytes(script.args().get(0)?).ok()?, old_token_str: bcs::from_bytes(script.args().get(1)?).ok()?, - proof_path: bcs::from_bytes(script.args().get(2)?).ok()?, - proof_siblings: bcs::from_bytes(script.args().get(3)?).ok()?, - amount: bcs::from_bytes(script.args().get(4)?).ok()?, + proof_path_hash: bcs::from_bytes(script.args().get(2)?).ok()?, + proof_value_hash: bcs::from_bytes(script.args().get(3)?).ok()?, + proof_siblings: bcs::from_bytes(script.args().get(4)?).ok()?, + amount: bcs::from_bytes(script.args().get(5)?).ok()?, }) } else { None diff --git a/vm/framework/starcoin-framework/doc/asset_mapping.md b/vm/framework/starcoin-framework/doc/asset_mapping.md index eb7855fe8c..fb0ec67b38 100644 --- a/vm/framework/starcoin-framework/doc/asset_mapping.md +++ b/vm/framework/starcoin-framework/doc/asset_mapping.md @@ -24,12 +24,10 @@ with proof verification. - [Function `calculation_proof`](#0x1_asset_mapping_calculation_proof) -
use 0x1::bcs;
-use 0x1::coin;
+
use 0x1::coin;
 use 0x1::debug;
 use 0x1::error;
 use 0x1::fungible_asset;
-use 0x1::hash;
 use 0x1::object;
 use 0x1::primary_fungible_store;
 use 0x1::signer;
@@ -369,7 +367,7 @@ Retrieves the balance for a specific token type
 
 
 
-
public entry fun assign_to_account_with_proof(token_issuer: &signer, receiper: address, old_token_str: vector<u8>, proof_path: vector<u8>, proof_siblings: vector<u8>, amount: u64)
+
public entry fun assign_to_account_with_proof(token_issuer: &signer, receiper: address, old_token_str: vector<u8>, proof_path_hash: vector<u8>, proof_value_hash: vector<u8>, proof_siblings: vector<u8>, amount: u64)
 
@@ -382,7 +380,8 @@ Retrieves the balance for a specific token type token_issuer: &signer, receiper: address, old_token_str: vector<u8>, - proof_path: vector<u8>, + proof_path_hash: vector<u8>, + proof_value_hash: vector<u8>, proof_siblings: vector<u8>, amount: u64 ) acquires AssetMappingPool, AssetMappingCoinType, AssetMappingProof { @@ -393,7 +392,7 @@ Retrieves the balance for a specific token type // Verify that the token type of the request mapping is the passed-in verification type assert!( - calculation_proof(proof_path, amount, split_proof_siblings_from_vec(proof_siblings)), + calculation_proof(proof_path_hash, proof_value_hash, split_proof_siblings_from_vec(proof_siblings)), error::unauthenticated(EINVALID_NOT_PROOF) ); @@ -486,7 +485,7 @@ Requirements: Computes and verifies the provided proof -
fun calculation_proof(proof_path_hash: vector<u8>, amount: u64, proof_siblings: vector<vector<u8>>): bool
+
fun calculation_proof(proof_path_hash: vector<u8>, blob_hash: vector<u8>, proof_siblings: vector<vector<u8>>): bool
 
@@ -497,14 +496,14 @@ Computes and verifies the provided proof
fun calculation_proof(
     proof_path_hash: vector<u8>,
-    amount: u64,
+    blob_hash: vector<u8>,
     proof_siblings: vector<vector<u8>>
 ): bool acquires AssetMappingProof {
     let expect_proof_root =
         borrow_global_mut<AssetMappingProof>(system_addresses::get_starcoin_framework()).proof_root;
     let actual_root = starcoin_proof_verifier::computer_root_hash(
         proof_path_hash,
-        hash::sha3_256(bcs::to_bytes(&amount)),
+        blob_hash,
         proof_siblings
     );
     expect_proof_root == actual_root
diff --git a/vm/framework/starcoin-framework/doc/starcoin_proof.md b/vm/framework/starcoin-framework/doc/starcoin_proof.md
index bd417ec870..7b786843e3 100644
--- a/vm/framework/starcoin-framework/doc/starcoin_proof.md
+++ b/vm/framework/starcoin-framework/doc/starcoin_proof.md
@@ -12,11 +12,14 @@
 -  [Function `verify_on`](#0x1_starcoin_proof_verifier_verify_on)
 -  [Function `verify`](#0x1_starcoin_proof_verifier_verify)
 -  [Function `computer_root_hash`](#0x1_starcoin_proof_verifier_computer_root_hash)
+-  [Function `splite_symbol`](#0x1_starcoin_proof_verifier_splite_symbol)
+-  [Function `split`](#0x1_starcoin_proof_verifier_split)
 
 
 
use 0x1::hash;
 use 0x1::starcoin_proof_bit;
 use 0x1::starcoin_proof_structured_hash;
+use 0x1::vector;
 
@@ -86,6 +89,15 @@ ## Constants + + + + +
const DELMITER: u8 = 124;
+
+ + + @@ -241,6 +253,75 @@ + + + + +## Function `splite_symbol` + + + +
public fun splite_symbol(): u8
+
+ + + +
+Implementation + + +
public fun splite_symbol(): u8 {
+    DELMITER
+}
+
+ + + +
+ + + +## Function `split` + + + +
public fun split(input: vector<u8>): vector<vector<u8>>
+
+ + + +
+Implementation + + +
public fun split(input: vector<u8>): vector<vector<u8>> {
+    let result: vector<vector<u8>> = vector::empty();
+    let current_segment = vector::empty<u8>();
+    let i = 0;
+    let len = vector::length(&input);
+
+    while (i < len) {
+        let current_byte = *vector::borrow(&input, i);
+        if (current_byte == DELMITER) {
+            if (!vector::is_empty(¤t_segment)) {
+                vector::push_back(&mut result, current_segment);
+                current_segment = vector::empty();
+            };
+        } else {
+            vector::push_back(&mut current_segment, current_byte);
+        };
+        i = i + 1;
+    };
+
+    if (!vector::is_empty(¤t_segment)) {
+        vector::push_back(&mut result, current_segment);
+    };
+    result
+}
+
+ + +
diff --git a/vm/framework/starcoin-framework/sources/asset_mapping.move b/vm/framework/starcoin-framework/sources/asset_mapping.move index 43302c4a8e..2ffa35260f 100644 --- a/vm/framework/starcoin-framework/sources/asset_mapping.move +++ b/vm/framework/starcoin-framework/sources/asset_mapping.move @@ -4,9 +4,7 @@ /// with proof verification. module starcoin_framework::asset_mapping { - use std::bcs; use std::error; - use std::hash; use std::signer; use std::string; use std::vector; @@ -26,6 +24,8 @@ module starcoin_framework::asset_mapping { #[test_only] use starcoin_framework::starcoin_coin::{Self, STC}; #[test_only] + use starcoin_framework::starcoin_proof_verifier::splite_symbol; + #[test_only] use starcoin_std::type_info; /// AssetMappingStore represents a store for mapped assets @@ -274,15 +274,32 @@ module starcoin_framework::asset_mapping { #[test(framework= @starcoin_framework)] fun test_asset_mapping_calculation_proof(framework: &signer) acquires AssetMappingProof { - let siblings = vector::empty>(); - vector::push_back(&mut siblings, x"cfb1462d4fc72f736eab2a56b2bf72ca6ad1c4e8c79557046a8b0adce047f007"); - vector::push_back(&mut siblings, x"5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000"); - vector::push_back(&mut siblings, x"5ca9febe74c7fde3fdcf2bd464de6d8899a0a13d464893aada2714c6fa774f9d"); - vector::push_back(&mut siblings, x"1519a398fed69687cabf51adf831f0ee1650aaf79775d00135fc70f55a73e151"); - vector::push_back(&mut siblings, x"50ce5c38983ba2eb196acd44e0aaedf040b1437ad1106e05ca452d7e27e4e03f"); - vector::push_back(&mut siblings, x"55ed28435637a061a6dd9e20b72849199cd36184570f976b7e306a27bebf2fdf"); - vector::push_back(&mut siblings, x"0dc23e31614798a6f67659b0b808b3eadc3b13a2a7bc03580a9e3004e45c2e6c"); - vector::push_back(&mut siblings, x"83bed048bc0bc452c98cb0e9f1cc0f691919eaf756864fc44940c2d1e01da92a"); + let siblings_data = vector::empty(); + vector::append(&mut siblings_data, x"cfb1462d4fc72f736eab2a56b2bf72ca6ad1c4e8c79557046a8b0adce047f007"); + vector::push_back(&mut siblings_data, splite_symbol()); + + vector::append(&mut siblings_data, x"5350415253455f4d45524b4c455f504c414345484f4c4445525f484153480000"); + vector::push_back(&mut siblings_data, splite_symbol()); + + vector::append(&mut siblings_data, x"5ca9febe74c7fde3fdcf2bd464de6d8899a0a13d464893aada2714c6fa774f9d"); + vector::push_back(&mut siblings_data, splite_symbol()); + + vector::append(&mut siblings_data, x"1519a398fed69687cabf51adf831f0ee1650aaf79775d00135fc70f55a73e151"); + vector::push_back(&mut siblings_data, splite_symbol()); + + vector::append(&mut siblings_data, x"50ce5c38983ba2eb196acd44e0aaedf040b1437ad1106e05ca452d7e27e4e03f"); + vector::push_back(&mut siblings_data, splite_symbol()); + + vector::append(&mut siblings_data, x"55ed28435637a061a6dd9e20b72849199cd36184570f976b7e306a27bebf2fdf"); + vector::push_back(&mut siblings_data, splite_symbol()); + + vector::append(&mut siblings_data, x"0dc23e31614798a6f67659b0b808b3eadc3b13a2a7bc03580a9e3004e45c2e6c"); + vector::push_back(&mut siblings_data, splite_symbol()); + + vector::append(&mut siblings_data, x"83bed048bc0bc452c98cb0e9f1cc0f691919eaf756864fc44940c2d1e01da92a"); + vector::push_back(&mut siblings_data, splite_symbol()); + + let siblings = starcoin_proof_verifier::split(siblings_data); let element_key = x"4cc8bd9df94b37c233555d9a3bba0a712c3c709f047486d1e624b2bcd3b83266"; Self::initialize(framework, x"f65860f575bf2a198c069adb4e7872037e3a329b63ef617e40afa39b87b067c8"); @@ -316,5 +333,4 @@ module starcoin_framework::asset_mapping { ); debug::print(&std::string::utf8(b"asset_mapping::test_asset_mapping_coin_type_verify | exited")); } - } diff --git a/vm/framework/starcoin-framework/sources/proof/starcoin_proof.move b/vm/framework/starcoin-framework/sources/proof/starcoin_proof.move index f30c64f5db..2a1cfc1ccc 100644 --- a/vm/framework/starcoin-framework/sources/proof/starcoin_proof.move +++ b/vm/framework/starcoin-framework/sources/proof/starcoin_proof.move @@ -68,6 +68,39 @@ module starcoin_framework::starcoin_proof_verifier { current_hash } + + // ASCII for '|' + const DELMITER: u8 = 124; + + public fun splite_symbol(): u8 { + DELMITER + } + + public fun split(input: vector): vector> { + let result: vector> = vector::empty(); + let current_segment = vector::empty(); + let i = 0; + let len = vector::length(&input); + + while (i < len) { + let current_byte = *vector::borrow(&input, i); + if (current_byte == DELMITER) { + if (!vector::is_empty(¤t_segment)) { + vector::push_back(&mut result, current_segment); + current_segment = vector::empty(); + }; + } else { + vector::push_back(&mut current_segment, current_byte); + }; + i = i + 1; + }; + + if (!vector::is_empty(¤t_segment)) { + vector::push_back(&mut result, current_segment); + }; + result + } + #[test] public fun test_starcoin_proof_verify_is_expect_root() { let siblings = vector::empty>(); @@ -89,6 +122,29 @@ module starcoin_framework::starcoin_proof_verifier { ); assert!(actual_root_hash == expect_root_hash, 1000); } + + #[test] + public fun test_starcoin_proof_split() { + // Test case 1: Normal split + let input1 = b"hello|world|test"; + let result1 = split(input1); + assert!(vector::length(&result1) == 3, 10010); + + // Test case 2: Empty segments + let input2 = b"||test||"; + let result2 = split(input2); + assert!(vector::length(&result2) == 1, 10011); + + // Test case 3: Single segment + let input3 = b"hello"; + let result3 = split(input3); + assert!(vector::length(&result3) == 1, 10012); + + // Test case 4: Empty input + let input4 = b""; + let result4 = split(input4); + assert!(vector::length(&result4) == 0, 10013); + } }