Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
geometryolife authored Jul 20, 2023
2 parents 61e30c0 + 055c4d2 commit b4c191a
Show file tree
Hide file tree
Showing 74 changed files with 7,487 additions and 226 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/check_build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ on:
- 'docs/**'
- 'fixtures/**'
- 'kube/**'
- 'scripts/**'
- '**.md'
pull_request:
branches: ["main"]
paths-ignore:
- 'docs/**'
- 'fixtures/**'
- 'kube/**'
- 'scripts/**'
- '**.md'

env:
Expand Down
69 changes: 35 additions & 34 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ enum_dispatch = "^0.3"
ethereum-types = "0.14.1"
ethers = { version = "2.0.7", features = ["legacy"] }
eyre = "0.6.8"
fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "c27e87fb539c88b6fe1eac7dd82561254bb1e07a" }
fastcrypto = { git = "https://github.com/rooch-network/fastcrypto", branch = "main" }
futures = "0.3"
hex = "0.4.3"
rustc-hex = "1.0"
Expand Down Expand Up @@ -181,42 +181,43 @@ rstest = "0.16.0"
nostr = "0.22"
serde-reflection = "0.3.6"
serde-generate = "0.25.1"
rust_secp256k1 = { version = "0.27.0", package = "secp256k1", features = ["recovery", "rand-std", "bitcoin_hashes", "global-context"] }

