Giter Club home page Giter Club logo

Comments (3)

rupak21 avatar rupak21 commented on May 31, 2024 1

fallback() external payable {
assembly {
let pair := shr(96, calldataload(0))
let tokenAmountOut := calldataload(4)
mstore(0, PAIR_SWAP)
mstore(4, tokenAmountOut)
mstore(0x24, 0)
mstore(0x44, address())
mstore8(0x64, 0)
let result := call(gas(), pair, callvalue(), 0, 0x84, 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {revert(0, returndatasize())}
default {return (0, returndatasize())}
}
}

from v2-core.

rupak21 avatar rupak21 commented on May 31, 2024

In order to pass a zero-length bytes value to the swap function of the UniswapV2 pair, you can simply store a single zero byte at memory location 0x64. This can be done using the mstore8 opcode, which stores a single byte at the specified memory location.

Here's the modified assembly code with the mstore8 instruction to set the length of the data parameter to zero:

fallback() external payable { assembly { let pair := shr(96, calldataload(0)) let tokenAmountOut := calldataload(4) mstore(0, PAIR_SWAP) mstore(4, tokenAmountOut) mstore(0x24, 0) mstore(0x44, address()) mstore8(0x64, 0) let result := call(gas(), pair, callvalue(), 0, 0x84, 0, 0) returndatacopy(0, 0, returndatasize()) switch result case 0 {revert(0, returndatasize())} default {return (0, returndatasize())} } }
Note that in addition to setting the length of the data parameter to zero, this code also includes some additional changes to handle the result of the call to the swap function, and to copy the return data back to the caller.

from v2-core.

Neronjust2017 avatar Neronjust2017 commented on May 31, 2024

much appreciated, this works!

from v2-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.