Skip to content

Commit 0ea8072

Browse files
0xJepsenEvalir
authored andcommitted
book workflow (bluealloy#537)
* book workflow * mdbook lint * mdbook build optional * Update introduction.md * interpreter primitives + precompiles mdbook test, doctests * fmt + CI * clippy + book
1 parent a300096 commit 0ea8072

34 files changed

+382
-577
lines changed

.github/workflows/book.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: book
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
merge_group:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
name: test
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Install mdbook
18+
run: |
19+
mkdir mdbook
20+
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
21+
echo `pwd`/mdbook >> $GITHUB_PATH
22+
23+
- name: Install mdbook-template
24+
run: |
25+
mkdir mdbook-template
26+
curl -sSL https://github.com/sgoudham/mdbook-template/releases/latest/download/mdbook-template-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook-template
27+
echo `pwd`/mdbook-template >> $GITHUB_PATH
28+
29+
- name: Run tests
30+
run: mdbook test
31+
32+
lint:
33+
runs-on: ubuntu-latest
34+
name: lint
35+
36+
steps:
37+
- uses: actions/checkout@v3
38+
39+
- name: Install mdbook-linkcheck
40+
run: |
41+
mkdir mdbook-linkcheck
42+
curl -sSL -o mdbook-linkcheck.zip https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/latest/download/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip
43+
unzip mdbook-linkcheck.zip -d ./mdbook-linkcheck
44+
chmod +x `pwd`/mdbook-linkcheck/mdbook-linkcheck
45+
echo `pwd`/mdbook-linkcheck >> $GITHUB_PATH
46+
47+
- name: Run linkcheck
48+
run: mdbook-linkcheck --standalone
49+
50+
build:
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v3
54+
with:
55+
fetch-depth: 0
56+
57+
- name: Install toolchain
58+
uses: dtolnay/rust-toolchain@nightly
59+
- uses: Swatinem/rust-cache@v2
60+
with:
61+
cache-on-failure: true
62+
63+
- name: Install mdbook
64+
run: |
65+
mkdir mdbook
66+
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
67+
echo `pwd`/mdbook >> $GITHUB_PATH
68+
69+
- name: Install mdbook-template
70+
run: |
71+
mkdir mdbook-template
72+
curl -sSL https://github.com/sgoudham/mdbook-template/releases/latest/download/mdbook-template-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook-template
73+
echo `pwd`/mdbook-template >> $GITHUB_PATH
74+
75+
- name: Build book
76+
run: mdbook build
77+
78+
- name: Build docs
79+
run: RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo +nightly doc --all --no-deps
80+
81+
- name: Move docs to book folder
82+
run: |
83+
mkdir -p target/book/docs
84+
mv target/doc target/book/docs
85+
86+
- name: Archive artifact
87+
shell: sh
88+
run: |
89+
chmod -c -R +rX "target/book" |
90+
while read line; do
91+
echo "::warning title=Invalid file permissions automatically fixed::$line"
92+
done
93+
tar \
94+
--dereference --hard-dereference \
95+
--directory "target/book" \
96+
-cvf "$RUNNER_TEMP/artifact.tar" \
97+
--exclude=.git \
98+
--exclude=.github \
99+
.
100+
101+
- name: Upload artifact
102+
uses: actions/upload-artifact@v3
103+
with:
104+
name: github-pages
105+
path: ${{ runner.temp }}/artifact.tar
106+
retention-days: 1
107+
if-no-files-found: error
108+
109+
deploy:
110+
# Only deploy if a push to main
111+
if: github.ref_name == 'main' && github.event_name == 'push'
112+
runs-on: ubuntu-latest
113+
needs: [test, lint, build]
114+
115+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
116+
permissions:
117+
pages: write
118+
id-token: write
119+
120+
environment:
121+
name: github-pages
122+
url: ${{ steps.deployment.outputs.page_url }}
123+
124+
steps:
125+
- name: Deploy to GitHub Pages
126+
id: deployment
127+
uses: actions/deploy-pages@v2

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ cargo run -p revm --features ethersdb --example fork_ref_transact
6565
(If you want to add your project to the list, ping me or open the PR)
6666

6767

68+
# Documentation
69+
70+
To serve the mdbook documentation, ensure you have mdbook installed (if not install it with cargo) and then run:
71+
72+
```shell
73+
mdbook serve documentation
74+
```
75+
6876
# Contact
6977

7078
There is public telegram group: https://t.me/+Ig4WDWOzikA3MzA0

book.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
[book]
2-
authors = ["Colin, Waylon Jepsen"]
2+
authors = ["Colin Roberts, Waylon Jepsen"]
33
language = "en"
44
multilingual = false
55
src = "documentation/src"
66
title = "Rust EVM"
7+
8+
9+
[output.linkcheck]
10+
optional = true
11+
follow-web-links = true

crates/primitives/src/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub enum ExecutionResult {
3737
impl ExecutionResult {
3838
/// Returns if transaction execution is successful.
3939
/// 1 indicates success, 0 indicates revert.
40-
/// https://eips.ethereum.org/EIPS/eip-658
40+
/// <https://eips.ethereum.org/EIPS/eip-658>
4141
pub fn is_success(&self) -> bool {
4242
matches!(self, Self::Success { .. })
4343
}

crates/primitives/src/specification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(non_camel_case_types)]
22

33
/// SpecId and their activation block
4-
/// Information was obtained from: https://github.com/ethereum/execution-specs
4+
/// Information was obtained from: <https://github.com/ethereum/execution-specs>
55
#[repr(u8)]
66
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, enumn::N)]
77
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

