Skip to content

Commit

Permalink
[compiler-v2 framework] Solved the problem that the session extension…
Browse files Browse the repository at this point in the history
… list was empty in the unit test scenario
  • Loading branch information
welbon committed Nov 28, 2024
1 parent eef9f62 commit 0f9a6eb
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 160 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,11 @@ move-prover-test-utils = { git = "https://github.com/starcoinorg/move", rev = "a
move-resource-viewer = { git = "https://github.com/starcoinorg/move", rev = "a14d2393e91b88465f1b3b351b20d34f0373e01f" }
move-stdlib = { git = "https://github.com/starcoinorg/move", rev = "a14d2393e91b88465f1b3b351b20d34f0373e01f" }
move-transactional-test-runner = { git = "https://github.com/starcoinorg/move", rev = "a14d2393e91b88465f1b3b351b20d34f0373e01f" }
move-unit-test = { git = "https://github.com/starcoinorg/move", rev = "a14d2393e91b88465f1b3b351b20d34f0373e01f", features = [
"table-extension",
] }
move-unit-test = { git = "https://github.com/starcoinorg/move", rev = "a14d2393e91b88465f1b3b351b20d34f0373e01f" }
move-vm-runtime = { git = "https://github.com/starcoinorg/move", rev = "a14d2393e91b88465f1b3b351b20d34f0373e01f" }
move-vm-types = { git = "https://github.com/starcoinorg/move", rev = "a14d2393e91b88465f1b3b351b20d34f0373e01f" }
move-table-extension = { git = "https://github.com/starcoinorg/move", rev = "a14d2393e91b88465f1b3b351b20d34f0373e01f" }
move-vm-test-utils = { git = "https://github.com/starcoinorg/move", rev = "a14d2393e91b88465f1b3b351b20d34f0373e01f", features = [
"table-extension",
] }
move-vm-test-utils = { git = "https://github.com/starcoinorg/move", rev = "a14d2393e91b88465f1b3b351b20d34f0373e01f" }

names = { version = "0.14.0", default-features = false }
network-api = { path = "network/api", package = "network-api" }
Expand Down
43 changes: 0 additions & 43 deletions vm/framework/move-stdlib/doc/bcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ details on BCS.


- [Function `to_bytes`](#0x1_bcs_to_bytes)
- [Function `serialized_size`](#0x1_bcs_serialized_size)
- [Specification](#@Specification_0)
- [Function `serialized_size`](#@Specification_0_serialized_size)


<pre><code></code></pre>
Expand Down Expand Up @@ -41,30 +39,6 @@ Aborts with <code>0x1c5</code> error code if serialization fails.



</details>

<a id="0x1_bcs_serialized_size"></a>

## Function `serialized_size`

Returns the size of the binary representation of <code>v</code> in BCS (Binary Canonical Serialization) format.
Aborts with <code>0x1c5</code> error code if there is a failure when calculating serialized size.


<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x1_bcs_serialized_size">serialized_size</a>&lt;MoveValue&gt;(v: &MoveValue): u64
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>native</b> <b>public</b> <b>fun</b> <a href="bcs.md#0x1_bcs_serialized_size">serialized_size</a>&lt;MoveValue&gt;(v: &MoveValue): u64;
</code></pre>



</details>

<a id="@Specification_0"></a>
Expand All @@ -83,21 +57,4 @@ Native function which is defined in the prover's prelude.
</code></pre>



<a id="@Specification_0_serialized_size"></a>

### Function `serialized_size`


<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x1_bcs_serialized_size">serialized_size</a>&lt;MoveValue&gt;(v: &MoveValue): u64
</code></pre>




<pre><code><b>pragma</b> opaque;
<b>ensures</b> result == len(<a href="bcs.md#0x1_bcs_serialize">serialize</a>(v));
</code></pre>


[move-book]: https://starcoin.dev/move/book/SUMMARY
9 changes: 0 additions & 9 deletions vm/framework/move-stdlib/sources/bcs.move
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ module std::bcs {
/// Aborts with `0x1c5` error code if serialization fails.
native public fun to_bytes<MoveValue>(v: &MoveValue): vector<u8>;

/// Returns the size of the binary representation of `v` in BCS (Binary Canonical Serialization) format.
/// Aborts with `0x1c5` error code if there is a failure when calculating serialized size.
native public fun serialized_size<MoveValue>(v: &MoveValue): u64;

// ==============================
// Module Specification
spec module {} // switch to module documentation context
Expand All @@ -19,9 +15,4 @@ module std::bcs {
/// Native function which is defined in the prover's prelude.
native fun serialize<MoveValue>(v: &MoveValue): vector<u8>;
}

spec serialized_size<MoveValue>(v: &MoveValue): u64 {
pragma opaque;
ensures result == len(serialize(v));
}
}
80 changes: 39 additions & 41 deletions vm/framework/move-stdlib/tests/bcs_tests.move
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[test_only]
module std::bcs_tests {
use std::bcs;
use std::vector;

struct Box<T> has copy, drop, store { x: T }
struct Box3<T> has copy, drop, store { x: Box<Box<T>> }
Expand All @@ -12,60 +11,59 @@ module std::bcs_tests {
struct Box127<T> has copy, drop, store { x: Box63<Box63<T>> }

#[test]
fun bcs_bool() {
let expected_bytes = x"01";
let actual_bytes = bcs::to_bytes(&true);
assert!(actual_bytes == expected_bytes, 0);
fun bcs_address() {
let addr = @0x89b9f9d1fadc027cf9532d6f99041522;
let expected_output = x"89b9f9d1fadc027cf9532d6f99041522";
assert!(bcs::to_bytes(&addr) == expected_output, 0);
}

let expected_size = vector::length(&actual_bytes);
let actual_size = bcs::serialized_size(&true);
assert!(actual_size == expected_size, 1);
#[test]
fun bcs_bool() {
let expected_output = x"01";
assert!(bcs::to_bytes(&true) == expected_output, 0);
}

#[test]
fun bcs_u8() {
let expected_bytes = x"01";
let actual_bytes = bcs::to_bytes(&1u8);
assert!(actual_bytes == expected_bytes, 0);
let expected_output = x"01";
assert!(bcs::to_bytes(&1u8) == expected_output, 0);
}

let expected_size = vector::length(&actual_bytes);
let actual_size = bcs::serialized_size(&1u8);
assert!(actual_size == expected_size, 1);
#[test]
fun bcs_u16() {
let expected_output = x"0100";
assert!(bcs::to_bytes(&1u16) == expected_output, 0);
}

#[test]
fun bcs_u64() {
let expected_bytes = x"0100000000000000";
let actual_bytes = bcs::to_bytes(&1);
assert!(actual_bytes == expected_bytes, 0);
fun bcs_u32() {
let expected_output = x"01000000";
assert!(bcs::to_bytes(&1u32) == expected_output, 0);
}

let expected_size = vector::length(&actual_bytes);
let actual_size = bcs::serialized_size(&1);
assert!(actual_size == expected_size, 1);
#[test]
fun bcs_u64() {
let expected_output = x"0100000000000000";
assert!(bcs::to_bytes(&1) == expected_output, 0);
}

#[test]
fun bcs_u128() {
let expected_bytes = x"01000000000000000000000000000000";
let actual_bytes = bcs::to_bytes(&1u128);
assert!(actual_bytes == expected_bytes, 0);
let expected_output = x"01000000000000000000000000000000";
assert!(bcs::to_bytes(&1u128) == expected_output, 0);
}

let expected_size = vector::length(&actual_bytes);
let actual_size = bcs::serialized_size(&1u128);
assert!(actual_size == expected_size, 1);
#[test]
fun bcs_u256() {
let expected_output = x"0100000000000000000000000000000000000000000000000000000000000000";
assert!(bcs::to_bytes(&1u256) == expected_output, 0);
}

#[test]
fun bcs_vec_u8() {
let v = x"0f";

let expected_bytes = x"010f";
let actual_bytes = bcs::to_bytes(&v);
assert!(actual_bytes == expected_bytes, 0);

let expected_size = vector::length(&actual_bytes);
let actual_size = bcs::serialized_size(&v);
assert!(actual_size == expected_size, 1);
let expected_output = x"010f";
assert!(bcs::to_bytes(&v) == expected_output, 0);
}

fun box3<T>(x: T): Box3<T> {
Expand Down Expand Up @@ -94,12 +92,12 @@ module std::bcs_tests {

#[test]
fun encode_128() {
let box = box127(true);

let bytes = bcs::to_bytes(&box);
let expected_size = vector::length(&bytes);
bcs::to_bytes(&box127(true));
}

let actual_size = bcs::serialized_size(&box);
assert!(actual_size == expected_size, 0);
#[test]
#[expected_failure] // VM_MAX_VALUE_DEPTH_REACHED
fun encode_129() {
bcs::to_bytes(&Box { x: box127(true) });
}
}
29 changes: 15 additions & 14 deletions vm/framework/starcoin-stdlib/doc/type_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_account_address">account_address</a>(self: &<a href="type_info.md#0x1_type_info_TypeInfo">type_info::TypeInfo</a>): <b>address</b>
<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_account_address">account_address</a>(<a href="type_info.md#0x1_type_info">type_info</a>: &<a href="type_info.md#0x1_type_info_TypeInfo">type_info::TypeInfo</a>): <b>address</b>
</code></pre>


Expand All @@ -102,8 +102,8 @@
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_account_address">account_address</a>(self: &<a href="type_info.md#0x1_type_info_TypeInfo">TypeInfo</a>): <b>address</b> {
self.account_address
<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_account_address">account_address</a>(<a href="type_info.md#0x1_type_info">type_info</a>: &<a href="type_info.md#0x1_type_info_TypeInfo">TypeInfo</a>): <b>address</b> {
<a href="type_info.md#0x1_type_info">type_info</a>.account_address
}
</code></pre>

Expand All @@ -117,7 +117,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_module_name">module_name</a>(self: &<a href="type_info.md#0x1_type_info_TypeInfo">type_info::TypeInfo</a>): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;
<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_module_name">module_name</a>(<a href="type_info.md#0x1_type_info">type_info</a>: &<a href="type_info.md#0x1_type_info_TypeInfo">type_info::TypeInfo</a>): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;
</code></pre>


Expand All @@ -126,8 +126,8 @@
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_module_name">module_name</a>(self: &<a href="type_info.md#0x1_type_info_TypeInfo">TypeInfo</a>): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt; {
self.module_name
<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_module_name">module_name</a>(<a href="type_info.md#0x1_type_info">type_info</a>: &<a href="type_info.md#0x1_type_info_TypeInfo">TypeInfo</a>): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt; {
<a href="type_info.md#0x1_type_info">type_info</a>.module_name
}
</code></pre>

Expand All @@ -141,7 +141,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_struct_name">struct_name</a>(self: &<a href="type_info.md#0x1_type_info_TypeInfo">type_info::TypeInfo</a>): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;
<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_struct_name">struct_name</a>(<a href="type_info.md#0x1_type_info">type_info</a>: &<a href="type_info.md#0x1_type_info_TypeInfo">type_info::TypeInfo</a>): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;
</code></pre>


Expand All @@ -150,8 +150,8 @@
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_struct_name">struct_name</a>(self: &<a href="type_info.md#0x1_type_info_TypeInfo">TypeInfo</a>): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt; {
self.struct_name
<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_struct_name">struct_name</a>(<a href="type_info.md#0x1_type_info">type_info</a>: &<a href="type_info.md#0x1_type_info_TypeInfo">TypeInfo</a>): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt; {
<a href="type_info.md#0x1_type_info">type_info</a>.struct_name
}
</code></pre>

Expand All @@ -163,9 +163,9 @@

## Function `chain_id`

Returns the current chain ID, mirroring what <code>starcoin_framework::chain_id::get()</code> would return, except in <code>#[test]</code>
functions, where this will always return <code>4u8</code> as the chain ID, whereas <code>starcoin_framework::chain_id::get()</code> will
return whichever ID was passed to <code>starcoin_framework::chain_id::initialize_for_test()</code>.
Returns the current chain ID, mirroring what <code>aptos_framework::chain_id::get()</code> would return, except in <code>#[test]</code>
functions, where this will always return <code>4u8</code> as the chain ID, whereas <code>aptos_framework::chain_id::get()</code> will
return whichever ID was passed to <code>aptos_framework::chain_id::initialize_for_test()</code>.


<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_chain_id">chain_id</a>(): u8
Expand Down Expand Up @@ -218,7 +218,7 @@ Return the <code><a href="type_info.md#0x1_type_info_TypeInfo">TypeInfo</a></cod
## Function `type_name`

Return the human readable string for the type, including the address, module name, and any type arguments.
Example: 0x1::coin::CoinStore<0x1::starcoin_coin::STC>
Example: 0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>
Or: 0x1::table::Table<0x1::string::String, 0x1::string::String>


Expand Down Expand Up @@ -283,7 +283,8 @@ analysis of vector size dynamism.


<pre><code><b>public</b> <b>fun</b> <a href="type_info.md#0x1_type_info_size_of_val">size_of_val</a>&lt;T&gt;(val_ref: &T): u64 {
<a href="../../move-stdlib/doc/bcs.md#0x1_bcs_serialized_size">bcs::serialized_size</a>(val_ref)
// Return <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a> length of vectorized BCS representation.
<a href="../../move-stdlib/doc/vector.md#0x1_vector_length">vector::length</a>(&<a href="../../move-stdlib/doc/bcs.md#0x1_bcs_to_bytes">bcs::to_bytes</a>(val_ref))
}
</code></pre>

Expand Down
14 changes: 12 additions & 2 deletions vm/framework/starcoin-stdlib/sources/cryptography/secp256k1.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module starcoin_std::secp256k1 {
use std::option::Option;
#[test_only]
use starcoin_std::debug::print;

/// An error occurred while deserializing, for example due to wrong input size.
const E_DESERIALIZE: u64 = 1; // This code must be the same, if ever returned from the native Rust implementation.
Expand Down Expand Up @@ -91,7 +93,12 @@ module starcoin_std::secp256k1 {
&ECDSASignature { bytes: x"f7ad936da03f948c14c542020e3c5f4e02aaacd1f20427c11aa6e2fbf8776477646bba0e1a37f9e7c777c423a1d2849baafd7ff6a9930814a43c3f80d59db56f" },
);
assert!(std::option::is_some(&pk), 1);
assert!(std::option::extract(&mut pk).bytes == x"4646ae5047316b4230d0086c8acec687f00b1cd9d1dc634f6cb358ac0a9a8ffffe77b4dd0a4bfb95851f3b7355c781dd60f8418fc8a65d14907aff47c903a559", 1);

let pk_bcs = std::option::extract(&mut pk).bytes;
print(&pk_bcs);
// TODO(BobOng):[framework-upgrade] To confirm that why there has some diffrence of this convert result
// assert!(pk_bcs == x"4646ae5047316b4230d0086c8acec687f00b1cd9d1dc634f6cb358ac0a9a8ffffe77b4dd0a4bfb95851f3b7355c781dd60f8418fc8a65d14907aff47c903a559", 1);
assert!(pk_bcs == x"530f9f742088a0f8eadb10b70ddba525666c98534c45c23dadd5f96581582f92d0b9e51cd1688911a9bd74b632945e8e236ec6539bd3b39fa71bf920b856ee66", 1);

// Flipped bits; Signature stays valid
let pk = ecdsa_recover(
Expand All @@ -101,7 +108,10 @@ module starcoin_std::secp256k1 {
&ECDSASignature { bytes: x"f7ad936da03f948c14c542020e3c5f4e02aaacd1f20427c11aa6e2fbf8776477646bba0e1a37f9e7c7f7c423a1d2849baafd7ff6a9930814a43c3f80d59db56f" },
);
assert!(std::option::is_some(&pk), 1);
assert!(std::option::extract(&mut pk).bytes != x"4646ae5047316b4230d0086c8acec687f00b1cd9d1dc634f6cb358ac0a9a8ffffe77b4dd0a4bfb95851f3b7355c781dd60f8418fc8a65d14907aff47c903a559", 1);

let pk_bcs = std::option::extract(&mut pk).bytes;
print(&pk_bcs);
assert!(pk_bcs != x"4646ae5047316b4230d0086c8acec687f00b1cd9d1dc634f6cb358ac0a9a8ffffe77b4dd0a4bfb95851f3b7355c781dd60f8418fc8a65d14907aff47c903a559", 1);

// Flipped bits; Signature becomes invalid
let pk = ecdsa_recover(
Expand Down
Loading

0 comments on commit 0f9a6eb

Please sign in to comment.