foundry-rs / foundry-rs/foundry

bug(tracing): Forge test do not show decoded events when emitting events using inline assembly

Open
#10,451 5 comments 0 reactions 0 assignees View on GitHub
A-tracing C-forge T-bug
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
18h 20m
Merged PRs (30d)
510

Description

### Component

Forge

### Have you ensured that all of these are up to date?

- [ ] Foundry
- [x] Foundryup

### What version of Foundry are you on?

forge Version: 1.0.0-v1.0.0

### What version of Foundryup are you on?

foundryup: 1.1.0

### What command(s) is the bug in?

forge test

### Operating System

None

### Describe the bug

I used the below snippet to emit events:
```
event Exchange(bytes swapResult);

function emitExchange(
address pool,
address tokenIn,
address tokenOut,
uint256 amountIn,
uint256 amountOut
) internal {
assembly ("memory-safe") {
// Get a pointer to some free memory.
let fmp := mload(0x40)

// Write the data into memory in reverse order because we are packing it into 92 bytes.
// We will use 32 + 20 + 20 + 16 + 16 = 104 bytes of memory.
mstore(add(fmp, 72), amountOut) // 104 - 32 = 72
mstore(add(fmp, 56), amountIn) // 72 - 16 = 56
mstore(add(fmp, 40), tokenOut) // 56 - 16 = 40
mstore(add(fmp, 20), tokenIn) // 40 - 20 = 20
mstore(fmp, pool) // 20 - 20 = 0

// Emit the event.
// The actual data is starting from fmp + 12
log1(add(fmp, 12), 92, EXCHANGE_EVENT_SELECTOR)

// Now clean the memory we used
mstore(fmp, 0)
mstore(add(fmp, 0x20), 0)
mstore(add(fmp, 0x40), 0)
mstore(add(fmp, 0x60), 0)
}
}
```

When running tests, instead of showing `emit Exchange(...)`, it showed:

Image

And for some places, it showed:

Image

I checked the logs from the test transaction using `vm.recordLogs` and confirmed that all the logs are correct.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.