diff --git a/.github/workflows/release-packaging.yaml b/.github/workflows/release-packaging.yaml index 4afbe33..28d8a4e 100644 --- a/.github/workflows/release-packaging.yaml +++ b/.github/workflows/release-packaging.yaml @@ -8,7 +8,7 @@ jobs: release: name: Release Packaging env: - PROJECT_NAME_UNDERSCORE: omo + PROJECT_NAME_UNDERSCORE: flexemu runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9a14a97..c5251d2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: test: name: Test env: - PROJECT_NAME_UNDERSCORE: omo + PROJECT_NAME_UNDERSCORE: flexemu CARGO_INCREMENTAL: 0 RUSTFLAGS: -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort RUSTDOCFLAGS: -Cpanic=abort diff --git a/Cargo.lock b/Cargo.lock index 71ce45c..8e5eb05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1273,6 +1273,61 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "flexemu" +version = "0.1.0" +dependencies = [ + "anyhow", + "byteorder", + "bytes 1.2.1", + "clap 3.2.22", + "env_logger 0.9.1", + "ethtrie-codec", + "goblin", + "hex", + "hex-buffer-serde", + "lazy_static", + "log 0.4.20", + "map-macro", + "maplit", + "memory-db", + "num-traits", + "rlp", + "serde", + "serde_json", + "strum", + "thiserror", + "toml", + "trie-db", + "unicorn-engine", + "value-bag", +] + +[[package]] +name = "flexemu-workflow" +version = "0.1.0" +dependencies = [ + "anyhow", + "bcs-ext", + "clap 3.2.22", + "env_logger 0.10.0", + "flexemu", + "futures-retry", + "futures-util", + "jsonrpc-core-client", + "lazy_static", + "log 0.4.20", + "serde", + "serde_json", + "starcoin-crypto", + "starcoin-rpc-api", + "starcoin-rpc-client", + "starcoin-types", + "starcoin-vm-types", + "tokio", + "toml", +] + [[package]] name = "fnv" version = "1.0.7" @@ -3216,61 +3271,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "omo" -version = "0.1.0" -dependencies = [ - "anyhow", - "byteorder", - "bytes 1.2.1", - "clap 3.2.22", - "env_logger 0.9.1", - "ethtrie-codec", - "goblin", - "hex", - "hex-buffer-serde", - "lazy_static", - "log 0.4.20", - "map-macro", - "maplit", - "memory-db", - "num-traits", - "rlp", - "serde", - "serde_json", - "strum", - "thiserror", - "toml", - "trie-db", - "unicorn-engine", - "value-bag", -] - -[[package]] -name = "omo-workflow" -version = "0.1.0" -dependencies = [ - "anyhow", - "bcs-ext", - "clap 3.2.22", - "env_logger 0.10.0", - "futures-retry", - "futures-util", - "jsonrpc-core-client", - "lazy_static", - "log 0.4.20", - "omo", - "serde", - "serde_json", - "starcoin-crypto", - "starcoin-rpc-api", - "starcoin-rpc-client", - "starcoin-types", - "starcoin-vm-types", - "tokio", - "toml", -] - [[package]] name = "once_cell" version = "1.15.0" diff --git a/Cargo.toml b/Cargo.toml index adec864..677f5ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [workspace] resolver = "2" members = [ - "omo", - "omo-workflow", + "flexemu", + "flexemu-workflow", "rust-mips-example", "crates/ethtrie-codec" ] diff --git a/README.md b/README.md index fd7edc6..4f302e9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# OMO +# flexEmu General purpose bytecode emulator with per-step proof. It can be used to generate challenge proof of optimistic rollup, @@ -8,7 +8,7 @@ See more introductions here: [en](docs/overview.md) / [zh](docs/ch/overview.md). ## Platforms -OMO could emulate program built with: +flexEmu could emulate program built with: - **Arch**: MIPS32 - **OS**: Linux @@ -32,10 +32,10 @@ Not fully supported yet, only for developing. The project contains three major Rust crates: -- [`./omo` ](omo): main entrypoint of the OMO emulator. +- [`./flexemu` ](flexemu): main entrypoint of the flexEmu emulator. - [`./rust-mips-example`](rust-mips-example): examples crate. It is configured to build into a linux mips binary, which - can be run by `OMO`. -- [`./omo-workflow`](omo-workflow): Rust binary to demonstrate how OMO work with onchain contracts to provide + can be run by `flexEmu`. +- [`./flexemu-workflow`](flexemu-workflow): Rust binary to demonstrate how flexEmu work with onchain contracts to provide interacting fraud proof. ### Prerequisites @@ -68,7 +68,7 @@ brew install richard-vd/musl-cross/musl-cross --without-x86_64 --with-mips cargo build --target mips-unknown-linux-musl --release ``` -**Compile `OMO`:** +**Compile `flexEmu`:** ```shell cargo build --release @@ -77,7 +77,7 @@ cargo build --release **Run Example1:** ```shell -RUST_LOG=error ./omo --config config.toml.example run --env E1=a --env E2=b ../target/mips-unknown-linux-musl/release/rust-mips-example E1 E2 +RUST_LOG=error ./flexemu --config config.toml.example run --env E1=a --env E2=b ../target/mips-unknown-linux-musl/release/rust-mips-example E1 E2 ``` **Output:** @@ -91,7 +91,7 @@ E2=b **Run Example2:** ```shell -RUST_LOG=error ./omo --config config.toml.example run ../rooch/omo/target/mips-unknown-linux-musl/release/arith-example 1 11 +RUST_LOG=error ./flexemu --config config.toml.example run ../rooch/flexemu/target/mips-unknown-linux-musl/release/arith-example 1 11 ``` **Output:** diff --git a/contracts/Move.toml b/contracts/Move.toml index b447420..05e8e96 100644 --- a/contracts/Move.toml +++ b/contracts/Move.toml @@ -11,11 +11,11 @@ trie = {local = "./deps/trie"} #starcoin-framework-commons = {git = "https://github.com/starcoinorg/starcoin-framework-commons.git", rev = "e7f538175a5f50a97207692569b6631a87ee08cc"} [dev-addresses] -omo = "0x48" +flexemu = "0x48" signed_integer="0x49" trie="0x50" [addresses] -omo="0xfc2cd714a9d954dcec4ca5366d2461c4" +flexemu="0xfc2cd714a9d954dcec4ca5366d2461c4" signed_integer="0xfc2cd714a9d954dcec4ca5366d2461c4" trie="0xfc2cd714a9d954dcec4ca5366d2461c4" diff --git a/contracts/README.md b/contracts/README.md index e810c71..0c0266c 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -7,7 +7,7 @@ The folder contains Move modules used in layer2 to verify layer2 instructions. Download move-cli from [movelang](https://github.com/move-language/move) ``` -$ move build --docs -d +$ move build --doc -d ``` ### Module docs @@ -16,7 +16,7 @@ see `./build/docs`. ### Dev keys -`./dev.key` is the private key corresponding to the dev-address of omo. +`./dev.key` is the private key corresponding to the dev-address of flexemu. You can use the key to deploy contracts if you don't want to change the dev-address in Move.toml. And dont use it in production! \ No newline at end of file diff --git a/contracts/bins/README.md b/contracts/bins/README.md index fe75a73..28191ea 100644 --- a/contracts/bins/README.md +++ b/contracts/bins/README.md @@ -1,7 +1,7 @@ ## Gen test data with testbin ```shell -../target/release/omo --config ../omo/config.toml.example gen-state -s 59 ./bins/arith-example 1 10 +../target/release/flexemu --config ../flexemu/config.toml.example gen-state -s 59 ./bins/arith-example 1 10 ``` this will generate a dir `step-59` with state and proof at step 59 when running the `arith-example`. diff --git a/contracts/integration-tests/step_59_test.move b/contracts/integration-tests/step_59_test.move index d90ef46..648dddd 100644 --- a/contracts/integration-tests/step_59_test.move +++ b/contracts/integration-tests/step_59_test.move @@ -7,7 +7,7 @@ //# run --signers alice --args x"{{$.read-json[-1].access_nodes}}" --args x"{{$.read-json[-1].root_before}}" --args x"{{$.read-json[-1].root_after}}" script { - use omo::mips_emulator; + use flexemu::mips_emulator; use StarcoinFramework::Signer; use trie::rlp; diff --git a/contracts/sources/challenge_script.move b/contracts/sources/challenge_script.move index bad7274..757f312 100644 --- a/contracts/sources/challenge_script.move +++ b/contracts/sources/challenge_script.move @@ -1,9 +1,9 @@ /// Public entrpoints functions for onchain challenges. -module omo::challenge_script { - use omo::SimpleChallenge; +module flexemu::challenge_script { + use flexemu::SimpleChallenge; use trie::hash_value; use trie::rlp; - use omo::mips_emulator; + use flexemu::mips_emulator; use StarcoinFramework::Signer; public(script) fun declare_state(signer: signer, final_state: vector) { diff --git a/contracts/sources/memory.move b/contracts/sources/memory.move index 1923459..472be30 100644 --- a/contracts/sources/memory.move +++ b/contracts/sources/memory.move @@ -1,6 +1,6 @@ /// `memory` module implements the read/write operations to underlying memory slots stored in eth-trie. /// Besides, the module also includes rw operations to registers. -module omo::memory { +module flexemu::memory { use trie::hash_value::{HashValue}; use signed_integer::bits::Bits; use StarcoinFramework::Vector::{length}; diff --git a/contracts/sources/mips.move b/contracts/sources/mips.move index b38d456..098a535 100644 --- a/contracts/sources/mips.move +++ b/contracts/sources/mips.move @@ -1,11 +1,11 @@ /// Mips Reference impl. https://inst.eecs.berkeley.edu/~cs61c/resources/MIPS_help.html -module omo::mips { +module flexemu::mips { use signed_integer::bits; use signed_integer::bits::{Bits, se, left_shift}; use signed_integer::i64; use trie::hash_value::HashValue; use trie::hash_value; - use omo::memory::{Memory, read_reg, write_reg, read_reg_bits, write_reg_bits, read_memory, write_memory}; + use flexemu::memory::{Memory, read_reg, write_reg, read_reg_bits, write_reg_bits, read_memory, write_memory}; const REG_ZERO: u64 = 2; @@ -532,7 +532,7 @@ module omo::mips { } -//module omo::utils { +//module flexemu::utils { // /// SignExt_idx(dat) // public fun se(dat: u64, idx: u64): u64 { // 0 diff --git a/contracts/sources/mips_emulator.move b/contracts/sources/mips_emulator.move index fdc8825..aaa82d2 100644 --- a/contracts/sources/mips_emulator.move +++ b/contracts/sources/mips_emulator.move @@ -1,7 +1,7 @@ /// A mips emulator which can run a single mips instruction based on pre-added state. -module omo::mips_emulator { - use omo::memory; - use omo::mips; +module flexemu::mips_emulator { + use flexemu::memory; + use flexemu::mips; use trie::hash_value; public fun create(signer: &signer) { diff --git a/contracts/sources/simple_challenge.move b/contracts/sources/simple_challenge.move index df60a97..967d20c 100644 --- a/contracts/sources/simple_challenge.move +++ b/contracts/sources/simple_challenge.move @@ -1,9 +1,9 @@ /// Challenge contracts used by layer2 roles like defender/challenger. -module omo::SimpleChallenge { +module flexemu::SimpleChallenge { use StarcoinFramework::Table; use StarcoinFramework::Vector; use StarcoinFramework::Signer; - use omo::mips_emulator; + use flexemu::mips_emulator; use trie::hash_value::HashValue; use trie::hash_value; @@ -80,7 +80,7 @@ module omo::SimpleChallenge { move_to(signer, challenges); } - /// only used in omo demo + /// only used in flexemu demo public fun clean_state(signer: &signer) acquires Global, Challenges { if (exists(Signer::address_of(signer))) { let Challenges {value} = move_from(Signer::address_of(signer)); diff --git a/docs/ch/components.md b/docs/ch/components.md index 93fad83..064ac27 100644 --- a/docs/ch/components.md +++ b/docs/ch/components.md @@ -1,7 +1,7 @@ Components === -OMO 主要有以下四个关键组件: +flexEmu 主要有以下四个关键组件: * Loader: 加载可执行文件。 * CPU Emulator: 在宿主机上模拟执行指令。 @@ -28,8 +28,8 @@ OMO 主要有以下四个关键组件: ## Registers and Stack -在 CPU Emulator 之上, OMO 提供了关于栈的抽象,以及更高级的寄存器和内存操作。这样我们可以很方便的对运行状态进行快照。 +在 CPU Emulator 之上, flexEmu 提供了关于栈的抽象,以及更高级的寄存器和内存操作。这样我们可以很方便的对运行状态进行快照。 ## OS Interface -OMO 模拟了大量系统调用,并保证调用是幂等的。 +flexEmu 模拟了大量系统调用,并保证调用是幂等的。 diff --git a/docs/ch/overview.md b/docs/ch/overview.md index db14d67..a33f302 100644 --- a/docs/ch/overview.md +++ b/docs/ch/overview.md @@ -1,7 +1,7 @@ 概览 === -## 关于 OMO +## 关于 flexEmu 随着链上交易量增多,Layer2 成为解决扩容问题的一个重要研究领域,其中 optimistic rollup 这一方向已经有了落地的解决方案,比如 Arbitrum (后称 arb), Optimism Cannon (后称 op)。 @@ -13,7 +13,7 @@ arb 和 op 都采用了交互式的链上仲裁技术。交互式的意思是, 和 Qiling 不同的是,区块链中的合约执行环境相对简单,没复杂 I/O 的外部交互,也无需考虑系统隔离性。另外,qiling 缺少中间状态生成以及状态证明,这是做交互式仲裁所必须的功能之一。 -我们把这个合约执行环境称作 OMO。 +我们把这个合约执行环境称作 flexEmu。 ## 更多资料 diff --git a/docs/ch/proof_of_fraud.md b/docs/ch/proof_of_fraud.md index 4fda0d4..2ca5880 100644 --- a/docs/ch/proof_of_fraud.md +++ b/docs/ch/proof_of_fraud.md @@ -27,12 +27,12 @@ 然后针对更底层的 MIPS 代码,生成相应的中间状态数据以及证明。 我认为,cannon 的思路更加灵活,更具有通用性和扩展性,但 cannon 目前的实现和 geth 捆绑的过于紧密,不便于将其直接运用到其他合约语言虚拟机上,比如 Move。 -OMO 试图扩展这种中间状态证明生成思路的适用范围,让其可以被更多的虚拟机使用。 +flexEmu 试图扩展这种中间状态证明生成思路的适用范围,让其可以被更多的虚拟机使用。 -目前 OMO 实现了 mips 指令集代码的执行和中间状态证明的生成(其他指令集比如 wasm, riscv 也在后续计划中)。 +目前 flexEmu 实现了 mips 指令集代码的执行和中间状态证明的生成(其他指令集比如 wasm, riscv 也在后续计划中)。 MIPS 模拟器的底层实现使用了 [unicorn](https://github.com/unicorn-engine/unicorn),并参考了 [qiling](https://github.com/qilingframework/qiling) 的部分逻辑。 在执行 mips 代码的过程中,unicorn 提供了多种 hook,能够让调用者方便的知晓程序的运行状态。 -具体到状态证明,OMO 主要关心程序的 _内存/寄存器_ 状态。 +具体到状态证明,flexEmu 主要关心程序的 _内存/寄存器_ 状态。 ``` rust pub struct EmulatorState { @@ -43,7 +43,7 @@ pub struct EmulatorState { ``` 内存和寄存器本质上都是一个数组(有些地址的值为0,可以不参与状态证明),一种比较大众的证明生成方式是 merkle tree root。 -OMO 也是基于这种朴素的方法实现中间状态证明。 +flexEmu 也是基于这种朴素的方法实现中间状态证明。 ### 链上执行(仲裁) @@ -55,7 +55,7 @@ OMO 也是基于这种朴素的方法实现中间状态证明。 ### 仲裁合约(法官) -为了验证 OMO 的可行性,我们用 Move 实现了针对 mips 指令集的[仲裁合约](https://github.com/starcoinorg/omo/tree/main/contracts)。 +为了验证 flexEmu 的可行性,我们用 Move 实现了针对 mips 指令集的[仲裁合约](https://github.com/rooch-network/flexemu/tree/main/contracts)。 该合约实现了上述的链上执行功能,包含了: - 前置状态的上链。 @@ -65,6 +65,6 @@ OMO 也是基于这种朴素的方法实现中间状态证明。 ## 链上仲裁的 DEMO -OMO 代码库里,包含有一个模拟控辩双方做链上仲裁的命令行程序:[omo-workflow](https://github.com/starcoinorg/omo/tree/main/omo-workflow) 。 +flexEmu 代码库里,包含有一个模拟控辩双方做链上仲裁的命令行程序:[flexemu-workflow](https://github.com/rooch-network/flexemu/tree/main/flexemu-workflow) 。 代码主页介绍了如何运行该程序,有兴趣的读者可以动手尝试一下。 diff --git a/docs/components.md b/docs/components.md index daf9ca1..cb45db6 100644 --- a/docs/components.md +++ b/docs/components.md @@ -1,9 +1,9 @@ Components === -OMO comprises four key components in present: +flexEmu comprises four key components in present: -* Loader: Loading process for executing in OMO emulator. +* Loader: Loading process for executing in flexEmu emulator. * CPU Emulator: Emulate instructions on host machine. * Registers and Stack: Emulate registers and stack in memory for snapshot. * OS Interface: Emulate system calls on host OS. @@ -28,8 +28,8 @@ Based on [Unicorn](https://github.com/unicorn-engine/unicorn) to achieve multi C ## Registers and Stack -On top of CPU Emulator, OMO provides an abstraction of the stack, as well as more advanced register and memory operations. This allows us to easily take snapshots of the running state. +On top of CPU Emulator, flexEmu provides an abstraction of the stack, as well as more advanced register and memory operations. This allows us to easily take snapshots of the running state. ## OS Interface -OMO simulates a large number of system calls and guarantees that the calls are idempotent. \ No newline at end of file +flexEmu simulates a large number of system calls and guarantees that the calls are idempotent. \ No newline at end of file diff --git a/docs/guidelines.md b/docs/guidelines.md index 541820e..2229638 100644 --- a/docs/guidelines.md +++ b/docs/guidelines.md @@ -1,7 +1,7 @@ Guidelines === -Guidelines of background, design and implementation docs of OMO. +Guidelines of background, design and implementation docs of flexEmu. * [Overview](overview.md) / [[概览]](ch/overview.md) * [Components](components.md) / [[组件]](ch/components.md) diff --git a/docs/overview.md b/docs/overview.md index 13d258f..adc72ff 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -1,7 +1,7 @@ Overview === -## About OMO +## About flexEmu As the number of on-chain transactions increases, Layer2 has become an important research area to solve the scaling problem, and there are already grounded solutions in the direction of optimistic rollup, such as Arbitrum (later called arb) and Optimism Cannon (later called op). @@ -13,8 +13,8 @@ Based on this, we try to implement a generic and verifiable contract execution e Unlike Qiling, the execution environment of contracts in blockchain is relatively simple, with no complex I/O external interactions, and no need to consider system isolation. In addition, qiling lacks intermediate state generation and proof of state, which is one of the features required for interactive arbitration. -We refer to this contract execution environment as OMO. +We refer to this contract execution environment as flexEmu. ## Learn More -You can learn OMO from [Documents](guidelines.md). +You can learn flexEmu from [Documents](guidelines.md). diff --git a/docs/proof_of_fraud.md b/docs/proof_of_fraud.md index 4f03c16..f5f7334 100644 --- a/docs/proof_of_fraud.md +++ b/docs/proof_of_fraud.md @@ -27,12 +27,12 @@ The difference is that instead of customizing a new set of virtual machines, can It then generates intermediate state data and proofs for the underlying MIPS code. I think cannon's idea is more flexible, general and extensible, but cannon's current implementation is too tightly bound to geth to make it easy to apply it directly to other contract language VMs, such as Move. -OMO tries to extend the applicability of this intermediate state proof generation idea to more VMs. +flexEmu tries to extend the applicability of this intermediate state proof generation idea to more VMs. -Currently, OMO implements the execution of the mips instruction set code and the generation of intermediate state proofs (other instruction sets such as wasm, riscv are planned in the future). +Currently, flexEmu implements the execution of the mips instruction set code and the generation of intermediate state proofs (other instruction sets such as wasm, riscv are planned in the future). The underlying implementation of the MIPS simulator uses [unicorn](https://github.com/unicorn-engine/unicorn) and references some of the logic of [qiling](https://github.com/qilingframework/qiling). During the execution of the mips code, unicorn provides various hooks that allow the caller to easily know the running state of the program. -Specifically for state proof, OMO is concerned with the _memory/register_ state of the program. +Specifically for state proof, flexEmu is concerned with the _memory/register_ state of the program. ``` rust pub struct EmulatorState { @@ -43,7 +43,7 @@ pub struct EmulatorState { ``` Memory and registers are essentially an array (some addresses have a value of 0 and can be left out of the state proof), and a more popular way of generating proofs is merkle tree root. -OMO is also based on this plain approach to implement intermediate state proofs. +flexEmu is also based on this plain approach to implement intermediate state proofs. ### On-chain Execution (arbitration) @@ -55,7 +55,7 @@ This idea is similar to that of the Ethernet light node: in the absence of a com ### Arbitration Contract (Judge) -To verify the feasibility of OMO, we implemented [arbitration contract](https://github.com/starcoinorg/omo/tree/main/contracts) for the mips instruction set using Move. +To verify the feasibility of flexEmu, we implemented [arbitration contract](https://github.com/rooch-network/flexemu/tree/main/contracts) for the mips instruction set using Move. This contract implements the on-chain execution functionality described above and contains. - The up-chaining of pre-states. @@ -65,5 +65,5 @@ This contract implements the on-chain execution functionality described above an ## DEMO for on-chain Arbitration -OMO contains a command line program that simulates on-chain arbitration between the accuser and the defender: [omo-workflow](https://github.com/starcoinorg/omo/tree/main/omo-workflow). +flexEmu contains a command line program that simulates on-chain arbitration between the accuser and the defender: [flexemu-workflow](https://github.com/rooch-network/flexemu/tree/main/flexemu-workflow). The code home page describes how to run the program, and interested readers can try it out. diff --git a/omo-workflow/Cargo.toml b/flexemu-workflow/Cargo.toml similarity index 94% rename from omo-workflow/Cargo.toml rename to flexemu-workflow/Cargo.toml index 1799623..1f94405 100644 --- a/omo-workflow/Cargo.toml +++ b/flexemu-workflow/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "omo-workflow" +name = "flexemu-workflow" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -omo = {path = "../omo"} +flexemu = {path = "../flexemu" } serde = "~1" serde_json = "~1" starcoin-crypto = { git = "https://github.com/starcoinorg/starcoin-crypto", rev = "d871dfb4216f034ee334a575926c101574d9d6dc" } diff --git a/flexemu-workflow/README.md b/flexemu-workflow/README.md new file mode 100644 index 0000000..acfe20f --- /dev/null +++ b/flexemu-workflow/README.md @@ -0,0 +1,37 @@ +## flexEmu Demo + +Rust binary to demonstrate how flexemu work with onchain contracts to provide interacting fraud proof. + +### How to run + +#### Prerequisite + +- Build a release binary of starcoin from dev branch, and put it into you PATH. I'll refer it as `starcoin`. +- Build a release binary of this repo. I'll refer it as `./target/release/flexemu-workflow` + +#### Run + +1. start starcoin dev server, and populate accounts and deploy onchain contracts. + +```shell +cd ./flexemu-workflow +starcoin -n dev -d stc-dev +bash demo_init.sh +``` + +2. start defender and challenger. + +cd root folder then run defender with: + +```shell +./target/release/flexemu-workflow --nodeurl ws://127.0.0.1:9870 --config flexemu/config.toml.example --keyfile flexemu-workflow/defender-0x72d8f07846f8fc7efc742921310124b3.key --exec contracts/bins/arith-example --arg 1 --arg 10 proposer 4040 +``` + +and challenger with: + +```shell +./target/release/flexemu-workflow --nodeurl ws://127.0.0.1:9870 --config flexemu/config.toml.example --keyfile flexemu-workflow/challenger-0x613bcd14c23d993d3f751b218510a009.key --exec contracts/bins/arith-example --arg 1 --arg 10 challenger --proposer 0x72d8f07846f8fc7efc742921310124b3 +``` + +this's it. defender and challenger will start a conversation to negotiate which step they have disagreement on. +and one can execute the final step to determine who is right. diff --git a/omo-workflow/challenger-0x613bcd14c23d993d3f751b218510a009.key b/flexemu-workflow/challenger-0x613bcd14c23d993d3f751b218510a009.key similarity index 100% rename from omo-workflow/challenger-0x613bcd14c23d993d3f751b218510a009.key rename to flexemu-workflow/challenger-0x613bcd14c23d993d3f751b218510a009.key diff --git a/omo-workflow/defender-0x72d8f07846f8fc7efc742921310124b3.key b/flexemu-workflow/defender-0x72d8f07846f8fc7efc742921310124b3.key similarity index 100% rename from omo-workflow/defender-0x72d8f07846f8fc7efc742921310124b3.key rename to flexemu-workflow/defender-0x72d8f07846f8fc7efc742921310124b3.key diff --git a/omo-workflow/demo_init.sh b/flexemu-workflow/demo_init.sh similarity index 100% rename from omo-workflow/demo_init.sh rename to flexemu-workflow/demo_init.sh diff --git a/omo-workflow/src/lib.rs b/flexemu-workflow/src/lib.rs similarity index 95% rename from omo-workflow/src/lib.rs rename to flexemu-workflow/src/lib.rs index 585e3a5..d758804 100644 --- a/omo-workflow/src/lib.rs +++ b/flexemu-workflow/src/lib.rs @@ -9,9 +9,9 @@ use crate::{ }, }; use log::{error, info}; -use omo::{ +use flexemu::{ arch::mips::{MipsProfile, MIPS}, - config::OmoConfig, + config::FlexEmuConfig, emulator::{Emulator, EmulatorState, StateChange}, os::linux::LinuxRunner, step_proof::generate_step_proof, @@ -32,7 +32,7 @@ use std::{thread::sleep, time::Duration}; pub struct SharedData { client: RpcClient, key: Ed25519PrivateKey, - omo_config: OmoConfig, + flexemu_config: FlexEmuConfig, program: RunUnit, } pub struct Challenger { @@ -52,7 +52,7 @@ pub struct RunUnit { impl Proposer { pub fn new( - omo_config: OmoConfig, + flexemu_config: FlexEmuConfig, program: RunUnit, key: Ed25519PrivateKey, rpc: RpcClient, @@ -64,7 +64,7 @@ impl Proposer { client: rpc, key, program, - omo_config, + flexemu_config, }, } } @@ -85,7 +85,7 @@ impl Proposer { info!("already declare_state with root {}", g.declared_state); } else { let emu_state = run_mips( - self.inner.omo_config.clone(), + self.inner.flexemu_config.clone(), self.inner.program.binary.clone(), self.inner.program.argv.clone(), self.inner.program.env.clone(), @@ -120,7 +120,7 @@ impl Proposer { // already stopped if c.l + 1 == c.r { let state_change = run_mips_state_change( - self.inner.omo_config.clone(), + self.inner.flexemu_config.clone(), self.inner.program.binary.clone(), self.inner.program.argv.clone(), self.inner.program.env.clone(), @@ -186,7 +186,7 @@ impl Proposer { let state_root = match self.fault_step { Some(f) if f <= next_step as usize => HashValue::new( run_mips( - self.inner.omo_config.clone(), + self.inner.flexemu_config.clone(), self.inner.program.binary.clone(), self.inner.program.argv.clone(), self.inner.program.env.clone(), @@ -196,7 +196,7 @@ impl Proposer { ), _ => HashValue::new( run_mips( - self.inner.omo_config.clone(), + self.inner.flexemu_config.clone(), self.inner.program.binary.clone(), self.inner.program.argv.clone(), self.inner.program.env.clone(), @@ -250,7 +250,7 @@ impl SharedData { impl Challenger { pub fn new( - omo_config: OmoConfig, + flexemu_config: FlexEmuConfig, program: RunUnit, key: Ed25519PrivateKey, rpc: RpcClient, @@ -262,7 +262,7 @@ impl Challenger { client: rpc, key, program, - omo_config, + flexemu_config, }, } } @@ -277,7 +277,7 @@ impl Challenger { let declared_state = remote_reader.get_resource::(self.proposer_address)?; if let Some(Global { declared_state }) = declared_state { let emu_state = run_mips( - self.inner.omo_config.clone(), + self.inner.flexemu_config.clone(), self.inner.program.binary.clone(), self.inner.program.argv.clone(), self.inner.program.env.clone(), @@ -348,7 +348,7 @@ impl Challenger { let proposer_address = self.proposer_address; if c.l + 1 == c.r { let state_change = run_mips_state_change( - self.inner.omo_config.clone(), + self.inner.flexemu_config.clone(), self.inner.program.binary.clone(), self.inner.program.argv.clone(), self.inner.program.env.clone(), @@ -397,7 +397,7 @@ impl Challenger { ); } else { let state = run_mips( - self.inner.omo_config.clone(), + self.inner.flexemu_config.clone(), self.inner.program.binary.clone(), self.inner.program.argv.clone(), self.inner.program.env.clone(), @@ -416,7 +416,7 @@ impl Challenger { } fn run_mips( - config: OmoConfig, + config: FlexEmuConfig, binary: Vec, argv: Vec, env: Vec<(String, String)>, @@ -435,7 +435,7 @@ fn run_mips( } fn run_mips_state_change( - config: OmoConfig, + config: FlexEmuConfig, binary: Vec, argv: Vec, env: Vec<(String, String)>, diff --git a/omo-workflow/src/main.rs b/flexemu-workflow/src/main.rs similarity index 91% rename from omo-workflow/src/main.rs rename to flexemu-workflow/src/main.rs index b01f955..fcc9273 100644 --- a/omo-workflow/src/main.rs +++ b/flexemu-workflow/src/main.rs @@ -1,7 +1,7 @@ use clap::Parser; use log::LevelFilter; -use omo::{config::OmoConfig, parse_key_val}; -use omo_workflow::RunUnit; +use flexemu::{config::FlexEmuConfig, parse_key_val}; +use flexemu_workflow::RunUnit; use starcoin_crypto::{ed25519::Ed25519PrivateKey, ValidCryptoMaterialStringExt}; use starcoin_rpc_client::RpcClient; use starcoin_types::account_address::AccountAddress; @@ -60,7 +60,7 @@ fn main() -> anyhow::Result<()> { node_url, cmd, } = Options::parse(); - let config: OmoConfig = + let config: FlexEmuConfig = toml::from_str(&std::fs::read_to_string(&config_file).unwrap()).unwrap(); let binary = read(exec.as_path()).unwrap(); let argv = { @@ -74,7 +74,7 @@ fn main() -> anyhow::Result<()> { let client = RpcClient::connect_websocket(&node_url).unwrap(); match cmd { Commands::Proposer { fault_step } => { - let p = omo_workflow::Proposer::new( + let p = flexemu_workflow::Proposer::new( config, RunUnit { env: envs, @@ -88,7 +88,7 @@ fn main() -> anyhow::Result<()> { p.run()?; } Commands::Challenger { proposer } => { - let challenger = omo_workflow::Challenger::new( + let challenger = flexemu_workflow::Challenger::new( config, RunUnit { env: envs, diff --git a/omo-workflow/src/move_resources.rs b/flexemu-workflow/src/move_resources.rs similarity index 100% rename from omo-workflow/src/move_resources.rs rename to flexemu-workflow/src/move_resources.rs diff --git a/omo-workflow/src/txn_builder.rs b/flexemu-workflow/src/txn_builder.rs similarity index 100% rename from omo-workflow/src/txn_builder.rs rename to flexemu-workflow/src/txn_builder.rs diff --git a/omo/Cargo.toml b/flexemu/Cargo.toml similarity index 98% rename from omo/Cargo.toml rename to flexemu/Cargo.toml index 892165b..8038713 100644 --- a/omo/Cargo.toml +++ b/flexemu/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "omo" +name = "flexemu" version = "0.1.0" edition = "2021" diff --git a/omo/config.toml.example b/flexemu/config.toml.example similarity index 100% rename from omo/config.toml.example rename to flexemu/config.toml.example diff --git a/omo/src/arch/mips.rs b/flexemu/src/arch/mips.rs similarity index 100% rename from omo/src/arch/mips.rs rename to flexemu/src/arch/mips.rs diff --git a/omo/src/arch/mod.rs b/flexemu/src/arch/mod.rs similarity index 100% rename from omo/src/arch/mod.rs rename to flexemu/src/arch/mod.rs diff --git a/omo/src/cc/mod.rs b/flexemu/src/cc/mod.rs similarity index 100% rename from omo/src/cc/mod.rs rename to flexemu/src/cc/mod.rs diff --git a/omo/src/config/mod.rs b/flexemu/src/config/mod.rs similarity index 85% rename from omo/src/config/mod.rs rename to flexemu/src/config/mod.rs index bcf1851..3282e1a 100644 --- a/omo/src/config/mod.rs +++ b/flexemu/src/config/mod.rs @@ -3,6 +3,6 @@ use serde::{Deserialize, Serialize}; use crate::loader::Config; #[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Debug)] -pub struct OmoConfig { +pub struct FlexEmuConfig { pub os: Config, } diff --git a/omo/src/emulator.rs b/flexemu/src/emulator.rs similarity index 98% rename from omo/src/emulator.rs rename to flexemu/src/emulator.rs index 992bb93..aa72a08 100644 --- a/omo/src/emulator.rs +++ b/flexemu/src/emulator.rs @@ -12,7 +12,7 @@ use ethtrie_codec::{EthTrieLayout, KeccakHasher, RlpNodeCodec}; use crate::{ arch::{ArchInfo, ArchT}, - config::OmoConfig, + config::FlexEmuConfig, engine::{Engine, Machine, MemoryState}, errors::EmulatorError, loader::{ElfLoader, LoadInfo}, @@ -21,7 +21,7 @@ use crate::{ }; pub struct Emulator<'a, A, Os> { - config: OmoConfig, + config: FlexEmuConfig, core: Engine<'a, A>, os: Os, } @@ -36,7 +36,7 @@ impl<'a, A, O> Emulator<'a, A, O> { } impl<'a, A: ArchT, O: Runner> Emulator<'a, A, O> { - pub fn new(conf: OmoConfig, arch: A, mode: Mode, os: O) -> Result { + pub fn new(conf: FlexEmuConfig, arch: A, mode: Mode, os: O) -> Result { let mut machine = Machine::create(arch, mode); // let binary = binary.as_ref(); // let load_result = ElfLoader::load(&config.os, binary, argv, &mut machine)?; diff --git a/omo/src/engine.rs b/flexemu/src/engine.rs similarity index 100% rename from omo/src/engine.rs rename to flexemu/src/engine.rs diff --git a/omo/src/errors.rs b/flexemu/src/errors.rs similarity index 100% rename from omo/src/errors.rs rename to flexemu/src/errors.rs diff --git a/omo/src/lib.rs b/flexemu/src/lib.rs similarity index 100% rename from omo/src/lib.rs rename to flexemu/src/lib.rs diff --git a/omo/src/loader/mod.rs b/flexemu/src/loader/mod.rs similarity index 100% rename from omo/src/loader/mod.rs rename to flexemu/src/loader/mod.rs diff --git a/omo/src/main.rs b/flexemu/src/main.rs similarity index 98% rename from omo/src/main.rs rename to flexemu/src/main.rs index 57b7b4d..05e69df 100644 --- a/omo/src/main.rs +++ b/flexemu/src/main.rs @@ -1,9 +1,9 @@ use byteorder::ByteOrder; use clap::Parser; use log::{info, LevelFilter}; -use omo::{ +use flexemu::{ arch::mips::{MipsProfile, MIPS}, - config::OmoConfig, + config::FlexEmuConfig, emulator::{Emulator, StateChange}, errors::EmulatorError, os::linux::LinuxRunner, @@ -63,7 +63,7 @@ fn main() -> Result<(), EmulatorError> { let opts: Options = Options::parse(); - let config: OmoConfig = + let config: FlexEmuConfig = toml::from_str(&std::fs::read_to_string(&opts.config_file).unwrap()).unwrap(); match opts.command { diff --git a/omo/src/memory.rs b/flexemu/src/memory.rs similarity index 100% rename from omo/src/memory.rs rename to flexemu/src/memory.rs diff --git a/omo/src/os/README.md b/flexemu/src/os/README.md similarity index 100% rename from omo/src/os/README.md rename to flexemu/src/os/README.md diff --git a/omo/src/os/linux/file.rs b/flexemu/src/os/linux/file.rs similarity index 100% rename from omo/src/os/linux/file.rs rename to flexemu/src/os/linux/file.rs diff --git a/omo/src/os/linux/mod.rs b/flexemu/src/os/linux/mod.rs similarity index 99% rename from omo/src/os/linux/mod.rs rename to flexemu/src/os/linux/mod.rs index d1cbe4b..bd73dac 100644 --- a/omo/src/os/linux/mod.rs +++ b/flexemu/src/os/linux/mod.rs @@ -1356,7 +1356,7 @@ impl Inner { ) -> Result { log::debug!("getcwd ({}, {}) pc: {}", buf, size, core.pc()?); let dir = match env::current_dir() { - // omo should run on same env. + // flexemu should run on same env. Err(e) => { log::debug!("failed to getcwd ({}, {}): {:?}", buf, size, e); return Ok(-1); diff --git a/omo/src/os/linux/syscall.rs b/flexemu/src/os/linux/syscall.rs similarity index 100% rename from omo/src/os/linux/syscall.rs rename to flexemu/src/os/linux/syscall.rs diff --git a/omo/src/os/linux/syscall_table.json b/flexemu/src/os/linux/syscall_table.json similarity index 100% rename from omo/src/os/linux/syscall_table.json rename to flexemu/src/os/linux/syscall_table.json diff --git a/omo/src/os/mod.rs b/flexemu/src/os/mod.rs similarity index 100% rename from omo/src/os/mod.rs rename to flexemu/src/os/mod.rs diff --git a/omo/src/rand b/flexemu/src/rand similarity index 100% rename from omo/src/rand rename to flexemu/src/rand diff --git a/omo/src/rand.rs b/flexemu/src/rand.rs similarity index 100% rename from omo/src/rand.rs rename to flexemu/src/rand.rs diff --git a/omo/src/registers.rs b/flexemu/src/registers.rs similarity index 100% rename from omo/src/registers.rs rename to flexemu/src/registers.rs diff --git a/omo/src/stack.rs b/flexemu/src/stack.rs similarity index 100% rename from omo/src/stack.rs rename to flexemu/src/stack.rs diff --git a/omo/src/step_proof.rs b/flexemu/src/step_proof.rs similarity index 100% rename from omo/src/step_proof.rs rename to flexemu/src/step_proof.rs diff --git a/omo/src/utils.rs b/flexemu/src/utils.rs similarity index 100% rename from omo/src/utils.rs rename to flexemu/src/utils.rs diff --git a/omo-workflow/README.md b/omo-workflow/README.md deleted file mode 100644 index 115f397..0000000 --- a/omo-workflow/README.md +++ /dev/null @@ -1,37 +0,0 @@ -## OMO Demo - -Rust binary to demonstrate how omo work with onchain contracts to provide interacting fraud proof. - -### How to run - -#### Prerequisite - -- Build a release binary of starcoin from dev branch, and put it into you PATH. I'll refer it as `starcoin`. -- Build a release binary of this repo. I'll refer it as `./target/release/omo-workflow` - -#### Run - -1. start starcoin dev server, and populate accounts and deploy onchain contracts. - -```shell -cd ./omo-workflow -starcoin -n dev -d stc-dev -bash demo_init.sh -``` - -2. start defender and challenger. - -cd root folder then run defender with: - -```shell -./target/release/omo-workflow --nodeurl ws://127.0.0.1:9870 --config omo/config.toml.example --keyfile omo-workflow/defender-0x72d8f07846f8fc7efc742921310124b3.key --exec contracts/bins/arith-example --arg 1 --arg 10 proposer 4040 -``` - -and challenger with: - -```shell -./target/release/omo-workflow --nodeurl ws://127.0.0.1:9870 --config omo/config.toml.example --keyfile omo-workflow/challenger-0x613bcd14c23d993d3f751b218510a009.key --exec contracts/bins/arith-example --arg 1 --arg 10 challenger --proposer 0x72d8f07846f8fc7efc742921310124b3 -``` - -this's it. defender and challenger will start an conversation to negotiate which step they have disagreement on. -and one can execute the final step to determine who is right.