-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[asset-mapping] split starcoin_proof.move to more files
- Loading branch information
Showing
7 changed files
with
164 additions
and
162 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
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,42 @@ | ||
|
||
<a id="0x1_starcoin_proof_bit"></a> | ||
|
||
# Module `0x1::starcoin_proof_bit` | ||
|
||
|
||
|
||
- [Function `get_bit`](#0x1_starcoin_proof_bit_get_bit) | ||
|
||
|
||
<pre><code></code></pre> | ||
|
||
|
||
|
||
<a id="0x1_starcoin_proof_bit_get_bit"></a> | ||
|
||
## Function `get_bit` | ||
|
||
|
||
|
||
<pre><code><b>public</b> <b>fun</b> <a href="starcoin_proof_bit.md#0x1_starcoin_proof_bit_get_bit">get_bit</a>(data: &<a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8>, index: u64): bool | ||
</code></pre> | ||
|
||
|
||
|
||
<details> | ||
<summary>Implementation</summary> | ||
|
||
|
||
<pre><code><b>public</b> <b>fun</b> <a href="starcoin_proof_bit.md#0x1_starcoin_proof_bit_get_bit">get_bit</a>(data: &<a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8>, index: u64): bool { | ||
<b>let</b> pos = index / 8; | ||
<b>let</b> bit = (7 - index % 8); | ||
(*<a href="../../move-stdlib/doc/vector.md#0x1_vector_borrow">vector::borrow</a>(data, pos) >> (bit <b>as</b> u8)) & 1u8 != 0 | ||
} | ||
</code></pre> | ||
|
||
|
||
|
||
</details> | ||
|
||
|
||
[move-book]: https://starcoin.dev/move/book/SUMMARY |
87 changes: 87 additions & 0 deletions
87
vm/framework/starcoin-framework/doc/starcoin_proof_structured_hash.md
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,87 @@ | ||
|
||
<a id="0x1_starcoin_proof_structured_hash"></a> | ||
|
||
# Module `0x1::starcoin_proof_structured_hash` | ||
|
||
|
||
|
||
- [Constants](#@Constants_0) | ||
- [Function `hash`](#0x1_starcoin_proof_structured_hash_hash) | ||
- [Function `concat`](#0x1_starcoin_proof_structured_hash_concat) | ||
|
||
|
||
<pre><code><b>use</b> <a href="../../move-stdlib/doc/bcs.md#0x1_bcs">0x1::bcs</a>; | ||
<b>use</b> <a href="../../move-stdlib/doc/hash.md#0x1_hash">0x1::hash</a>; | ||
<b>use</b> <a href="../../move-stdlib/doc/vector.md#0x1_vector">0x1::vector</a>; | ||
</code></pre> | ||
|
||
|
||
|
||
<a id="@Constants_0"></a> | ||
|
||
## Constants | ||
|
||
|
||
<a id="0x1_starcoin_proof_structured_hash_STARCOIN_HASH_PREFIX"></a> | ||
|
||
|
||
|
||
<pre><code><b>const</b> <a href="starcoin_proof_structured_hash.md#0x1_starcoin_proof_structured_hash_STARCOIN_HASH_PREFIX">STARCOIN_HASH_PREFIX</a>: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8> = [83, 84, 65, 82, 67, 79, 73, 78, 58, 58]; | ||
</code></pre> | ||
|
||
|
||
|
||
<a id="0x1_starcoin_proof_structured_hash_hash"></a> | ||
|
||
## Function `hash` | ||
|
||
|
||
|
||
<pre><code><b>public</b> <b>fun</b> <a href="../../move-stdlib/doc/hash.md#0x1_hash">hash</a><MoveValue: store>(structure: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8>, data: &MoveValue): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8> | ||
</code></pre> | ||
|
||
|
||
|
||
<details> | ||
<summary>Implementation</summary> | ||
|
||
|
||
<pre><code><b>public</b> <b>fun</b> <a href="../../move-stdlib/doc/hash.md#0x1_hash">hash</a><MoveValue: store>(structure: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8>, data: &MoveValue): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8> { | ||
<b>let</b> prefix_hash = <a href="../../move-stdlib/doc/hash.md#0x1_hash_sha3_256">hash::sha3_256</a>(<a href="starcoin_proof_structured_hash.md#0x1_starcoin_proof_structured_hash_concat">concat</a>(&<a href="starcoin_proof_structured_hash.md#0x1_starcoin_proof_structured_hash_STARCOIN_HASH_PREFIX">STARCOIN_HASH_PREFIX</a>, structure)); | ||
<b>let</b> bcs_bytes = <a href="../../move-stdlib/doc/bcs.md#0x1_bcs_to_bytes">bcs::to_bytes</a>(data); | ||
<a href="../../move-stdlib/doc/hash.md#0x1_hash_sha3_256">hash::sha3_256</a>(<a href="starcoin_proof_structured_hash.md#0x1_starcoin_proof_structured_hash_concat">concat</a>(&prefix_hash, bcs_bytes)) | ||
} | ||
</code></pre> | ||
|
||
|
||
|
||
</details> | ||
|
||
<a id="0x1_starcoin_proof_structured_hash_concat"></a> | ||
|
||
## Function `concat` | ||
|
||
|
||
|
||
<pre><code><b>fun</b> <a href="starcoin_proof_structured_hash.md#0x1_starcoin_proof_structured_hash_concat">concat</a>(v1: &<a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8>, v2: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8>): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8> | ||
</code></pre> | ||
|
||
|
||
|
||
<details> | ||
<summary>Implementation</summary> | ||
|
||
|
||
<pre><code><b>fun</b> <a href="starcoin_proof_structured_hash.md#0x1_starcoin_proof_structured_hash_concat">concat</a>(v1: &<a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8>, v2: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8>): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a><u8> { | ||
<b>let</b> data = *v1; | ||
<a href="../../move-stdlib/doc/vector.md#0x1_vector_append">vector::append</a>(&<b>mut</b> data, v2); | ||
data | ||
} | ||
</code></pre> | ||
|
||
|
||
|
||
</details> | ||
|
||
|
||
[move-book]: https://starcoin.dev/move/book/SUMMARY |
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
9 changes: 9 additions & 0 deletions
9
vm/framework/starcoin-framework/sources/proof/starcoin_proof_bit.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,9 @@ | ||
module starcoin_framework::starcoin_proof_bit { | ||
use std::vector; | ||
|
||
public fun get_bit(data: &vector<u8>, index: u64): bool { | ||
let pos = index / 8; | ||
let bit = (7 - index % 8); | ||
(*vector::borrow(data, pos) >> (bit as u8)) & 1u8 != 0 | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
vm/framework/starcoin-framework/sources/proof/starcoin_proof_structured_hash.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,19 @@ | ||
module starcoin_framework::starcoin_proof_structured_hash { | ||
use std::bcs; | ||
use std::hash; | ||
use std::vector; | ||
|
||
const STARCOIN_HASH_PREFIX: vector<u8> = b"STARCOIN::"; | ||
|
||
public fun hash<MoveValue: store>(structure: vector<u8>, data: &MoveValue): vector<u8> { | ||
let prefix_hash = hash::sha3_256(concat(&STARCOIN_HASH_PREFIX, structure)); | ||
let bcs_bytes = bcs::to_bytes(data); | ||
hash::sha3_256(concat(&prefix_hash, bcs_bytes)) | ||
} | ||
|
||
fun concat(v1: &vector<u8>, v2: vector<u8>): vector<u8> { | ||
let data = *v1; | ||
vector::append(&mut data, v2); | ||
data | ||
} | ||
} |