Skip to content

Commit

Permalink
[AA] change signing_data to auth_data
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark committed Dec 11, 2024
1 parent ff4d489 commit 45b271c
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 35 deletions.
111 changes: 111 additions & 0 deletions aptos-move/framework/aptos-framework/doc/auth_data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@

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

# Module `0x1::auth_data`



- [Enum `AbstractionAuthData`](#0x1_auth_data_AbstractionAuthData)
- [Function `digest`](#0x1_auth_data_digest)
- [Function `authenticator`](#0x1_auth_data_authenticator)


<pre><code></code></pre>



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

## Enum `AbstractionAuthData`



<pre><code>enum <a href="auth_data.md#0x1_auth_data_AbstractionAuthData">AbstractionAuthData</a> <b>has</b> <b>copy</b>, drop
</code></pre>



<details>
<summary>Variants</summary>


<details>
<summary>V1</summary>


<details>
<summary>Fields</summary>


<dl>
<dt>
<code>digest: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;</code>
</dt>
<dd>

</dd>
<dt>
<code>authenticator: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;</code>
</dt>
<dd>

</dd>
</dl>


</details>

</details>

</details>

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

## Function `digest`



<pre><code><b>public</b> <b>fun</b> <a href="auth_data.md#0x1_auth_data_digest">digest</a>(signing_data: &<a href="auth_data.md#0x1_auth_data_AbstractionAuthData">auth_data::AbstractionAuthData</a>): &<a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="auth_data.md#0x1_auth_data_digest">digest</a>(signing_data: &<a href="auth_data.md#0x1_auth_data_AbstractionAuthData">AbstractionAuthData</a>): &<a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt; {
&signing_data.digest
}
</code></pre>



</details>

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

## Function `authenticator`



<pre><code><b>public</b> <b>fun</b> <a href="auth_data.md#0x1_auth_data_authenticator">authenticator</a>(signing_data: &<a href="auth_data.md#0x1_auth_data_AbstractionAuthData">auth_data::AbstractionAuthData</a>): &<a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="auth_data.md#0x1_auth_data_authenticator">authenticator</a>(signing_data: &<a href="auth_data.md#0x1_auth_data_AbstractionAuthData">AbstractionAuthData</a>): &<a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt; {
&signing_data.authenticator
}
</code></pre>



</details>


[move-book]: https://aptos.dev/move/book/SUMMARY
10 changes: 10 additions & 0 deletions aptos-move/framework/aptos-framework/doc/bcs_stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [Function `deserialize_vector`](#0x1_bcs_stream_deserialize_vector)
- [Function `deserialize_string`](#0x1_bcs_stream_deserialize_string)
- [Function `deserialize_option`](#0x1_bcs_stream_deserialize_option)
- [Specification](#@Specification_1)


<pre><code><b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
Expand Down Expand Up @@ -639,5 +640,14 @@ The <code>elem_deserializer</code> lambda expression is used to deserialize the

</details>

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

## Specification



<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>


[move-book]: https://aptos.dev/move/book/SUMMARY
30 changes: 22 additions & 8 deletions aptos-move/framework/aptos-framework/doc/lite_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
- [Function `dispatchable_authenticate`](#@Specification_1_dispatchable_authenticate)


<pre><code><b>use</b> <a href="create_signer.md#0x1_create_signer">0x1::create_signer</a>;
<pre><code><b>use</b> <a href="auth_data.md#0x1_auth_data">0x1::auth_data</a>;
<b>use</b> <a href="create_signer.md#0x1_create_signer">0x1::create_signer</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
<b>use</b> <a href="event.md#0x1_event">0x1::event</a>;
<b>use</b> <a href="function_info.md#0x1_function_info">0x1::function_info</a>;
<b>use</b> <a href="object.md#0x1_object">0x1::object</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option">0x1::option</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">0x1::signer</a>;
<b>use</b> <a href="signing_data.md#0x1_signing_data">0x1::signing_data</a>;
<b>use</b> <a href="../../aptos-stdlib/doc/simple_map.md#0x1_simple_map">0x1::simple_map</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string">0x1::string</a>;
</code></pre>
Expand Down Expand Up @@ -466,7 +466,7 @@ Return the current dispatchable authenticator move function info. <code>None</co



<pre><code><b>fun</b> <a href="lite_account.md#0x1_lite_account_authenticate">authenticate</a>(<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, func_info: <a href="function_info.md#0x1_function_info_FunctionInfo">function_info::FunctionInfo</a>, <a href="signing_data.md#0x1_signing_data">signing_data</a>: <a href="signing_data.md#0x1_signing_data_SigningData">signing_data::SigningData</a>): <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>
<pre><code><b>fun</b> <a href="lite_account.md#0x1_lite_account_authenticate">authenticate</a>(<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, func_info: <a href="function_info.md#0x1_function_info_FunctionInfo">function_info::FunctionInfo</a>, signing_data: <a href="auth_data.md#0x1_auth_data_AbstractionAuthData">auth_data::AbstractionAuthData</a>): <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>
</code></pre>


Expand All @@ -478,12 +478,12 @@ Return the current dispatchable authenticator move function info. <code>None</co
<pre><code><b>fun</b> <a href="lite_account.md#0x1_lite_account_authenticate">authenticate</a>(
<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
func_info: FunctionInfo,
<a href="signing_data.md#0x1_signing_data">signing_data</a>: SigningData,
signing_data: AbstractionAuthData,
): <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a> <b>acquires</b> <a href="lite_account.md#0x1_lite_account_DispatchableAuthenticator">DispatchableAuthenticator</a> {
<b>let</b> func_infos = <a href="lite_account.md#0x1_lite_account_dispatchable_authenticator_internal">dispatchable_authenticator_internal</a>(<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(&<a href="account.md#0x1_account">account</a>));
<b>assert</b>!(<a href="../../aptos-stdlib/doc/simple_map.md#0x1_simple_map_contains_key">simple_map::contains_key</a>(func_infos, &func_info), <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="lite_account.md#0x1_lite_account_EFUNCTION_INFO_EXISTENCE">EFUNCTION_INFO_EXISTENCE</a>));
<a href="function_info.md#0x1_function_info_load_module_from_function">function_info::load_module_from_function</a>(&func_info);
<a href="lite_account.md#0x1_lite_account_dispatchable_authenticate">dispatchable_authenticate</a>(<a href="account.md#0x1_account">account</a>, <a href="signing_data.md#0x1_signing_data">signing_data</a>, &func_info)
<a href="lite_account.md#0x1_lite_account_dispatchable_authenticate">dispatchable_authenticate</a>(<a href="account.md#0x1_account">account</a>, signing_data, &func_info)
}
</code></pre>

Expand All @@ -498,7 +498,7 @@ Return the current dispatchable authenticator move function info. <code>None</co
The native function to dispatch customized move authentication function.


<pre><code><b>fun</b> <a href="lite_account.md#0x1_lite_account_dispatchable_authenticate">dispatchable_authenticate</a>(<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, <a href="signing_data.md#0x1_signing_data">signing_data</a>: <a href="signing_data.md#0x1_signing_data_SigningData">signing_data::SigningData</a>, function: &<a href="function_info.md#0x1_function_info_FunctionInfo">function_info::FunctionInfo</a>): <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>
<pre><code><b>fun</b> <a href="lite_account.md#0x1_lite_account_dispatchable_authenticate">dispatchable_authenticate</a>(<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, signing_data: <a href="auth_data.md#0x1_auth_data_AbstractionAuthData">auth_data::AbstractionAuthData</a>, function: &<a href="function_info.md#0x1_function_info_FunctionInfo">function_info::FunctionInfo</a>): <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>
</code></pre>


Expand All @@ -509,7 +509,7 @@ The native function to dispatch customized move authentication function.

<pre><code><b>native</b> <b>fun</b> <a href="lite_account.md#0x1_lite_account_dispatchable_authenticate">dispatchable_authenticate</a>(
<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
<a href="signing_data.md#0x1_signing_data">signing_data</a>: SigningData,
signing_data: AbstractionAuthData,
function: &FunctionInfo
): <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>;
</code></pre>
Expand All @@ -529,18 +529,32 @@ The native function to dispatch customized move authentication function.




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


<pre><code><b>fun</b> <a href="lite_account.md#0x1_lite_account_spec_dispatchable_authenticate">spec_dispatchable_authenticate</a>(
<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
signing_data: AbstractionAuthData,
function: &FunctionInfo
): <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>;
</code></pre>



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

### Function `dispatchable_authenticate`


<pre><code><b>fun</b> <a href="lite_account.md#0x1_lite_account_dispatchable_authenticate">dispatchable_authenticate</a>(<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, <a href="signing_data.md#0x1_signing_data">signing_data</a>: <a href="signing_data.md#0x1_signing_data_SigningData">signing_data::SigningData</a>, function: &<a href="function_info.md#0x1_function_info_FunctionInfo">function_info::FunctionInfo</a>): <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>
<pre><code><b>fun</b> <a href="lite_account.md#0x1_lite_account_dispatchable_authenticate">dispatchable_authenticate</a>(<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, signing_data: <a href="auth_data.md#0x1_auth_data_AbstractionAuthData">auth_data::AbstractionAuthData</a>, function: &<a href="function_info.md#0x1_function_info_FunctionInfo">function_info::FunctionInfo</a>): <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>
</code></pre>




<pre><code><b>pragma</b> opaque;
<b>ensures</b> [abstract] result == <a href="lite_account.md#0x1_lite_account_spec_dispatchable_authenticate">spec_dispatchable_authenticate</a>(<a href="account.md#0x1_account">account</a>, signing_data, function);
</code></pre>


Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/aptos-framework/doc/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This is the reference documentation of the Aptos framework.
- [`0x1::aptos_account`](aptos_account.md#0x1_aptos_account)
- [`0x1::aptos_coin`](aptos_coin.md#0x1_aptos_coin)
- [`0x1::aptos_governance`](aptos_governance.md#0x1_aptos_governance)
- [`0x1::auth_data`](auth_data.md#0x1_auth_data)
- [`0x1::bcs_stream`](bcs_stream.md#0x1_bcs_stream)
- [`0x1::block`](block.md#0x1_block)
- [`0x1::chain_id`](chain_id.md#0x1_chain_id)
Expand Down Expand Up @@ -57,7 +58,6 @@ This is the reference documentation of the Aptos framework.
- [`0x1::reconfiguration_state`](reconfiguration_state.md#0x1_reconfiguration_state)
- [`0x1::reconfiguration_with_dkg`](reconfiguration_with_dkg.md#0x1_reconfiguration_with_dkg)
- [`0x1::resource_account`](resource_account.md#0x1_resource_account)
- [`0x1::signing_data`](signing_data.md#0x1_signing_data)
- [`0x1::stake`](stake.md#0x1_stake)
- [`0x1::staking_config`](staking_config.md#0x1_staking_config)
- [`0x1::staking_contract`](staking_contract.md#0x1_staking_contract)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module aptos_framework::auth_data {
enum AbstractionAuthData has copy, drop {
V1 { digest: vector<u8>, authenticator: vector<u8> },
}

#[test_only]
public fun create_auth_data(digest: vector<u8>): AbstractionAuthData {
AbstractionAuthData::V1 { digest }
}

public fun digest(signing_data: &AbstractionAuthData): &vector<u8> {
&signing_data.digest
}

public fun authenticator(signing_data: &AbstractionAuthData): &vector<u8> {
&signing_data.authenticator
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spec aptos_framework::bcs_stream {
spec module {
pragma verify = false;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module aptos_framework::lite_account {
use aptos_framework::event;
use aptos_framework::function_info::{Self, FunctionInfo};
use aptos_framework::object;
use aptos_framework::signing_data::SigningData;
use aptos_framework::auth_data::AbstractionAuthData;
#[test_only]
use aptos_framework::account::create_account_for_test;

Expand Down Expand Up @@ -162,7 +162,7 @@ module aptos_framework::lite_account {
fun authenticate(
account: signer,
func_info: FunctionInfo,
signing_data: SigningData,
signing_data: AbstractionAuthData,
): signer acquires DispatchableAuthenticator {
let func_infos = dispatchable_authenticator_internal(signer::address_of(&account));
assert!(simple_map::contains_key(func_infos, &func_info), error::not_found(EFUNCTION_INFO_EXISTENCE));
Expand All @@ -173,7 +173,7 @@ module aptos_framework::lite_account {
/// The native function to dispatch customized move authentication function.
native fun dispatchable_authenticate(
account: signer,
signing_data: SigningData,
signing_data: AbstractionAuthData,
function: &FunctionInfo
): signer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ spec aptos_framework::lite_account {
pragma verify = false;
}

spec dispatchable_authenticate {

spec fun spec_dispatchable_authenticate(
account: signer,
signing_data: AbstractionAuthData,
function: &FunctionInfo
): signer;

spec dispatchable_authenticate(account: signer, signing_data: AbstractionAuthData, function: &FunctionInfo): signer {
pragma opaque;
ensures [abstract] result == spec_dispatchable_authenticate(account, signing_data, function);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module aa::single_key {
use std::option;
use std::signer;
use aptos_std::bls12381::{Self, PublicKey};
use aptos_framework::signing_data::{Self, SigningData};
use aptos_framework::auth_data::{Self, AbstractionAuthData};

/// Only fungible asset metadata owner can make changes.
const EINVALID_PUBLIC_KEY: u64 = 1;
Expand Down Expand Up @@ -32,16 +32,16 @@ module aa::single_key {
/// Authorization function for account abstraction.
public fun authenticate(
account: signer,
signing_data: SigningData,
signing_data: AbstractionAuthData,
): signer acquires BLSPublicKey {
let addr = signer::address_of(&account);
assert!(exists<BLSPublicKey>(addr), EPUBLIC_KEY_NOT_FOUND);
let pubkey = &borrow_global<BLSPublicKey>(addr).key;
assert!(
bls12381::verify_normal_signature(
&bls12381::signature_from_bytes(*signing_data::authenticator(&signing_data)),
&bls12381::signature_from_bytes(*auth_data::authenticator(&signing_data)),
pubkey,
*signing_data::digest(&signing_data)
*auth_data::digest(&signing_data)
),
EINVALID_SIGNATURE
);
Expand Down

0 comments on commit 45b271c

Please sign in to comment.