Skip to content

feat(ethexe/contracts): add fee for upload code, add method for withdrawing exec balance#5280

Open
StackOverflowExcept1on wants to merge 8 commits intomasterfrom
av/ethexe-contracts-upload-code-fee-and-withdraw-erc20
Open

feat(ethexe/contracts): add fee for upload code, add method for withdrawing exec balance#5280
StackOverflowExcept1on wants to merge 8 commits intomasterfrom
av/ethexe-contracts-upload-code-fee-and-withdraw-erc20

Conversation

@StackOverflowExcept1on
Copy link
Copy Markdown
Member

No description provided.

@StackOverflowExcept1on StackOverflowExcept1on self-assigned this Apr 3, 2026
@StackOverflowExcept1on StackOverflowExcept1on added A0-pleasereview PR is ready to be reviewed by the team D8-ethexe ethexe-related PR labels Apr 3, 2026
@semanticdiff-com
Copy link
Copy Markdown

semanticdiff-com bot commented Apr 3, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  ethexe/ethereum/abi/WrappedVara.json  100% smaller
  ethexe/ethereum/abi/BatchMulticall.json  100% smaller
  ethexe/ethereum/abi/POAMiddleware.json  99% smaller
  ethexe/ethereum/abi/Middleware.json  99% smaller
  ethexe/ethereum/abi/DemoCaller.json  98% smaller
  ethexe/ethereum/abi/Gear.json  96% smaller
  ethexe/ethereum/abi/Mirror.json  96% smaller
  ethexe/ethereum/src/router/mod.rs  14% smaller
  ethexe/contracts/foundry.lock Unsupported file format
  ethexe/contracts/src/IRouter.sol Unsupported file format
  ethexe/contracts/src/Router.sol Unsupported file format
  ethexe/contracts/src/libraries/Gear.sol Unsupported file format
  ethexe/contracts/test/POC.t.sol Unsupported file format
  ethexe/ethereum/abi/Router.json Unsupported file format
  ethexe/ethereum/src/deploy.rs  0% smaller
  ethexe/sdk/src/router.rs  0% smaller

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the router contract by introducing a fee mechanism for code validation to cover operational costs. It also adds administrative capabilities for balance management and updates the infrastructure to track network gas prices, ensuring that validation requests are properly incentivized and funded.

Highlights

  • Validation Fee Implementation: Introduced a mandatory fee for code validation requests, calculated based on the latest gas price and a fixed commitment gas constant.
  • Executable Balance Management: Added a new administrative function to withdraw the contract's accumulated executable balance.
  • Gas Price Tracking: Implemented automatic tracking of the latest Ethereum gas price within the router contract to facilitate accurate fee calculations.
