아래 항목들을 포함하면 안전하지 않습니다.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
contract UnsafeV1 {
address public owner;
uint public val = 123;
uint public start = block.timestamp;
constructor() {
owner = msg.sender;
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract UnsafeV1 is Initializable {
// Safe - constants and immutables
uint public constant MY_CONSTANT = 111;
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
uint public immutable MY_IMMUTABLE;
// Unsafe - constructor
address public owner;
// uint public val = 123;
uint public val;
// uint public start = block.timestamp;
uint public start;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(uint _x) {
// owner = msg.sender;
MY_IMMUTABLE = _x;
}
}
logic contract 에서 초기화된 상수(constant)와 immutable은 변경 불가능하기 때문에 예외로, Safe code 로 인정됩니다. (constant 와 immutable 로 선언된 데이터는 스토리지에 저장되지 않고 implementation 안에 저장(코드의 일부가 됨)되기 때문에 이뮤터블한 성질이 보장됩니다. immutable 이 constant 와 다른 점은 선언과 동시에 초기화하지 않고, constructor 내에서 디플로이할 때 초기화 가능하다는 점입니다.)
constructor가 포함되어 있으면 오픈제플린에서 경고를 발생시킵니다. 이를 해결하기 위해선 예외 처리해주어야 합니다. 이 constructor는 safe code 이며, 예외적으로 필요합니다. 라고 알려주기 위해 아래 주석을 추가합니다.