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

implement setimmutable(offset, "name", value) and loadimmutable("name") for 0.8.6 #97

Open
jacky860226 opened this issue Jul 15, 2021 · 2 comments
Assignees

Comments

@jacky860226
Copy link
Contributor

setimmutable(offset, "name", value) assumes that the runtime code of the contract containing the given named immutable was copied to memory at offset offset and will write value to all positions in memory (relative to offset) that contain the placeholder that was generated for calls to loadimmutable("name") in the runtime code.

@eee4017 eee4017 self-assigned this Jul 22, 2021
@CaptainVincent
Copy link
Member

For reference:
The evm version will directly modify the immutable data on deployed bytecode in constructor.

Simple test case

object "a" {
    code {
        let memPtr := mload(64)
        codecopy(memPtr, dataoffset("Test_deployed"), datasize("Test_deployed"))
        setimmutable(
            0,
            "Name",
            address()
        )
        return(memPtr, datasize("Test_deployed"))
    }
    object "Test_deployed" {
        code {
            let addr := loadimmutable("Name")
            return(addr, 20)
            function fun() -> temp {
                temp := loadimmutable("Name")
            }
        }
    }
}
solc test_case.yul --strict-assembly

Binary representation:

604051605361001d8239306000818160010152602c0152605381f350fe7f0000000000000000000000000000000000000000000000000000000000000000601481f36051565b60007f000000000000000000000000000000000000000000000000000000000000000090505b90565b50

@CaptainVincent
Copy link
Member

CaptainVincent commented Jul 23, 2021

Consider to add immutable field as a string type placeholder on data section and embedded into deployed bytecode.
All loadimmutable ops are corresponding to the convert data placeholder into value types.
In the top layer setimmutable need calculate the offset of placeholder on deployed bytecode first, and generate replace the placeholder IR for setimmutable.

  • How to Insert bytes into data section of wasm?

    It's could reference to emitNestedBytecodeFunction in SOLL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants