Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 1.38 KB

File metadata and controls

50 lines (37 loc) · 1.38 KB

EVM的內存

EVM的内存

  1. 可以理解為一個動態字節數組
  2. 支持以8bit或256bit寫入(MSTORE8, MSTORE)
  3. 但支持以256bit讀取(MLOAD)

預留slot (4個內存slot)

  1. 0x00-0x3f (64bytes) => 用來存key的hash的值
  2. 0x40-0x5f (32bytes) => RAM大小,Free memory pointer
  3. 0x60-0x7f (32bytes) => 32bytes的0值插槽,用於需要零值的地方

值變量

uint

function testUint() public pure returns (uint){
    uint a = 3;
    return a;
}

EVM Memory Layout for Value Variables

String

function testShortString() public pure returns (string memory){
    string memory x = "WTF";
    return x;
}

x的長度3保存內存槽在0x80, 內容WTF保存在內存槽0xa0 EVM Memory Layout for Value Variables

Bytes

function testLongBytes() public pure returns (bytes memory){
    bytes memory x = hex"365f5f375f5f365f73bebebebebebebebebebebebebebebebebebebebe5af43d5f5f3e5f3d91602a57fd5bf3";
    return x;
}

x的長度為44(0x2c),保存在內存槽0x80

內容保存在內存槽0xa0-0xc0

EVM Memory Layout for Value Variables