Skip to content

Use serde without std if not needed#98

Closed
vlad9486 wants to merge 2 commits intomasterfrom
v2.1.3-serde-no-std
Closed

Use serde without std if not needed#98
vlad9486 wants to merge 2 commits intomasterfrom
v2.1.3-serde-no-std

Conversation

@vlad9486
Copy link
Copy Markdown

@vlad9486 vlad9486 commented Nov 24, 2025

In order to use the crate with serde in the smart contract, prevent unwanted std from being pulled.

Summary by CodeRabbit

  • Chores

    • Updated Rust toolchain to 1.82.0
    • Bumped workspace package version to 2.1.4
    • Adjusted dependency settings for serde to improve compatibility
  • Refactor

    • Refined internal hash/digest handling for improved stability and consistency

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 24, 2025

Walkthrough

Dependency and toolchain updates plus systematic refactoring of Keccak256 digest conversions to explicitly convert digests to [u8; 32] before making H256. Serde is set with default-features = false; Rust toolchain bumped from 1.81.0 to 1.82.0.

Changes

Cohort / File(s) Summary
Dependency & Toolchain Configuration
Cargo.toml, rust-toolchain.toml
Serde dependency updated to include default-features = false while keeping features = ["derive"]. Workspace package version bumped 2.1.32.1.4. Rust toolchain updated from 1.81.01.82.0.
Keccak256 Digest Type Conversions
evm/src/executor/stack/executor.rs, evm/src/runtime/eval/system.rs
Replaced uses of H256::from_slice(Keccak256::digest(x).as_slice()) with H256::from_slice(<[u8; 32]>::from(Keccak256::digest(x)).as_slice()) across create/create2, legacy create address computation, code_hash retrieval, and sha3. No control-flow or API changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Changes are repetitive but touch runtime/executor code; verify correct byte-order and conversions in:
    • evm/src/executor/stack/executor.rs
    • evm/src/runtime/eval/system.rs
  • Confirm workspace Cargo.toml version and serde feature semantics.

Suggested reviewers

  • aleksuss

Poem

🐰 I nibbled bytes in moonlit labs tonight,

From slices to arrays — tidy and bright,
Keccak curled snug in a thirty-two bed,
Serde trimmed sails as the toolchain sped,
Hops of type-safety, a rabbit's delight.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: disabling serde's default features to avoid std inclusion, which aligns with the Cargo.toml modifications and PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v2.1.3-serde-no-std

Comment @coderabbitai help to get the list of available commands and usage tips.

@vlad9486 vlad9486 force-pushed the v2.1.3-serde-no-std branch from dc240d3 to a5e899f Compare November 24, 2025 08:08
@vlad9486 vlad9486 changed the title (fix): use serde without std Use serde without std if not needed Nov 24, 2025
@vlad9486 vlad9486 marked this pull request as ready for review November 24, 2025 09:54
@vlad9486 vlad9486 requested a review from mrLSD November 24, 2025 11:29
@mrLSD mrLSD added this to the v2.1.4 milestone Nov 24, 2025
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5e899f and 686df5d.

📒 Files selected for processing (1)
  • Cargo.toml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: ethereum-tests-32-bit
  • GitHub Check: unit-tests-32-bit
  • GitHub Check: ethereum-tests
🔇 Additional comments (1)
Cargo.toml (1)

11-11: Version bump to 2.1.4 is appropriate.

Incrementing the patch version from 2.1.3 to 2.1.4 correctly reflects this dependency configuration fix. This is a non-breaking change for users and aligns with semantic versioning.

Comment thread Cargo.toml
rlp = { version = "0.6", default-features = false, features = ["derive"] }
sha3 = { version = "0.10", default-features = false }
serde = { version = "1.0", features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

No-std compatibility: serde now excludes std by default.

Adding default-features = false to serde prevents the standard library from being pulled into smart contract builds while preserving the derive feature for macros. This aligns with the project's no-std support declaration and the existing pattern used for other dependencies (e.g., rlp, sha3, primitive-types).

Verify that the derive feature alone is sufficient for all serde usage across the codebase. Specifically, confirm that no code relies on serde's alloc or std features. Run the following to identify potential gaps:


🏁 Script executed:

#!/bin/bash
# Search for serde feature attributes or conditional compilation that might expect std
rg -n "serde.*std|#\[cfg.*serde" --type rust

Length of output: 1199


🏁 Script executed:

#!/bin/bash
# 1. Check if 'with-serde' feature is defined in Cargo.toml
echo "=== Checking for 'with-serde' feature in Cargo.toml ==="
rg -n "with-serde|features\s*=" Cargo.toml | head -20

# 2. Search for direct serde::ser or serde::de calls (runtime serialization)
echo -e "\n=== Searching for runtime serde usage (ser/de calls) ==="
rg -n "serde::(ser|de)::|\.serialize\(|\.deserialize\(" --type rust | head -20

# 3. Check if any code directly imports serde types beyond derive
echo -e "\n=== Checking for direct serde type imports ==="
rg -n "use serde::" --type rust

Length of output: 4470


🏁 Script executed:

#!/bin/bash
# 1. Get full Cargo.toml to see feature definitions
echo "=== Full Cargo.toml contents ==="
cat Cargo.toml

# 2. Check if evm-tests is a dev-dependency or separate crate
echo -e "\n=== Cargo.toml workspace members ==="
rg -n "\[workspace\]|\[\[bin\]\]|members\s*=" Cargo.toml | head -20

# 3. Check evm-tests/Cargo.toml to see its own serde dependency
echo -e "\n=== evm-tests serde configuration ==="
find . -name Cargo.toml -path "*/evm-tests/*" -o -path "*/evm-tests/Cargo.toml" | head -5

Length of output: 1116


🏁 Script executed:

#!/bin/bash
# 1. Check evm-tests/jsontests/Cargo.toml dependencies
echo "=== evm-tests/jsontests/Cargo.toml ==="
cat evm-tests/jsontests/Cargo.toml

# 2. Check evm/Cargo.toml for serde usage
echo -e "\n=== evm/Cargo.toml ==="
cat evm/Cargo.toml

# 3. Check evm-tests/ethjson/Cargo.toml if it exists
echo -e "\n=== evm-tests/ethjson/Cargo.toml ==="
if [ -f evm-tests/ethjson/Cargo.toml ]; then
  cat evm-tests/ethjson/Cargo.toml
else
  echo "File not found"
fi

Length of output: 2579


Serde configuration introduces compilation failure: workspace dependency missing required "std" feature.

The root workspace now provides serde with only the derive feature, but evm/Cargo.toml attempts to enable serde/std when the std feature is activated (line in evm's feature definition). This creates an unsatisfiable dependency.

Fix required:

Add "std" to serde features in workspace Cargo.toml line 25:

serde = { version = "1.0", default-features = false, features = ["derive", "std"] }

This maintains no-std compatibility for environments that don't use the std feature while allowing standard library usage when needed.

🤖 Prompt for AI Agents
In Cargo.toml around line 25, the workspace serde declaration disables default
features but only enables "derive", which conflicts with evm/Cargo.toml's
optional use of serde with the "std" feature; update the workspace serde
features to include "std" in addition to "derive" so that enabling std in
subcrates can satisfy the dependency (i.e., add "std" to the features list for
serde in the workspace Cargo.toml).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aleksuss what do you think?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check evm/Cargo.toml to verify serde/std feature usage
echo "=== evm/Cargo.toml contents ==="
cat evm/Cargo.toml

# Also check for any feature definitions that enable serde/std
echo -e "\n=== Checking for serde feature usage in evm crate ==="
rg -n 'serde.*std|features.*=.*\[.*"std"' evm/Cargo.toml

Length of output: 1461


@aleksuss Thank you for confirming! I can see that evm/Cargo.toml line 38 does try to enable serde/std when the std feature is active.

However, I want to flag a potential concern with the suggested fix: adding "std" to the workspace serde features list would enable std unconditionally, which would defeat the purpose of this PR (enabling serde usage without std in smart contracts).

# This would ALWAYS enable std:
serde = { version = "1.0", default-features = false, features = ["derive", "std"] }

Could you verify if there's an actual compilation error with the current configuration? The pattern used here (workspace with default-features = false, subcrate enabling features via feature flags) is the same pattern used successfully for other dependencies like sha3, rlp, and primitive-types.

If there is a compilation error, consider these alternatives:

  1. Specify serde features in the subcrate directly instead of in the workspace
  2. Make serde non-workspace dependency in evm/Cargo.toml to have full control
  3. Verify the Rust/Cargo version supports this pattern (current toolchain is 1.82.0)

Would you like me to help investigate further or test a different approach?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would pass the features in the member crates only. In the workspace Cargo.toml I would use:

serde = { version = "1.0", default-features = false }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. FYI: @vlad9486

@mrLSD mrLSD requested a review from aleksuss November 24, 2025 16:45
@mrLSD
Copy link
Copy Markdown
Member

mrLSD commented Dec 19, 2025

Managed in #95

@mrLSD mrLSD closed this Dec 19, 2025
@mrLSD mrLSD removed this from the v2.1.4 milestone Dec 19, 2025
@mrLSD mrLSD deleted the v2.1.3-serde-no-std branch February 4, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants