Skip to content

runtime: solc toolchain + ERC-20 integration test (closes #52)#63

Merged
proofmancer merged 2 commits into
mainfrom
runtime/solidity-toolchain
May 25, 2026
Merged

runtime: solc toolchain + ERC-20 integration test (closes #52)#63
proofmancer merged 2 commits into
mainfrom
runtime/solidity-toolchain

Conversation

@proofmancer
Copy link
Copy Markdown
Member

Closes #52.

Real Solidity contracts now run end-to-end on chains built with Cleave. Compile with the real solc, deploy via Evm::deploy, call standard ERC-20 functions via ABI-encoded calldata. Removes the "v0.3 EVM engine accepts raw bytecode only" caveat from the runtime README.

What landed

Solidity fixture

runtime/tests/fixtures/MiniERC20.sol: minimal ERC-20 with balanceOf, transfer, totalSupply, and a constructor that mints initial supply to the deployer. ~30 lines, no allowance / approve / events (kept narrow to focus on proving the pipeline works).

Integration test (runtime/tests/solidity.rs)

  • Shells out to solc --bin --optimize and parses the textual output for the named contract's deployment bytecode
  • Hand-rolled ABI encoding for the four selectors the test uses:
    • balanceOf(address) -> 0x70a08231
    • transfer(address,uint256) -> 0xa9059cbb
    • totalSupply() -> 0x18160ddd
  • Constructor args appended to the deployment bytecode (standard Solidity ABI for constructor(uint256))
  • 2 tests:
    • erc20_deploys_and_transfers: deploys with 1M supply -> alice has 1M, bob has 0 -> alice transfers 100 to bob -> alice has 999_900, bob has 100
    • erc20_transfer_reverts_when_insufficient_balance: bob (zero balance) transfers 1 -> revert
  • Skips cleanly if solc is not on PATH (same pattern as the cleavec-dependent end-to-end test)

CI

apt-get install solc added to the runtime job. Every PR now exercises real Solidity compilation in CI.

Docs

Runtime README:

  • Solidity workflow documented (compile with solc, paste hex bytecode, run)
  • "ERC-20 / standard Solidity contract deployment via solc toolchain" removed from "what this runtime does not yet do"

End-to-end demo

// runtime/tests/solidity.rs::erc20_deploys_and_transfers
let bytecode = compile_contract(&erc20_source(), "MiniERC20")?;
let deploy_calldata = encode_deploy_call(bytecode, U256::from(1_000_000u64));

let mut evm = Evm::new();
evm.fund(alice, U256::from(10_000_000_000_000_000_000u128));
let contract = evm.deploy(alice, deploy_calldata)?;

let balance = evm.call(alice, contract, encode_balance_of(alice))?;
assert_eq!(decode_u256(&balance), U256::from(1_000_000u64));

evm.call(alice, contract, encode_transfer(bob, U256::from(100u64)))?;

let alice_after = evm.call(alice, contract, encode_balance_of(alice))?;
let bob_after = evm.call(alice, contract, encode_balance_of(bob))?;
assert_eq!(decode_u256(&alice_after), U256::from(999_900u64));
assert_eq!(decode_u256(&bob_after), U256::from(100u64));

Local run on Apple M3 Pro:

$ cargo test --release --test solidity
test erc20_deploys_and_transfers ... ok
test erc20_transfer_reverts_when_insufficient_balance ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; finished in 0.06s

What this PR does NOT yet do

  • ERC-20 bench: deferred. The bench harness would either pre-compile bytecode to a const or invoke solc on every run; both add complexity. The integration test proves correctness; bench can come when we have a use for per-call ERC-20 throughput numbers.
  • JSON-RPC layer: still on the "what this runtime does not yet do" list. Solidity tools (foundry, hardhat) expect eth_sendRawTransaction / eth_call; we haven't built that adapter.
  • alloy-sol-types: the test hand-rolls 4 selectors. Bringing in a generic ABI encoder is a 200-crate dependency vs ~30 lines of hand-rolling. Worth revisiting if the Solidity test surface grows past 5-10 selectors.
  • Foundry / Hardhat integration: out of scope. Foundry users can forge build then cleave-run --evm <hex> if they want; tighter integration is a future tooling PR.

What unblocks next

@proofmancer proofmancer merged commit c513bc7 into main May 25, 2026
2 checks passed
@proofmancer proofmancer deleted the runtime/solidity-toolchain branch May 25, 2026 15:42
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.

Solidity toolchain integration: solc pipeline + ERC-20 deploy test

1 participant