Skip to content

[executor] PROTOCOL_VENUS = 3 duplicated from Solidity — no link; silent mismatch on refactor #164

@obchain

Description

@obchain

PR: #41 (feat/executor: transaction builder + eth_call simulator)
File: crates/charon-executor/src/builder.rs — const PROTOCOL_VENUS: u8 = 3
Refs #41

Problem

builder.rs defines:

const PROTOCOL_VENUS: u8 = 3;

CharonLiquidator.sol defines:

uint8 internal constant PROTOCOL_VENUS = 3;

The selector pin test validates the ABI function selector (the tuple shape), not the protocolId field value. If the Solidity constant is renumbered during a refactor, the Rust encoder silently writes the old value. The contract branch:

if (params.protocolId != PROTOCOL_VENUS) revert UnsupportedProtocol(params.protocolId);

will fire on every call. The simulation gate will catch this (every sim returns Err) and no funds are lost, but all opportunities are silently dropped until the constant is manually re-synced.

Fix

Add a unit test that ABI-decodes the output of encode_calldata and asserts the protocolId byte equals 3 explicitly:

#[test]
fn encode_calldata_protocol_id_equals_venus_constant() {
    let builder = TxBuilder::new(mk_signer(), 56, address!("ff...ff"));
    let bytes = builder.encode_calldata(&mk_opportunity(), &mk_params()).unwrap();
    // uint8 is right-padded to 32 bytes; last byte of first word after selector
    let protocol_id = bytes[4 + 31];
    assert_eq!(protocol_id, 3u8, "protocolId must equal PROTOCOL_VENUS in CharonLiquidator.sol");
}

Add a comment on the Rust constant referencing contracts/src/CharonLiquidator.sol and the line number so future maintainers know where to sync.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglayer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p1-coreCore MVP scopestatus:readyScoped and ready to pick up

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions