Files
papers/hanzo-identity-nft/sections/04-smart-contract-architecture.tex

55 lines
1.4 KiB
TeX

\section{Smart Contract Architecture}
\subsection{Upgradeability}
The registry uses UUPS (Universal Upgradeable Proxy Standard)~\cite{eip1822}:
\begin{lstlisting}[language=Solidity]
contract HanzoRegistry is
Initializable,
UUPSUpgradeable,
Ownable2StepUpgradeable
{
function _authorizeUpgrade(address newImplementation)
internal override onlyOwner {}
}
\end{lstlisting}
UUPS places upgrade logic in the implementation contract, reducing proxy complexity and gas costs.
\subsection{Access Control}
Two-step ownership transfer prevents accidental lockout:
\begin{lstlisting}[language=Solidity]
// Ownable2StepUpgradeable provides:
function transferOwnership(address newOwner) public;
function acceptOwnership() public;
function pendingOwner() public view returns (address);
\end{lstlisting}
\subsection{NFT Contract}
\begin{lstlisting}[language=Solidity]
contract HanzoNft is ERC721, Ownable {
address public minter; // Registry contract
function mint(address to) external returns (uint256) {
require(msg.sender == minter, "Not minter");
uint256 tokenId = _tokenIdCounter++;
_safeMint(to, tokenId);
return tokenId;
}
function burn(uint256 tokenId) external {
require(_isApprovedOrOwner(msg.sender, tokenId),
"Not owner");
_burn(tokenId);
}
}
\end{lstlisting}
The NFT contract is minimal; all identity logic resides in the registry.