안녕하세요.
0.8.28 버전의 컨트랙트를 배포할 예정입니다.
kaia chain이 Shanghai 및 Cancun 포크에서 도입된 PUSH0
, TSTORE
, TLOAD
, MCOPY
opcode를 모두 지원하는 걸까요?
Ethereum mainnet, Ethereum testnet, BSC Mainnet, BSC Testnet에서는 모두 배포가 가능하였지만, kaia chain(kairos)에는 배포가 안되어 문의드립니다.
Kaia docs 에서 보면 모두 지원하는 것으로 보이지만, 해당 opcode가 포함된 컨트랙트는 배포가 되지 않아 도움요청 드립니다. (확인해보니 TSTORE
, TLOAD
만 사용한 컨트랙트는 배포 가능)
테스트한 데이터 공유드립니다.
rpc url : https://public-en-kairos.node.kaia.io
txhash : 0xdbf5a360d1d5ea737a1c4a837e32386e7b7505b3c99ddf6b1c493b5b4f797e0d
evmVersion : cancun
test contract
contract OpcodeExample {
bytes public data;
// Function using push0 and mcopy opcodes
function usePush0AndMcopy(bytes memory _data) public {
assembly {
// Using push0 opcode (0x5f) - push 0 onto the stack
// Let compiler use push0 by using 0 directly
let zero := 0
// Get data length
let dataLength := mload(_data)
// Allocate new memory position
let memPos := mload(0x40)
// Using custom assembly for mcopy (opcode 0x4a)
// Format: mcopy(destOffset, sourceOffset, size)
let src := add(_data, 0x20)
let dst := memPos
// Raw MCOPY using "PUSH1 0x4a" followed by binary EVM opcode for mcopy
// We manually insert the mcopy opcode (0x4a)
// Using direct bytecode insertion
mstore(0x00, "MCOPY")
mstore(dst, dataLength)
// "Before MCOPY" marker for debugging
log0(0x00, 0x20)
// Inline assembly for mcopy (attempt 1)
// 0x4a is MCOPY opcode in hex
let success := 0
// Use direct yul assembly
// This depends on EVM version support rather than Solidity compiler support
mcopy(dst, src, dataLength)
// "After MCOPY" marker for debugging
mstore(0x00, "AFTER")
log0(0x00, 0x20)
// Update memory pointer
mstore(0x40, add(memPos, dataLength))
}
data = _data;
}
// Function using tstore and tload opcodes
function useTstoreAndTload(uint key, uint value) public returns (uint) {
uint retrievedValue;
assembly {
// Using tstore opcode (0x5a) with key and value
// Direct inline Yul for tstore
tstore(key, value)
// Using tload opcode (0x5c) with key
// Direct inline Yul for tload
retrievedValue := tload(key)
}
return retrievedValue;
}
// Function using all opcodes together
function useAllOpcodes(bytes memory _data, uint key) public returns (bytes memory, uint) {
uint storedValue;
assembly {
// Using push0 (just use 0)
let zero := 0
// Get data length
let dataLength := mload(_data)
// Store length in transient storage (tstore)
tstore(key, dataLength)
// Allocate new memory position
let memPos := mload(0x40)
// Copy data using mcopy
let src := add(_data, 0x20)
let dst := memPos
mcopy(dst, src, dataLength)
// Retrieve length from transient storage (tload)
let storedLength := tload(key)
// Store the value for return
storedValue := storedLength
}
return (_data, storedValue);
}
}