0

Assume there is an example as below:

pragma solidity >=0.4.11 <0.6.0;

contract C {
    uint b;
    function f(uint x) public view returns (uint r) {
        assembly {
            r := mul(x, sload(b_slot)) // ignore the offset, we know it is zero
        }
    }
}

Can I move the "r := mul(x, sload(b_slot))" as an input string of a function? something like

pragma solidity >=0.4.11 <0.6.0;

contract C {
    uint b;
    function f(uint x, string memory assembly_code) public view returns (uint r) {
        assembly {
            string_to_assembly_code(assembly_code);
        }
    }
}

Call the function like C.f(3, "r := mul(x, sload(b_slot))") Because I cannot determine what calculation method I would use when deploy the contract, I would like to send the required calculation formula to the contract code for simple calculation. Is it possible to do it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.