Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: update doc [2] #1363

Open
ClementWalter opened this issue Aug 26, 2024 · 2 comments
Open

doc: update doc [2] #1363

ClementWalter opened this issue Aug 26, 2024 · 2 comments

Comments

@ClementWalter
Copy link
Member

ClementWalter commented Aug 26, 2024

Feature Request

What

General update, and especially this:

The following snippet surprised me first

// 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

This is however worth noticing in the doc

How

PR in https://github.com/kkrt-labs/kakarot-docs

@ShantelPeters

This comment was marked as abuse.

Copy link

onlydustapp bot commented Aug 27, 2024

Hey @ShantelPeters!
Thanks for showing interest.
We've created an application for you to contribute to Kakarot zkEVM.
Go check it out on OnlyDust!

@ClementWalter ClementWalter moved this from 🆕 Backlog to 📅 Next sprint in Kakarot's Project Management Oct 25, 2024
@ClementWalter ClementWalter changed the title doc: beware of the usage of msg.value and delegatecallCairo doc: update doc Oct 25, 2024
@ClementWalter ClementWalter changed the title doc: update doc doc: update doc [2] Oct 25, 2024
matthieuauger pushed a commit to matthieuauger/kakarot that referenced this issue Nov 9, 2024
* fix: check whitelisted tx

* feat: unit test toTypedEthTx with hash not whitelisted

* fix: WHITE_LISTED_EIP_155_TRANSACTION_HASHES indexer env

* fix: custom error for v !== 27 and v!==28

* fix: fmt

* fix: remove WHITE_LISTED_EIP_155_TRANSACTION_HASHES check

* fix: remove WHITE_LISTED_EIP_155_TRANSACTION_HASHES

* fix: error message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔖 Current sprint
Development

No branches or pull requests

2 participants