# How to use assembly codes around call forwarding?

**URL:** <https://forum.openzeppelin.com/t/how-to-use-assembly-codes-around-call-forwarding/3578>\
**Category:** Support\
**Tags:** design\
**Created:** [August 17, 2020, 9:26pm UTC](https://forum.openzeppelin.com/t/how-to-use-assembly-codes-around-call-forwarding/3578 "2020-08-17T21:26:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dyno](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/dyno/32/5270_2.png) [@Dyno](https://forum.openzeppelin.com/u/Dyno)\
**Post date:** [August 17, 2020, 9:26pm UTC](https://forum.openzeppelin.com/t/how-to-use-assembly-codes-around-call-forwarding/3578/1 "2020-08-17T21:26:07Z")

</div>

I was hoping to gain some knowledge around specific assembly codes, particularly the ones used in the Instadapp project to forward user calls to their proxy integration contracts.

The function in question is:

```auto
/**
     * @dev Delegate the calls to Connector And this function is ran by cast().
     * @param _target Target to of Connector.
     * @param _data CallData of function in Connector.
    */
    function spell(address _target, bytes memory _data) internal {
        require(_target != address(0), "target-invalid");
        assembly {
            let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0)

            switch iszero(succeeded)
                case 1 {
                    // throw if delegatecall failed
                    let size := returndatasize()
                    returndatacopy(0x00, 0x00, size)
                    revert(0x00, size)
                }
        }
    }

```

Specifically, what does this do, and how would one use it? I haven’t found actual docs explaining how `delegatecall()`, and `_mload()` function/parameters they take.

I do understand the delegatecall will return the status of the txn as a zero or 1 (and won’t auto-fail upon error) and the `switch()` checks if the transaction did fail (indicated by a zero return). Though I don’t know what `returndatasize` or `returndatacopy` does.

Thanks for any explanation/knowledge share. On a side-note, where are good sources to learn assembly? The official Solidity docs don’t do a great job in explanation.

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [August 19, 2020, 4:34am UTC](https://forum.openzeppelin.com/t/how-to-use-assembly-codes-around-call-forwarding/3578/2 "2020-08-19T04:34:02Z")

</div>

Hi @Dyno,

I don't know that much about assembly unfortunately, but I would recommend having a read through the following posts (including the whole series if split into multiple parts).

> [@How to survive in the Assembly world?](https://forum.openzeppelin.com/t/how-to-survive-in-the-assembly-world/1125):
>
> Overview Because in special situations we have to put aside our beautiful high-level Solidity language, the purpose of this series is to focus on some of the instructions that you need to understand to survive into the Jumanji assembly world. Trust me, I come from there. These posts will try to add value to the existent and amazing [articles](https://blog.openzeppelin.com/deconstructing-a-solidity-contract-part-i-introduction-832efd2d7737/) that [Ale](https://twitter.com/_ajsantander) made about the EVM internals. Experimental scientific method We will be focusing on a particular statement - or situati…

> **[Ethereum in Depth, Part 1 - OpenZeppelin blog](https://blog.openzeppelin.com/ethereum-in-depth-part-1-968981e6f833)**
>
> Welcome to the first part of a two-posts series aimed at software developers looking to understand how the EVM works. The idea is to explain and describe in detail core behavior of the EVM.

> **[Deconstructing a Solidity Smart Contract —Part I: Introduction - OpenZeppelin...](https://blog.openzeppelin.com/deconstructing-a-solidity-smart-contract-part-i-introduction-832efd2d7737)**
>
> You’re on the road, driving fast in your rare, fully restored 1969 Mustang Mach 1. The sunlight shimmers on the all-original, gorgeous plated rims. It’s just you, the road, the desert, and the never-ending chase of the horizon. Perfection!

> **[Proxy Patterns - OpenZeppelin blog](https://blog.openzeppelin.com/proxy-patterns)**
>
> One of the biggest advantages of Ethereum is that every transaction of moving funds, every contract deployed, and every transaction made to a contract is immutable on a public ledger...

> **[Deep dive into the Minimal Proxy contract - OpenZeppelin blog](https://blog.openzeppelin.com/deep-dive-into-the-minimal-proxy-contract)**
>
> In this deep dive into low-level EVM code, you will learn how to code a Minimal Proxy (EIP 1167) from scratch, no Solidity involved. Finally, we see how to easily deploy the proxy using OpenZeppelin's SDK.

Specifically looking at InstaDApp, you could have a look at the audit. You could also reach out to the team.

> **[InstaDApp Audit - OpenZeppelin blog](https://blog.openzeppelin.com/instadapp-audit)**
>
> The InstaDApp team asked us to audit their proxy wallet and wallet registry contracts. We examined the code and now publish our results.

---

<div class="post-metadata">

**Author:** ![Dyno](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/dyno/32/5270_2.png) [@Dyno](https://forum.openzeppelin.com/u/Dyno)\
**Post date:** [August 21, 2020, 4:03pm UTC](https://forum.openzeppelin.com/t/how-to-use-assembly-codes-around-call-forwarding/3578/3 "2020-08-21T16:03:35Z")

</div>

Great, thanks for these resources @abcoathup!