# Note: the BEGIN and END comments below are required for external tooling. Do not remove.
# BEGIN MOVE DEPENDENCIES
move-abigen = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-binary-format = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-bytecode-verifier = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-bytecode-utils = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-cli = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-command-line-common = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-compiler ={ git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-core-types = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c", features = ["address32"] }
move-coverage = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-disassembler = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-docgen = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-errmapgen = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-ir-compiler = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-model = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-package = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-prover = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-prover-boogie-backend = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-stackless-bytecode = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-prover-test-utils = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-resource-viewer = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-stackless-bytecode-interpreter = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-stdlib = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c", features = ["address32", "testing"] }
move-symbol-pool = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
#move-table-extension = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-transactional-test-runner = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-unit-test = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c", features = ["table-extension"] }
move-vm-runtime = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c", features = ["lazy_natives"] }
move-vm-test-utils = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c", features = ["table-extension"] }
move-vm-types = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
read-write-set = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
read-write-set-dynamic = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-bytecode-source-map = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-ir-types = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" }
move-abigen = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-binary-format = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-bytecode-verifier = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-bytecode-utils = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-cli = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-command-line-common = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-compiler ={ git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-core-types = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756", features = ["address32"] }
move-coverage = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-disassembler = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-docgen = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-errmapgen = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-ir-compiler = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-model = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-package = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-prover = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-prover-boogie-backend = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-stackless-bytecode = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-prover-test-utils = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-resource-viewer = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-stackless-bytecode-interpreter = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-stdlib = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756", features = ["address32", "testing"] }
move-symbol-pool = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
#move-table-extension = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-transactional-test-runner = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-unit-test = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756", features = ["table-extension"] }
move-vm-runtime = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756", features = ["lazy_natives"] }
move-vm-test-utils = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756", features = ["table-extension"] }
move-vm-types = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
read-write-set = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
read-write-set-dynamic = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-bytecode-source-map = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
move-ir-types = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" }
# END MOVE DEPENDENCIES

# keep this for convenient debug Move in local repo
Expand Down
35 changes: 30 additions & 5 deletions crates/rooch-executor/src/actor/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ use moveos_types::module_binding::MoveFunctionCaller;
use moveos_types::move_types::as_struct_tag;
use moveos_types::state::{AnnotatedState, State};
use moveos_types::state_resolver::{AnnotatedStateReader, StateReader};
use moveos_types::transaction::FunctionCall;
use moveos_types::transaction::TransactionExecutionInfo;
use moveos_types::transaction::VerifiedMoveOSTransaction;
use moveos_types::tx_context::TxContext;
use rooch_framework::bindings::address_mapping::AddressMapping;
use rooch_framework::bindings::auth_validator::AuthValidatorCaller;
use rooch_framework::bindings::transaction_validator::TransactionValidator;
use rooch_genesis::RoochGenesis;
use rooch_store::RoochDB;
use rooch_types::address::MultiChainAddress;
use rooch_types::transaction::AuthenticatorInfo;
use rooch_types::transaction::{AbstractTransaction, TransactionSequenceMapping};

pub struct ExecutorActor {
Expand Down Expand Up @@ -76,18 +80,17 @@ impl ExecutorActor {

let mut moveos_tx = tx.construct_moveos_transaction(resolved_sender?)?;

let result = {
let tx_validator = self.moveos.as_module_bundle::<TransactionValidator>();
tx_validator.validate(&moveos_tx.ctx, authenticator)
};
let result = self.validate_authenticator(&moveos_tx.ctx, authenticator);

match result {
Ok(_) => {
Ok((pre_execute_functions, post_execute_functions)) => {
// Add the original multichain address to the context
moveos_tx
.ctx
.add(multi_chain_address_sender)
.expect("add sender to context failed");
moveos_tx.append_pre_execute_functions(pre_execute_functions);
moveos_tx.append_post_execute_functions(post_execute_functions);
Ok(self.moveos.verify(moveos_tx)?)
}
Err(e) => {
Expand All @@ -100,6 +103,28 @@ impl ExecutorActor {
}
}
}

pub fn validate_authenticator(
&self,
ctx: &TxContext,
authenticator: AuthenticatorInfo,
) -> Result<(Vec<FunctionCall>, Vec<FunctionCall>)> {
let tx_validator = self.moveos.as_module_bundle::<TransactionValidator>();
let auth_validator = tx_validator.validate(ctx, authenticator.clone())?;
let auth_validator_caller = AuthValidatorCaller::new(&self.moveos, auth_validator);
auth_validator_caller.validate(ctx, authenticator.authenticator.payload)?;
// pre_execute_function: TransactionValidator first, then AuthValidator
let pre_execute_functions = vec![
TransactionValidator::pre_execute_function_call(),
auth_validator_caller.pre_execute_function_call(),
];
// post_execute_function: AuthValidator first, then TransactionValidator
let post_execute_functions = vec![
auth_validator_caller.post_execute_function_call(),
TransactionValidator::post_execute_function_call(),
];
Ok((pre_execute_functions, post_execute_functions))
}
}

impl Actor for ExecutorActor {}
Expand Down
1 change: 1 addition & 0 deletions crates/rooch-framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde_bytes = { workspace = true }
sha3 = { workspace = true }
smallvec = { workspace = true }
hex = { workspace = true }
rust_secp256k1 = { workspace = true }

move-binary-format = { workspace = true }
move-bytecode-utils = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/rooch-framework/doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ This is the reference documentation of the Rooch Framework.
- [`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::schnorr`](schnorr.md#0x3_schnorr)
- [`0x3::schnorr_validator`](schnorr_validator.md#0x3_schnorr_validator)
- [`0x3::transaction_validator`](transaction_validator.md#0x3_transaction_validator)


Expand Down
2 changes: 2 additions & 0 deletions crates/rooch-framework/doc/auth_validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
This module contains the error code for auth_validator module
The auth_validator implementation should contain the following functions
public fun validate(ctx: &StorageContext, payload: vector<u8>)
fun pre_execute(ctx: &mut StorageContext)
fun post_execute(ctx: &mut StorageContext)


- [Constants](#@Constants_0)
Expand Down
16 changes: 10 additions & 6 deletions crates/rooch-framework/doc/builtin_validators.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

- [Constants](#@Constants_0)
- [Function `genesis_init`](#0x3_builtin_validators_genesis_init)
- [Function `is_builtin`](#0x3_builtin_validators_is_builtin)
- [Function `is_builtin_scheme`](#0x3_builtin_validators_is_builtin_scheme)


<pre><code><b>use</b> <a href="">0x1::error</a>;
Expand All @@ -16,6 +16,7 @@
<b>use</b> <a href="ecdsa_validator.md#0x3_ecdsa_validator">0x3::ecdsa_validator</a>;
<b>use</b> <a href="ed25519_validator.md#0x3_ed25519_validator">0x3::ed25519_validator</a>;
<b>use</b> <a href="multi_ed25519_validator.md#0x3_multi_ed25519_validator">0x3::multi_ed25519_validator</a>;
<b>use</b> <a href="schnorr_validator.md#0x3_schnorr_validator">0x3::schnorr_validator</a>;
</code></pre>


Expand Down Expand Up @@ -59,20 +60,23 @@
//SCHEME_ECDSA: u64 = 2;
<b>let</b> id = <a href="auth_validator_registry.md#0x3_auth_validator_registry_register_internal">auth_validator_registry::register_internal</a>&lt;<a href="ecdsa_validator.md#0x3_ecdsa_validator_EcdsaValidator">ecdsa_validator::EcdsaValidator</a>&gt;(ctx);
<b>assert</b>!(id == <a href="ecdsa_validator.md#0x3_ecdsa_validator_scheme">ecdsa_validator::scheme</a>(), std::error::internal(<a href="builtin_validators.md#0x3_builtin_validators_E_GENESIS_INIT">E_GENESIS_INIT</a>));
//SCHEME_SCHNORR: u64 = 3;
<b>let</b> id = <a href="auth_validator_registry.md#0x3_auth_validator_registry_register_internal">auth_validator_registry::register_internal</a>&lt;<a href="schnorr_validator.md#0x3_schnorr_validator_SchnorrValidator">schnorr_validator::SchnorrValidator</a>&gt;(ctx);
<b>assert</b>!(id == <a href="schnorr_validator.md#0x3_schnorr_validator_scheme">schnorr_validator::scheme</a>(), std::error::internal(<a href="builtin_validators.md#0x3_builtin_validators_E_GENESIS_INIT">E_GENESIS_INIT</a>));
}
</code></pre>



</details>

<a name="0x3_builtin_validators_is_builtin"></a>
<a name="0x3_builtin_validators_is_builtin_scheme"></a>

## Function `is_builtin`
## Function `is_builtin_scheme`



<pre><code><b>public</b> <b>fun</b> <a href="builtin_validators.md#0x3_builtin_validators_is_builtin">is_builtin</a>(scheme: u64): bool
<pre><code><b>public</b> <b>fun</b> <a href="builtin_validators.md#0x3_builtin_validators_is_builtin_scheme">is_builtin_scheme</a>(scheme: u64): bool
</code></pre>


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


<pre><code><b>public</b> <b>fun</b> <a href="builtin_validators.md#0x3_builtin_validators_is_builtin">is_builtin</a>(scheme: u64): bool {
scheme == <a href="ed25519_validator.md#0x3_ed25519_validator_scheme">ed25519_validator::scheme</a>() || scheme == <a href="multi_ed25519_validator.md#0x3_multi_ed25519_validator_scheme">multi_ed25519_validator::scheme</a>() || scheme == <a href="ecdsa_validator.md#0x3_ecdsa_validator_scheme">ecdsa_validator::scheme</a>()
<pre><code><b>public</b> <b>fun</b> <a href="builtin_validators.md#0x3_builtin_validators_is_builtin_scheme">is_builtin_scheme</a>(scheme: u64): bool {
scheme == <a href="ed25519_validator.md#0x3_ed25519_validator_scheme">ed25519_validator::scheme</a>() || scheme == <a href="multi_ed25519_validator.md#0x3_multi_ed25519_validator_scheme">multi_ed25519_validator::scheme</a>() || scheme == <a href="ecdsa_validator.md#0x3_ecdsa_validator_scheme">ecdsa_validator::scheme</a>() || scheme == <a href="schnorr_validator.md#0x3_schnorr_validator_scheme">schnorr_validator::scheme</a>()
}
</code></pre>

Expand Down
44 changes: 44 additions & 0 deletions crates/rooch-framework/doc/schnorr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

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

# Module `0x3::schnorr`



- [Function `verify`](#0x3_schnorr_verify)


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



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

## Function `verify`

@param signature: A 65-bytes signature that is signed using Schnorr over Secpk256k1 key pairs.
@param msg: The message that the signature is signed against.
@param hash: The hash function used to hash the message when signing.

If the signature is valid to the pubkey and hashed message, return true. Else false.


<pre><code><b>public</b> <b>fun</b> <a href="schnorr.md#0x3_schnorr_verify">verify</a>(signature: &<a href="">vector</a>&lt;u8&gt;, msg: &<a href="">vector</a>&lt;u8&gt;, <a href="../doc/hash.md#0x1_hash">hash</a>: u8): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>native</b> <b>fun</b> <a href="schnorr.md#0x3_schnorr_verify">verify</a>(
signature: &<a href="">vector</a>&lt;u8&gt;,
msg: &<a href="">vector</a>&lt;u8&gt;,
<a href="../doc/hash.md#0x1_hash">hash</a>: u8
): bool;
</code></pre>



</details>
Loading

0 comments on commit b4c191a

Please sign in to comment.