Solidity Assembly
Simple Example
pragma solidity ^0.8.0;
contract Simple {
constructor(address _addr) {
assembly {
// Get the size of the code
let size := extcodesize(_addr);
// Allocate output byte array
code := mload(0x40);
// New "memory end" including padding
mstore(0x40, add(code, and(add(add(size, 0x20), 0x1f), not(0x1f))));
// Store length in memory
mstore(code, size);
// Retrieve the code
extcodecopy(addr, add(code, 0x20), 0, size);
}
}
}From Opcode
Last updated