Skip to content

Commit

Permalink
github test
Browse files Browse the repository at this point in the history
  • Loading branch information
so-kkroy22 committed May 4, 2024
1 parent 696169a commit f457172
Show file tree
Hide file tree
Showing 69 changed files with 253 additions and 5,028 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/move.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Move

on:
push:
branches: [ ]
pull_request:
branches: [ ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest
22 changes: 22 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Rust

on:
push:
branches: [ ]
pull_request:
branches: [ ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
1 change: 0 additions & 1 deletion aptos-move/framework/aptos-framework/doc/genesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,6 @@ encoded in a single BCS byte array.
operator,
pool_address,
validator.consensus_pubkey,
validator.proof_of_possession,
);
<a href="stake.md#0x1_stake_update_network_and_fullnode_addresses">stake::update_network_and_fullnode_addresses</a>(
operator,
Expand Down
69 changes: 16 additions & 53 deletions aptos-move/framework/aptos-framework/doc/stake.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion aptos-move/framework/aptos-framework/sources/genesis.move
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ module aptos_framework::genesis {
operator,
pool_address,
validator.consensus_pubkey,
validator.proof_of_possession,
);
stake::update_network_and_fullnode_addresses(
operator,
Expand Down
60 changes: 17 additions & 43 deletions aptos-move/framework/aptos-framework/sources/stake.move
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module aptos_framework::stake {
use std::option::{Self, Option};
use std::signer;
use std::vector;
use aptos_std::bls12381;
use aptos_std::ed25519;
use aptos_std::math64::min;
use aptos_std::table::{Self, Table};
use aptos_framework::aptos_coin::AptosCoin;
Expand Down Expand Up @@ -494,17 +494,10 @@ module aptos_framework::stake {
public entry fun initialize_validator(
account: &signer,
consensus_pubkey: vector<u8>,
proof_of_possession: vector<u8>,
network_addresses: vector<u8>,
fullnode_addresses: vector<u8>,
) acquires AllowedValidators {
// Checks the public key has a valid proof-of-possession to prevent rogue-key attacks.
let pubkey_from_pop = &mut bls12381::public_key_from_bytes_with_pop(
consensus_pubkey,
&proof_of_possession_from_bytes(proof_of_possession)
);
assert!(option::is_some(pubkey_from_pop), error::invalid_argument(EINVALID_PUBLIC_KEY));

initialize_owner(account);
move_to(account, ValidatorConfig {
consensus_pubkey,
Expand Down Expand Up @@ -693,7 +686,6 @@ module aptos_framework::stake {
operator: &signer,
pool_address: address,
new_consensus_pubkey: vector<u8>,
proof_of_possession: vector<u8>,
genesis: bool,
) acquires StakePool, ValidatorConfig {
assert_stake_pool_exists(pool_address);
Expand All @@ -704,16 +696,6 @@ module aptos_framework::stake {
let validator_info = borrow_global_mut<ValidatorConfig>(pool_address);
let old_consensus_pubkey = validator_info.consensus_pubkey;
// Checks the public key has a valid proof-of-possession to prevent rogue-key attacks.
if (!genesis) {
let pubkey_from_pop = &mut bls12381::public_key_from_bytes_with_pop(
new_consensus_pubkey,
&proof_of_possession_from_bytes(proof_of_possession)
);
assert!(option::is_some(pubkey_from_pop), error::invalid_argument(EINVALID_PUBLIC_KEY));
} else {
let pubkey = &mut bls12381::public_key_from_bytes(new_consensus_pubkey);
assert!(option::is_some(pubkey), error::invalid_argument(EINVALID_PUBLIC_KEY));
};
validator_info.consensus_pubkey = new_consensus_pubkey;

event::emit_event(
Expand All @@ -733,19 +715,17 @@ module aptos_framework::stake {
operator: &signer,
pool_address: address,
new_consensus_pubkey: vector<u8>,
proof_of_poseesion: vector<u8>,
) acquires StakePool, ValidatorConfig {
rotate_consensus_key_internal(operator, pool_address, new_consensus_pubkey, proof_of_poseesion, true);
rotate_consensus_key_internal(operator, pool_address, new_consensus_pubkey, true);
}

/// Rotate the consensus key of the validator, it'll take effect in next epoch.
public entry fun rotate_consensus_key(
operator: &signer,
pool_address: address,
new_consensus_pubkey: vector<u8>,
proof_of_possession: vector<u8>,
) acquires StakePool, ValidatorConfig {
rotate_consensus_key_internal(operator, pool_address, new_consensus_pubkey, proof_of_possession, false);
rotate_consensus_key_internal(operator, pool_address, new_consensus_pubkey, false);
}

/// Update the network and full node addresses of the validator. This only takes effect in the next epoch.
Expand Down Expand Up @@ -1388,7 +1368,6 @@ module aptos_framework::stake {

#[test_only]
use aptos_framework::aptos_coin;
use aptos_std::bls12381::proof_of_possession_from_bytes;
#[test_only]
use aptos_std::fixed_point64;

Expand All @@ -1405,15 +1384,13 @@ module aptos_framework::stake {

#[test_only]
public fun join_validator_set_for_test(
pk: &bls12381::PublicKey,
pop: &bls12381::ProofOfPossession,
pk: &ed25519::ValidatedPublicKey,
operator: &signer,
pool_address: address,
should_end_epoch: bool,
) acquires AptosCoinCapabilities, StakePool, ValidatorConfig, ValidatorPerformance, ValidatorSet, ValidatorFees {
let pk_bytes = bls12381::public_key_to_bytes(pk);
let pop_bytes = bls12381::proof_of_possession_to_bytes(pop);
rotate_consensus_key(operator, pool_address, pk_bytes, pop_bytes);
let pk_bytes = ed25519::validated_public_key_to_bytes(pk);
rotate_consensus_key(operator, pool_address, pk_bytes);
join_validator_set(operator, pool_address);
if (should_end_epoch) {
end_epoch();
Expand Down Expand Up @@ -1484,8 +1461,7 @@ module aptos_framework::stake {

#[test_only]
public fun initialize_test_validator(
public_key: &bls12381::PublicKey,
proof_of_possession: &bls12381::ProofOfPossession,
public_key: &ed25519::UnvalidatedPublicKey,
validator: &signer,
amount: u64,
should_join_validator_set: bool,
Expand All @@ -1496,9 +1472,8 @@ module aptos_framework::stake {
account::create_account_for_test(validator_address);
};

let pk_bytes = bls12381::public_key_to_bytes(public_key);
let pop_bytes = bls12381::proof_of_possession_to_bytes(proof_of_possession);
initialize_validator(validator, pk_bytes, pop_bytes, vector::empty(), vector::empty());
let pk_bytes = ed25519::unvalidated_public_key_to_bytes(public_key);
initialize_validator(validator, pk_bytes, vector::empty(), vector::empty());

if (amount > 0) {
mint_and_add_stake(validator, amount);
Expand All @@ -1516,7 +1491,7 @@ module aptos_framework::stake {
public fun create_validator_set(
aptos_framework: &signer,
active_validator_addresses: vector<address>,
public_keys: vector<bls12381::PublicKey>,
public_keys: vector<ed25519::ValidatedPublicKey>,
) {
let active_validators = vector::empty<ValidatorInfo>();
let i = 0;
Expand All @@ -1527,7 +1502,7 @@ module aptos_framework::stake {
addr: *validator_address,
voting_power: 0,
config: ValidatorConfig {
consensus_pubkey: bls12381::public_key_to_bytes(pk),
consensus_pubkey: ed25519::validated_public_key_to_bytes(pk),
network_addresses: b"",
fullnode_addresses: b"",
validator_index: 0,
Expand Down Expand Up @@ -1574,11 +1549,10 @@ module aptos_framework::stake {
}

#[test_only]
public fun generate_identity(): (bls12381::SecretKey, bls12381::PublicKey, bls12381::ProofOfPossession) {
let (sk, pkpop) = bls12381::generate_keys();
let pop = bls12381::generate_proof_of_possession(&sk);
let unvalidated_pk = bls12381::public_key_with_pop_to_normal(&pkpop);
(sk, unvalidated_pk, pop)
public fun generate_identity(): (ed25519::SecretKey, ed25519::UnvalidatedPublicKey) {
let (sk, pkpop) = ed25519::generate_keys();
let unvalidated_pk = ed25519::public_key_to_unvalidated(&pkpop);
(sk, unvalidated_pk)
}

#[test(aptos_framework = @aptos_framework, validator = @0x123)]
Expand All @@ -1588,8 +1562,8 @@ module aptos_framework::stake {
validator: &signer,
) acquires AllowedValidators, AptosCoinCapabilities, OwnerCapability, StakePool, ValidatorConfig, ValidatorPerformance, ValidatorSet, ValidatorFees {
initialize_for_test(aptos_framework);
let (_sk, pk, pop) = generate_identity();
initialize_test_validator(&pk, &pop, validator, 100, false, false);
let (_sk, pk) = generate_identity();
initialize_test_validator(&pk, validator, 100, false, false);

// Add more stake to exceed max. This should fail.
mint_and_add_stake(validator, 9901);
Expand Down
12 changes: 4 additions & 8 deletions aptos-move/framework/aptos-framework/sources/stake.spec.move
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,13 @@ spec aptos_framework::stake {
spec initialize_validator(
account: &signer,
consensus_pubkey: vector<u8>,
proof_of_possession: vector<u8>,
network_addresses: vector<u8>,
fullnode_addresses: vector<u8>,
){
let pubkey_from_pop = bls12381::spec_public_key_from_bytes_with_pop(
let pubkey_from_pop = ed25519::spec_public_key_validate_internal(
consensus_pubkey,
proof_of_possession_from_bytes(proof_of_possession)
);
aborts_if !option::spec_is_some(pubkey_from_pop);
aborts_if !pubkey_from_pop;
let addr = signer::address_of(account);
let post_addr = signer::address_of(account);
let allowed = global<AllowedValidators>(@aptos_framework);
Expand Down Expand Up @@ -357,18 +355,16 @@ spec aptos_framework::stake {
operator: &signer,
pool_address: address,
new_consensus_pubkey: vector<u8>,
proof_of_possession: vector<u8>,
) {
let pre_stake_pool = global<StakePool>(pool_address);
let post validator_info = global<ValidatorConfig>(pool_address);
aborts_if !exists<StakePool>(pool_address);
aborts_if signer::address_of(operator) != pre_stake_pool.operator_address;
aborts_if !exists<ValidatorConfig>(pool_address);
let pubkey_from_pop = bls12381::spec_public_key_from_bytes_with_pop(
let pubkey_from_pop = ed25519::spec_public_key_validate_internal(
new_consensus_pubkey,
proof_of_possession_from_bytes(proof_of_possession)
);
aborts_if !option::spec_is_some(pubkey_from_pop);
aborts_if !pubkey_from_pop;
modifies global<ValidatorConfig>(pool_address);
include StakedValueNochange;

Expand Down
18 changes: 9 additions & 9 deletions aptos-move/framework/aptos-stdlib/doc/ed25519.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,32 +175,32 @@ A purported Ed25519 signature that can be verified via <code>signature_verify_st
## Constants


<a id="0x1_ed25519_PUBLIC_KEY_NUM_BYTES"></a>
<a id="0x1_ed25519_E_WRONG_PUBKEY_SIZE"></a>

The size of a serialized public key, in bytes.
Wrong number of bytes were given as input when deserializing an Ed25519 public key.


<pre><code><b>const</b> <a href="ed25519.md#0x1_ed25519_PUBLIC_KEY_NUM_BYTES">PUBLIC_KEY_NUM_BYTES</a>: u64 = 32;
<pre><code><b>const</b> <a href="ed25519.md#0x1_ed25519_E_WRONG_PUBKEY_SIZE">E_WRONG_PUBKEY_SIZE</a>: u64 = 1;
</code></pre>



<a id="0x1_ed25519_E_WRONG_PUBKEY_SIZE"></a>
<a id="0x1_ed25519_E_WRONG_SIGNATURE_SIZE"></a>

Wrong number of bytes were given as input when deserializing an Ed25519 public key.
Wrong number of bytes were given as input when deserializing an Ed25519 signature.


<pre><code><b>const</b> <a href="ed25519.md#0x1_ed25519_E_WRONG_PUBKEY_SIZE">E_WRONG_PUBKEY_SIZE</a>: u64 = 1;
<pre><code><b>const</b> <a href="ed25519.md#0x1_ed25519_E_WRONG_SIGNATURE_SIZE">E_WRONG_SIGNATURE_SIZE</a>: u64 = 2;
</code></pre>



<a id="0x1_ed25519_E_WRONG_SIGNATURE_SIZE"></a>
<a id="0x1_ed25519_PUBLIC_KEY_NUM_BYTES"></a>

Wrong number of bytes were given as input when deserializing an Ed25519 signature.
The size of a serialized public key, in bytes.


<pre><code><b>const</b> <a href="ed25519.md#0x1_ed25519_E_WRONG_SIGNATURE_SIZE">E_WRONG_SIGNATURE_SIZE</a>: u64 = 2;
<pre><code><b>const</b> <a href="ed25519.md#0x1_ed25519_PUBLIC_KEY_NUM_BYTES">PUBLIC_KEY_NUM_BYTES</a>: u64 = 32;
</code></pre>


Expand Down
2 changes: 0 additions & 2 deletions aptos-move/framework/aptos-stdlib/doc/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ This is the reference documentation of the Aptos standard library.
- [`0x1::any`](any.md#0x1_any)
- [`0x1::aptos_hash`](hash.md#0x1_aptos_hash)
- [`0x1::big_vector`](big_vector.md#0x1_big_vector)
- [`0x1::bls12381`](bls12381.md#0x1_bls12381)
- [`0x1::bls12381_algebra`](bls12381_algebra.md#0x1_bls12381_algebra)
- [`0x1::bn254_algebra`](bn254_algebra.md#0x1_bn254_algebra)
- [`0x1::capability`](capability.md#0x1_capability)
- [`0x1::comparator`](comparator.md#0x1_comparator)
Expand Down
Loading

0 comments on commit f457172

Please sign in to comment.