crates/primitives/src/utilities.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,32 @@ pub fn create_address(caller: Address, nonce: u64) -> Address {
1717
pub fn create2_address(caller: Address, code_hash: B256, salt: U256) -> Address {
1818
caller.create2(salt.to_be_bytes::<32>(), code_hash)
1919
}
20+
21+
/// Serde functions to serde as [bytes::Bytes] hex string
22+
#[cfg(feature = "serde")]
23+
pub mod serde_hex_bytes {
24+
use alloc::string::{String, ToString};
25+
use serde::{Deserialize, Deserializer, Serializer};
26+
27+
pub fn serialize<S, T>(x: T, s: S) -> Result<S::Ok, S::Error>
28+
where
29+
S: Serializer,
30+
T: AsRef<[u8]>,
31+
{
32+
s.serialize_str(&alloc::format!("0x{}", hex::encode(x.as_ref())))
33+
}
34+
35+
pub fn deserialize<'de, D>(d: D) -> Result<bytes::Bytes, D::Error>
36+
where
37+
D: Deserializer<'de>,
38+
{
39+
let value = String::deserialize(d)?;
40+
if let Some(value) = value.strip_prefix("0x") {
41+
hex::decode(value)
42+
} else {
43+
hex::decode(&value)
44+
}
45+
.map(Into::into)
46+
.map_err(|e| serde::de::Error::custom(e.to_string()))
47+
}
48+
}

crates/revm/src/evm.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ use revm_precompile::Precompiles;
2525
/// want to update anything on it. It enabled `transact_ref` and `inspect_ref` functions
2626
/// * Database+DatabaseCommit allow directly committing changes of transaction. it enabled `transact_commit`
2727
/// and `inspect_commit`
28+
///
29+
/// /// # Example
30+
///
31+
/// ```
32+
/// # use revm::EVM; // Assuming this struct is in 'your_crate_name'
33+
/// # struct SomeDatabase; // Mocking a database type for the purpose of this example
34+
/// # struct Env; // Assuming the type Env is defined somewhere
35+
///
36+
/// let evm: EVM<SomeDatabase> = EVM::new();
37+
/// assert!(evm.db.is_none());
38+
/// ```
39+
///
2840
#[derive(Clone)]
2941
pub struct EVM<DB> {
3042
pub env: Env,

crates/revm/src/inspector/tracer_eip3155.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Inspector that support tracing of EIP-3155 https://eips.ethereum.org/EIPS/eip-3155
1+
//! Inspector that support tracing of EIP-3155 <https://eips.ethereum.org/EIPS/eip-3155>
22
33
use crate::inspectors::GasInspector;
44
use crate::interpreter::{CallInputs, CreateInputs, Gas, InstructionResult};

documentation/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
- [inner_models](./crates/interpreter/inner_models.md)
1313
- [instruction_result](./crates/interpreter/instruction_result.md)
1414
- [instructions](./crates/interpreter/instructions.md)
15-
- [Examples](./examples.md)
1615
- [Primitives](./crates/primitives.md)
1716
- [database](./crates/primitives/database.md)
1817
- [result](./crates/primitives/result.md)
@@ -32,3 +31,4 @@
3231
- [Identity function](./crates/precompile/identity.md)
3332
- [Modular Exponentiation](./crates/precompile/modexp.md)
3433
- [Secp256k1](./crates/precompile/secp256k1.md)
34+
- [Point Evaluation](./crates/precompile/point_evaluation.md)

documentation/src/crates/interpreter.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ The `interpreter` crate is concerned with the execution of the EVM opcodes and s
55
Modules:
66

77
- [gas](./interpreter/gas.md): This module deals with handling the gas mechanics in the EVM, such as calculating gas costs for operations.
8-
- [host](./interpreter/host.md): This module defines the `Host` trait, and any types or functions that the host machine (the machine running the EVM).
9-
- [inner_models](./interpreter/inner_models.md): Based on the name, this module could contain the inner data structures or models used in the EVM implementation.
10-
- [instruction_result](./interpreter/instruction_result.md): This module likely contains definitions related to the result of instruction execution.
11-
- [instructions](./interpreter/instructions.md): This module is expected to include the definitions of the EVM opcodes (instructions).
12-
- [interpreter](./interpreter/interpreter.md): This module would contain the Interpreter struct and related functionality for executing EVM instructions.
8+
- [host](./interpreter/host.md): This module defines the evm context `Host` trait.
9+
- [inner_models](./interpreter/inner_models.md): This module contains the inner data structures used in the EVM implementation.
10+
- [instruction_result](./interpreter/instruction_result.md): This module contains definitions related to the result of instruction execution.
11+
- [instructions](./interpreter/instructions.md): This module includes the definitions of the EVM opcodes (instructions).
12+
1313

1414
External Crates:
1515

@@ -18,9 +18,8 @@ External Crates:
1818

1919
Constants:
2020

21-
- `USE_GAS`: This constant determines whether gas measurement should be used. It's set to false if the no_gas_measuring feature is enabled.
21+
- `USE_GAS`: This constant determines whether gas measurement should be used. It's set to false if the `no_gas_measuring` feature is enabled.
2222

23-
Re-exported Types:
24-
Several types and functions are re-exported for easier access by users of this library, such as Gas, Host, InstructionResult, OpCode, Interpreter, Memory, Stack, and others. This allows users to import these items directly from the library root instead of from their individual modules.
25-
Re-exported Crate:
26-
revm_primitives: This crate is re-exported, likely providing primitive types or functionality used in the EVM implementation.
23+
Re-exports:
24+
- Several types and functions are re-exported for easier access by users of this library, such as `Gas`, `Host`, `InstructionResult`, `OpCode`, `Interpreter`, `Memory`, `Stack`, and others. This allows users to import these items directly from the library root instead of from their individual modules.
25+
- revm_primitives: This crate is re-exported, providing primitive types or functionality used in the EVM implementation.

0 commit comments

Comments
 (0)