Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
so-kkroy22 committed May 4, 2024
1 parent 7a12a70 commit 9ce0adf
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 83 deletions.
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.

6 changes: 6 additions & 0 deletions aptos-move/framework/aptos-framework/sources/stake.move
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ module aptos_framework::stake {
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 ed25519::new_validated_public_key_from_bytes(
consensus_pubkey,
);
assert!(option::is_some(pubkey_from_pop), error::invalid_argument(EINVALID_PUBLIC_KEY));

initialize_owner(account);
move_to(account, ValidatorConfig {
consensus_pubkey,
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
Original file line number Diff line number Diff line change
Expand Up @@ -1291,20 +1291,16 @@ impl EntryFunctionCall {
consensus_pubkey,
network_addresses,
fullnode_addresses,
} => stake_initialize_validator(
consensus_pubkey,
network_addresses,
fullnode_addresses,
),
} => {
stake_initialize_validator(consensus_pubkey, network_addresses, fullnode_addresses)
},
StakeJoinValidatorSet { pool_address } => stake_join_validator_set(pool_address),
StakeLeaveValidatorSet { pool_address } => stake_leave_validator_set(pool_address),
StakeReactivateStake { amount } => stake_reactivate_stake(amount),
StakeRotateConsensusKey {
pool_address,
new_consensus_pubkey,
} => {
stake_rotate_consensus_key(pool_address, new_consensus_pubkey)
},
} => stake_rotate_consensus_key(pool_address, new_consensus_pubkey),
StakeSetDelegatedVoter { new_voter } => stake_set_delegated_voter(new_voter),
StakeSetOperator { new_operator } => stake_set_operator(new_operator),
StakeUnlock { amount } => stake_unlock(amount),
Expand Down Expand Up @@ -5038,8 +5034,8 @@ mod decoder {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::StakeInitializeValidator {
consensus_pubkey: bcs::from_bytes(script.args().get(0)?).ok()?,
network_addresses: bcs::from_bytes(script.args().get(2)?).ok()?,
fullnode_addresses: bcs::from_bytes(script.args().get(3)?).ok()?,
network_addresses: bcs::from_bytes(script.args().get(1)?).ok()?,
fullnode_addresses: bcs::from_bytes(script.args().get(2)?).ok()?,
})
} else {
None
Expand Down

0 comments on commit 9ce0adf

Please sign in to comment.