Skip to content

Commit

Permalink
Merge commit '9811b7dbf465070d33d0b3ce7ed9c879fb937048'
Browse files Browse the repository at this point in the history
* commit '9811b7dbf465070d33d0b3ce7ed9c879fb937048':
  [rooch-networkgh-472] add helper function if modules are empty. (rooch-network#473)
  [AccountAbstraction] Implement AuthenticatorAbstraction (rooch-network#466)
  • Loading branch information
wubuku committed Jul 14, 2023
2 parents 76ec6ec + 9811b7d commit cee0307
Show file tree
Hide file tree
Showing 47 changed files with 2,383 additions and 900 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
crates/rooch-framework/doc linguist-generated=true
moveos/moveos-stdlib/move-stdlib/doc linguist-generated=true
moveos/moveos-stdlib/moveos-stdlib/doc linguist-generated=true
8 changes: 7 additions & 1 deletion crates/rooch-framework-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ move-vm-types = { workspace = true }
move-package = { workspace = true }
move-prover = { workspace = true }


moveos = { workspace = true }
moveos-types = { workspace = true }
moveos-verifier = { workspace = true }
moveos-store = { workspace = true }

rooch-framework = { workspace = true }
rooch-genesis = { workspace = true }
rooch-types = { workspace = true }
rooch-key = { workspace = true }

[dev-dependencies]
rooch-integration-test-runner = { workspace = true }
Expand Down
29 changes: 29 additions & 0 deletions crates/rooch-framework-tests/src/binding_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use moveos::moveos::MoveOS;
use moveos_store::MoveOSDB;
use moveos_types::module_binding::{ModuleBundle, MoveFunctionCaller};
use rooch_genesis::RoochGenesis;

pub struct RustBindingTest {
moveos: MoveOS,
}

impl RustBindingTest {
pub fn new() -> Result<Self> {
let moveosdb = MoveOSDB::new_with_memory_store();
let genesis: &RoochGenesis = &rooch_genesis::ROOCH_GENESIS;

let mut moveos = MoveOS::new(moveosdb, genesis.all_natives(), genesis.config.clone())?;
if moveos.state().is_genesis() {
moveos.init_genesis(genesis.genesis_txs())?;
}
Ok(Self { moveos })
}

pub fn as_module_bundle<'a, M: ModuleBundle<'a>>(&'a self) -> M {
self.moveos.as_module_bundle::<M>()
}
}
4 changes: 4 additions & 0 deletions crates/rooch-framework-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

pub mod binding_test;
#[cfg(test)]
mod tests;
30 changes: 30 additions & 0 deletions crates/rooch-framework-tests/src/tests/ed25519_validator_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use moveos_types::transaction::MoveAction;
use rooch_framework::bindings::empty::Empty;
use rooch_key::keystore::{AccountKeystore, InMemKeystore};
use rooch_types::transaction::{rooch::RoochTransactionData, AbstractTransaction};

use crate::binding_test;

#[test]
fn test_validate() {
let binding_test = binding_test::RustBindingTest::new().unwrap();
let ed25519_validator = binding_test
.as_module_bundle::<rooch_framework::bindings::ed25519_validator::Ed25519Validator>(
);

let keystore = InMemKeystore::new_insecure_for_tests(1);
let sender = keystore.addresses()[0];
let sequence_number = 0;
let action = MoveAction::new_function_call(Empty::empty_function_id(), vec![], vec![]);
let tx_data = RoochTransactionData::new(sender, sequence_number, action);
let tx = keystore.sign_transaction(&sender, tx_data).unwrap();
let auth_info = tx.authenticator_info();
let move_tx = tx.construct_moveos_transaction(sender.into()).unwrap();

ed25519_validator
.validate(&move_tx.ctx, auth_info.authenticator.payload)
.unwrap();
}
13 changes: 13 additions & 0 deletions crates/rooch-framework-tests/src/tests/empty_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use crate::binding_test;
use moveos_types::tx_context::TxContext;

#[test]
fn test_empty() {
let binding_test = binding_test::RustBindingTest::new().unwrap();
let empty = binding_test.as_module_bundle::<rooch_framework::bindings::empty::Empty>();
let ctx = TxContext::random_for_testing_only();
empty.empty(&ctx).unwrap();
}
6 changes: 6 additions & 0 deletions crates/rooch-framework-tests/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

mod ed25519_validator_tests;
mod empty_tests;
mod transaction_validator_tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use moveos_types::transaction::MoveAction;
use rooch_framework::bindings::empty::Empty;
use rooch_key::keystore::{AccountKeystore, InMemKeystore};
use rooch_types::transaction::{rooch::RoochTransactionData, AbstractTransaction};

use crate::binding_test;

#[test]
fn test_validate() {
let binding_test = binding_test::RustBindingTest::new().unwrap();
let transaction_validator = binding_test.as_module_bundle::<rooch_framework::bindings::transaction_validator::TransactionValidator>();

let keystore = InMemKeystore::new_insecure_for_tests(1);
let sender = keystore.addresses()[0];
let sequence_number = 0;
let action = MoveAction::new_function_call(Empty::empty_function_id(), vec![], vec![]);
let tx_data = RoochTransactionData::new(sender, sequence_number, action);
let tx = keystore.sign_transaction(&sender, tx_data).unwrap();
let auth_info = tx.authenticator_info();
let move_tx = tx.construct_moveos_transaction(sender.into()).unwrap();

transaction_validator
.validate(&move_tx.ctx, auth_info)
.unwrap();
}
10 changes: 9 additions & 1 deletion crates/rooch-framework/doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ This is the reference documentation of the Rooch Framework.


- [`0x3::account`](account.md#0x3_account)
- [`0x3::account_authentication`](account_authentication.md#0x3_account_authentication)
- [`0x3::address_mapping`](address_mapping.md#0x3_address_mapping)
- [`0x3::authenticator`](authenticator.md#0x3_authenticator)
- [`0x3::auth_validator`](auth_validator.md#0x3_auth_validator)
- [`0x3::auth_validator_registry`](auth_validator_registry.md#0x3_auth_validator_registry)
- [`0x3::builtin_validators`](builtin_validators.md#0x3_builtin_validators)
- [`0x3::core_addresses`](core_addresses.md#0x3_core_addresses)
- [`0x3::ecdsa_k1`](ecdsa_k1.md#0x3_ecdsa_k1)
- [`0x3::ed25519`](ed25519.md#0x3_ed25519)
- [`0x3::ed25519_validator`](ed25519_validator.md#0x3_ed25519_validator)
- [`0x3::empty`](empty.md#0x3_empty)
- [`0x3::genesis`](genesis.md#0x3_genesis)
- [`0x3::hash`](hash.md#0x3_hash)
- [`0x3::multi_ed25519_validator`](multi_ed25519_validator.md#0x3_multi_ed25519_validator)
- [`0x3::secp256k1_validator`](secp256k1_validator.md#0x3_secp256k1_validator)
- [`0x3::transaction_validator`](transaction_validator.md#0x3_transaction_validator)


Expand Down
95 changes: 0 additions & 95 deletions crates/rooch-framework/doc/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
- [Function `sequence_number_for_sender`](#0x3_account_sequence_number_for_sender)
- [Function `increment_sequence_number`](#0x3_account_increment_sequence_number)
- [Function `balance`](#0x3_account_balance)
- [Function `get_authentication_key`](#0x3_account_get_authentication_key)
- [Function `signer_address`](#0x3_account_signer_address)
- [Function `is_resource_account`](#0x3_account_is_resource_account)
- [Function `exists_at`](#0x3_account_exists_at)
- [Function `create_resource_account`](#0x3_account_create_resource_account)
- [Function `create_resource_address`](#0x3_account_create_resource_address)
- [Function `rotate_authentication_key_internal`](#0x3_account_rotate_authentication_key_internal)
- [Function `create_signer_with_capability`](#0x3_account_create_signer_with_capability)
- [Function `get_signer_capability_address`](#0x3_account_get_signer_capability_address)

Expand Down Expand Up @@ -57,12 +55,6 @@ Resource representing an account.

<dl>
<dt>
<code>authentication_key: <a href="">vector</a>&lt;u8&gt;</code>
</dt>
<dd>

</dd>
<dt>
<code>sequence_number: u64</code>
</dt>
<dd>
Expand Down Expand Up @@ -179,16 +171,6 @@ Account already exists



<a name="0x3_account_AUTHENTICATION_KEY_LENGTH"></a>

authentication key length


<pre><code><b>const</b> <a href="account.md#0x3_account_AUTHENTICATION_KEY_LENGTH">AUTHENTICATION_KEY_LENGTH</a>: u64 = 32;
</code></pre>



<a name="0x3_account_CONTRACT_ACCOUNT_AUTH_KEY_PLACEHOLDER"></a>


Expand Down Expand Up @@ -242,16 +224,6 @@ Cannot create account because address is reserved



<a name="0x3_account_EMalformedAuthenticationKey"></a>

The provided authentication key has an invalid length


<pre><code><b>const</b> <a href="account.md#0x3_account_EMalformedAuthenticationKey">EMalformedAuthenticationKey</a>: u64 = 4;
</code></pre>



<a name="0x3_account_ENoValidFrameworkReservedAddress"></a>

Address to create is not a valid reserved address for Rooch framework
Expand Down Expand Up @@ -504,35 +476,6 @@ Return the current TokenType balance of the account at <code>addr</code>.



</details>

<a name="0x3_account_get_authentication_key"></a>

## Function `get_authentication_key`



<pre><code><b>public</b> <b>fun</b> <a href="account.md#0x3_account_get_authentication_key">get_authentication_key</a>(ctx: &<a href="_StorageContext">storage_context::StorageContext</a>, addr: <b>address</b>): <a href="">vector</a>&lt;u8&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="account.md#0x3_account_get_authentication_key">get_authentication_key</a>(ctx: &StorageContext, addr: <b>address</b>): <a href="">vector</a>&lt;u8&gt; {
//<b>if</b> <a href="account.md#0x3_account">account</a> does not exist, <b>return</b> addr <b>as</b> authentication key
<b>if</b>(!<a href="_global_exists">account_storage::global_exists</a>&lt;<a href="account.md#0x3_account_Account">Account</a>&gt;(ctx, addr)){
<a href="_to_bytes">bcs::to_bytes</a>(&addr)
}<b>else</b>{
<a href="_global_borrow">account_storage::global_borrow</a>&lt;<a href="account.md#0x3_account_Account">Account</a>&gt;(ctx, addr).authentication_key
}
}
</code></pre>



</details>

<a name="0x3_account_signer_address"></a>
Expand Down Expand Up @@ -648,11 +591,6 @@ A resource account can only be created once
<a href="account.md#0x3_account_create_account_unchecked">create_account_unchecked</a>(ctx, resource_addr)
};

// By default, only the <a href="account.md#0x3_account_SignerCapability">SignerCapability</a> should have control over the resource <a href="account.md#0x3_account">account</a> and not the auth key.
// If the source <a href="account.md#0x3_account">account</a> wants direct control via auth key, they would need <b>to</b> explicitly rotate the auth key
// of the resource <a href="account.md#0x3_account">account</a> using the <a href="account.md#0x3_account_SignerCapability">SignerCapability</a>.
<a href="account.md#0x3_account_rotate_authentication_key_internal">rotate_authentication_key_internal</a>(ctx,&resource_signer, <a href="account.md#0x3_account_ZERO_AUTH_KEY">ZERO_AUTH_KEY</a>);
// <b>move_to</b>(&resource_signer, <a href="account.md#0x3_account_ResourceAccount">ResourceAccount</a> {});
<a href="_global_move_to">account_storage::global_move_to</a>&lt;<a href="account.md#0x3_account_ResourceAccount">ResourceAccount</a>&gt;(ctx,
&resource_signer,
<a href="account.md#0x3_account_ResourceAccount">ResourceAccount</a> {}
Expand Down Expand Up @@ -694,39 +632,6 @@ involves the use of a cryptographic hash operation and should be use thoughtfull



</details>

<a name="0x3_account_rotate_authentication_key_internal"></a>

## Function `rotate_authentication_key_internal`

This function is used to rotate a resource account's authentication key to 0, so that no private key can control
the resource account.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="account.md#0x3_account_rotate_authentication_key_internal">rotate_authentication_key_internal</a>(ctx: &<b>mut</b> <a href="_StorageContext">storage_context::StorageContext</a>, <a href="account.md#0x3_account">account</a>: &<a href="">signer</a>, new_auth_key: <a href="">vector</a>&lt;u8&gt;)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="account.md#0x3_account_rotate_authentication_key_internal">rotate_authentication_key_internal</a>(ctx: &<b>mut</b> StorageContext, <a href="account.md#0x3_account">account</a>: &<a href="">signer</a>, new_auth_key: <a href="">vector</a>&lt;u8&gt;) {
<b>let</b> addr = <a href="_address_of">signer::address_of</a>(<a href="account.md#0x3_account">account</a>);
<b>assert</b>!(<a href="account.md#0x3_account_exists_at">exists_at</a>(ctx, addr), <a href="_not_found">error::not_found</a>(<a href="account.md#0x3_account_EAccountNotExist">EAccountNotExist</a>));
<b>assert</b>!(
<a href="_length">vector::length</a>(&new_auth_key) == <a href="account.md#0x3_account_AUTHENTICATION_KEY_LENGTH">AUTHENTICATION_KEY_LENGTH</a>,
<a href="_invalid_argument">error::invalid_argument</a>(<a href="account.md#0x3_account_EMalformedAuthenticationKey">EMalformedAuthenticationKey</a>)
);
<b>let</b> account_resource = <a href="_global_borrow_mut">account_storage::global_borrow_mut</a>&lt;<a href="account.md#0x3_account_Account">Account</a>&gt;(ctx, addr);
account_resource.authentication_key = new_auth_key;
}
</code></pre>



</details>

<a name="0x3_account_create_signer_with_capability"></a>
Expand Down
Loading

0 comments on commit cee0307

Please sign in to comment.