Ignored Files
  • Ignored by pattern: ethexe/ethereum/abi/*.json (7)
    • ethexe/ethereum/abi/BatchMulticall.json
    • ethexe/ethereum/abi/DemoCaller.json
    • ethexe/ethereum/abi/Middleware.json
    • ethexe/ethereum/abi/Mirror.json
    • ethexe/ethereum/abi/POAMiddleware.json
    • ethexe/ethereum/abi/Router.json
    • ethexe/ethereum/abi/WrappedVara.json
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a dynamic gas pricing mechanism for code validation within the ethexe router, requiring a fee based on the network's latest gas price, and adds an owner-only function to withdraw WrappedVara. Key feedback points out that the withdrawal logic risks depleting reward funds, and the gas price update mechanism is incomplete as it lacks the documented periodic updates during batch commitments. Furthermore, the Rust client contains a potential integer overflow in fee calculations and uses discouraged error handling patterns, while the contract's strict fee equality and hardcoded deployment gas limits are noted as fragile.

Comment on lines +297 to +305
function withdrawExecutableBalance() external onlyOwner {
IERC20 _wrappedVara = IERC20(wrappedVara());

uint256 value = _wrappedVara.balanceOf(address(this));
require(value > 0, ZeroValueTransfer());

bool success = _wrappedVara.transfer(msg.sender, value);
require(success, WithdrawExecutableBalanceFailed());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The withdrawExecutableBalance function withdraws the entire WrappedVara balance of the Router contract. However, the Router also holds WrappedVara intended for rewards distribution (see _commitRewards at line 512). Withdrawing the full balance will cause rewards commitments to fail due to insufficient funds. Consider tracking the 'executable balance' separately or allowing withdrawal of only a specific amount.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we currently do not use _commitRewards at production

Comment thread ethexe/contracts/src/Router.sol
Comment thread ethexe/contracts/src/IRouter.sol Outdated
Comment thread ethexe/contracts/src/Router.sol Outdated
Comment thread ethexe/ethereum/src/deploy.rs Outdated
Comment thread ethexe/ethereum/src/router/mod.rs
// keccak256(abi.encode(uint256(keccak256("router.storage.Transient")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant TRANSIENT_STORAGE = 0xf02b465737fa6045c2ff53fb2df43c66916ac2166fa303264668fb2f6a1d8c00;

uint256 public constant CODE_COMMITMENT_GAS = 13_551;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

from benchmarks PR

@grishasobol
Copy link
Copy Markdown
Member

@claude review

@claude
Copy link
Copy Markdown

claude bot commented Apr 3, 2026

Claude finished @grishasobol's task in 1m 17s —— View job


Code Review

  • Gathering context
  • Reading changed files
  • Analyzing code
  • Posting review

This PR adds a mandatory fee for requestCodeValidation (paid in ETH, forwarded to the owner) and a withdrawExecutableBalance function to drain the Router's WVara balance. Here's my review:

ethexe/contracts/src/Router.sol

requestCodeValidation — fee forwarded to owner (Router.sol:333)

The fee is collected via owner().call{value: msg.value}("") with a low-level call. This works but has a subtle issue: if the owner is a contract with a complex receive(), the call could fail or reenter. Using Address.sendValue from OpenZeppelin (which already exists as a dependency) would be more idiomatic. That said, the PayValidationFeeFailed error would catch a revert.

requestCodeValidation>= vs == for fee check (Router.sol:327)

Currently uses >= (after the "fix review" commit). This is better than strict equality — it avoids unnecessary reverts when gas price increases between query and submission. Any excess is also forwarded to the owner, which is reasonable.

latestGasPrice initialization only in lookupGenesisHash (Router.sol:318)

The latestGasPrice is set to tx.gasprice in lookupGenesisHash, and updated again in commitBatch (line 407). The interface comment IRouter.sol:29 says it "changes every batch commitment" — which is now correct, since commitBatch (line 407) does update it. This is fine.

withdrawExecutableBalance — drains entire WVara balance (Router.sol:297-305)

As noted by Gemini, this drains the full WVara balance. The PR author clarified that _commitRewards is not used in production. However, the WVara balance can also be received from Mirror.performStateTransition (via _commitTransitions), which is in active use. If programs send value back to the Router through state transitions, that WVara is also being withdrawn here. This should be understood and documented — or the function should accept a uint256 amount parameter to allow partial withdrawal. As-is, it's an atomic admin escape hatch, which may be intentional.

CODE_COMMITMENT_GAS constant (Router.sol:36)

The value 13_551 with the comment "from benchmarks PR" is a magic constant with no further documentation in-line. A brief comment explaining what it represents (e.g., estimated gas cost of processing one code commitment on-chain) would help reviewers understand why this number.

ethexe/ethereum/src/router/mod.rs

Potential overflow in fee calculation (mod.rs:155)

(code_commitment_gas * latest_gas_price)
    .try_into()
    .expect("infallible")

Both code_commitment_gas and latest_gas_price are u128. Their product could overflow u128 if latest_gas_price is very large (though in practice, gas prices in wei are much smaller). The try_into() converts to U256 (alloy type), which won't overflow. The multiplication itself could overflow u128, but realistically 13_551 * gas_price_in_gwei * 1e9 stays well within u128 range. Still, the .expect("infallible") comment on try_into() is misleading — the conversion from u128 to alloy's U256 is genuinely infallible, but the multiplication is the hidden risk. A comment would help clarify.

latest_gas_price return type change (mod.rs:677-682)

Changed from u64 to u128. This makes sense given latest_gas_price is in wei and can exceed u64::MAX on some chains in extreme conditions. The change is correct.

ethexe/ethereum/src/deploy.rs

Hardcoded gas limit for lookupGenesisHash (deploy.rs:210)

.gas(100_000) // fixes out of gas error for unknown reason

This is a known workaround with an unexplained root cause. The gas now being written to protocolData.latestGasPrice (a new storage slot write from cold) in lookupGenesisHash is likely the cause — cold SSTORE costs 20,000 gas on EVM, and the auto-estimation may not account for it in the test harness. If that's the reason, it would be worth documenting. This only affects the test deployer, not production usage.

ethexe/sdk/src/router.rs

Type change from u64 to u128 (sdk/src/router.rs:198)

API-breaking change for SDK consumers. Fine if this is an early-stage API.

Summary

Overall the PR is straightforward and correct for its stated purpose. Key items to consider:

  1. withdrawExecutableBalance — consider whether partial withdrawal (amount parameter) is needed, and whether the function name correctly reflects intent (it drains all WVara, not just "executable balance").
  2. deploy.rs gas override — should have a comment explaining why the extra gas is needed (cold SSTORE for latestGasPrice).
  3. CODE_COMMITMENT_GAS constant — could use a brief inline comment explaining its derivation.

@grishasobol grishasobol requested review from ecol-master and removed request for grishasobol April 6, 2026 14:13
@grishasobol grishasobol added this to the Reviews till 8 April 2026 milestone Apr 6, 2026
// Private implementation details
impl EthereumDeployer {
/// Fixes "out of gas" error for unknown reason, maybe need to report to alloy?
const LOOKUP_GENESIS_HASH_GAS: u64 = 100_000;
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.

Yes, make sense, I don't find similar issues alloy repo right now.

But, I guess, it happens, because we use the nightly build of foundry (maybe I am wrong)

Copy link
Copy Markdown
Member

@breathx breathx left a comment

Choose a reason for hiding this comment

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

I don’t see any need to store or update the gas price, since we won’t be converting it directly, either now or in the future.

Moreover, the withdrawal of exec balances is high risk operation since it could brake further committing logic so I'd keep it in upcoming commitments reward.

Fee for code uploading should be charged in WVARA with some constant value that could be updated on migrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A0-pleasereview PR is ready to be reviewed by the team D8-ethexe ethexe-related PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants