// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
import {CairoLib} from "kakarot-lib/CairoLib.sol";
using CairoLib for uint256;
contract EthStarknetBridge {
/// @dev The cairo contract to call
uint256 constant starknetEth = 0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7;
uint256 constant TRANSFER_SELECTOR = uint256(keccak256("transfer")) % 2 ** 250;
/// @notice Sends ETH to a Starknet address
/// @param toStarknetAddress The Starknet address to send ETH to
function transfer(uint256 toStarknetAddress) external payable {
_transfer(toStarknetAddress, msg.value);
}
/// @notice Calls the Eth Cairo contract
/// @param toStarknetAddress The Starknet address to send ETH to
/// @param amount The amount of ETH to send
function _transfer(uint256 toStarknetAddress, uint256 amount) private {
// Split amount in [low, high]
uint128 amountLow = uint128(amount);
uint128 amountHigh = uint128(amount >> 128);
uint256[] memory transferCallData = new uint256[](3);
transferCallData[0] = toStarknetAddress;
transferCallData[1] = uint256(amountLow);
transferCallData[2] = uint256(amountHigh);
starknetEth.delegatecallCairo(TRANSFER_SELECTOR, transferCallData);
}
}
as the msg.value was sent 2 times. It's actually the intended behavior as:
msg.value sends ETH to the contract
delegatecallCairo sends ETH from the caller of transfer
Feature Request
Describe the Feature Request
The following snippet surprised me first
as the
msg.value
was sent 2 times. It's actually the intended behavior as:msg.value
sends ETH to the contractdelegatecallCairo
sends ETH from the caller oftransfer
This is however worth noticing in the doc