Skip to content

Commit

Permalink
Merge branch 'main' into feat/solidity-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/edr-ci.yml
#	crates/edr_napi/package.json
  • Loading branch information
agostbiro committed Sep 26, 2024
2 parents 2c76000 + 2c2c78b commit c679b68
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 65 deletions.
31 changes: 23 additions & 8 deletions .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
name: Setup rust
description: Sets up rust
name: Setup Rust
description: Sets up Rust
inputs:
toolchain:
description: The Rust toolchain to use
required: false
components:
description: Comma-separated list of components to install
required: false

runs:
using: composite
steps:
- name: Install Rust (stable)
uses: actions-rs/toolchain@v1
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
profile: minimal
override: true

- uses: Swatinem/rust-cache@v2
# Empty string means rust-toolchain if it exists, otherwise stable
toolchain: ${{ inputs.toolchain }}
components: ${{ inputs.components }}
cache: true
# Do not override the RUSTFLAGS by default and instead do that per job,
# if needed. Setting RUSTFLAGS via env var, config, etc. is mutually
# exclusive and often a source of bugs.
# Empty string here means no override.
rustflags: ""
# By default, we do not override the toolchain from rust-toolchain.
# The user needs to explicitly use `<cmd> +<toolchain>` for clarity.
override: false
46 changes: 10 additions & 36 deletions .github/workflows/edr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ jobs:
- uses: taiki-e/install-action@cargo-hack

- name: Cargo check no default features for all crates
uses: actions-rs/cargo@v1
with:
command: check
args: --all --no-default-features
run: cargo check --all --no-default-features

- name: Cargo hack for EDR crates
run: |
Expand Down Expand Up @@ -59,25 +56,16 @@ jobs:
key: edr-rs-rpc-cache-v1

- name: Build cargo tests
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --all-targets --all-features --no-run
run: cargo test --workspace --all-targets --all-features --no-run

- name: Run cargo test
uses: actions-rs/cargo@v1
env:
ALCHEMY_URL: ${{ secrets.ALCHEMY_URL }}
INFURA_URL: ${{ secrets.INFURA_URL }}
with:
command: test
args: --workspace --all-targets --all-features
run: cargo test --workspace --all-targets --all-features

- name: Doctests
uses: actions-rs/cargo@v1
with:
command: test
args: --doc --workspace --features tracing
run: cargo test --doc --workspace --features tracing

# disable until:
# 1) https://github.com/napi-rs/napi-rs/issues/1405 is resolved (Windows-only)
Expand All @@ -89,43 +77,29 @@ jobs:
# uses: taiki-e/install-action@nextest

# - name: Test with latest nextest release
# uses: actions-rs/cargo@v1
# env:
# CARGO_INCREMENTAL: ${{ matrix.CARGO_INCREMENTAL }}
# ALCHEMY_URL: ${{ secrets.ALCHEMY_URL }}
# with:
# command: nextest
# args: run --workspace --all-features --all-targets
# run: cargo nextest run --workspace --all-features --all-targets

edr-style:
name: Check EDR Style
runs-on: ubuntu-latest
needs: check-edr
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust
with:
components: clippy

- name: Install nightly rustfmt
uses: actions-rs/toolchain@v1
uses: ./.github/actions/setup-rust
with:
toolchain: nightly
profile: minimal
components: rustfmt

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
components: clippy

- uses: Swatinem/rust-cache@v2

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
toolchain: nightly
command: fmt
args: --all --check
run: cargo +nightly fmt --all --check

- name: Run cargo clippy
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/test-recent-mainnet-block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ jobs:
**/edr-cache
key: test-recent-mainnet-block-rpc-cache-v1

- name: Run test
uses: actions-rs/cargo@v1
with:
command: replay-block
args: -u ${{ secrets.ALCHEMY_URL }} -c 1
- run: cargo replay-block -u ${{ secrets.ALCHEMY_URL }} -c 1

- name: Notify failures
if: failure()
Expand Down
14 changes: 2 additions & 12 deletions .github/workflows/test-recent-optimism-block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ jobs:
with:
ref: feat/multichain

- name: Install Rust (stable)
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true

- uses: Swatinem/rust-cache@v2
- uses: ./.github/actions/setup-rust

- name: Cache EDR RPC cache
uses: actions/cache@v4
Expand All @@ -29,11 +23,7 @@ jobs:
**/edr-cache
key: test-recent-optimism-block-rpc-cache-v1

- name: Run test
uses: actions-rs/cargo@v1
with:
command: replay-block
args: -u ${{ secrets.ALCHEMY_URL }} -c optimism
- run: cargo replay-block -u ${{ secrets.ALCHEMY_URL }} -c optimism

- name: Notify failures
if: failure()
Expand Down
7 changes: 7 additions & 0 deletions crates/edr_napi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @nomicfoundation/edr

## 0.6.2

### Patch Changes

- af56289: fix(tracing): Decode unmapped instructions only at the opcode boundary
- debac88: fix(tracing): Use correct subtrace when detecting error error propagation across delegatecall

## 0.6.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion crates/edr_napi/src/trace/error_inferrer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ impl ErrorInferrer {
_ => return Ok(false),
};

let inst = subtrace_bytecode.get_instruction(step.pc)?;
let inst = bytecode.get_instruction(step.pc)?;

// All the remaining locations should be valid, as they are part of the inline
// asm
Expand Down
40 changes: 37 additions & 3 deletions crates/edr_solidity/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ fn uncompress_sourcemaps(compressed: &str) -> Vec<SourceMap> {
}

fn add_unmapped_instructions(instructions: &mut Vec<Instruction>, bytecode: &[u8]) {
let last_instr_pc = instructions.last().map_or(0, |instr| instr.pc);

let mut bytes_index = (last_instr_pc + 1) as usize;
let mut bytes_index = instructions.last().map_or(0, |instr| {
// On the odd chance that the last instruction is a PUSH, we make sure
// to include any immediate data that might be present.
instr.pc as usize + 1 + instr.opcode.info().immediate_size() as usize
});

while bytecode.get(bytes_index) != Some(OpCode::INVALID.get()).as_ref() {
let opcode = OpCode::new(bytecode[bytes_index]).expect("Invalid opcode");
Expand Down Expand Up @@ -207,3 +209,35 @@ pub fn decode_instructions(

instructions
}

#[cfg(test)]
mod tests {
use edr_evm::interpreter::opcode;

use super::*;

#[test]
fn unmapped_instruction_opcode_boundary() {
let bytecode = &[opcode::PUSH2, 0xde, 0xad, opcode::STOP, opcode::INVALID];

let mut instructions = vec![Instruction {
pc: 0,
opcode: OpCode::PUSH2,
jump_type: JumpType::NotJump,
push_data: Some(vec![0xde, 0xad]),
location: None,
}];

// Make sure we start decoding from opcode::STOP rather than from inside
// the push data.
add_unmapped_instructions(&mut instructions, bytecode);

assert!(matches!(
instructions.last(),
Some(Instruction {
opcode: OpCode::STOP,
..
})
));
}
}

0 comments on commit c679b68

Please sign in to comment.