본문 바로가기

분류 전체보기

(117)
[Ethernaut] 20. Denial 소스코드 // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import '@openzeppelin/contracts/math/SafeMath.sol'; contract Denial { using SafeMath for uint256; address public partner; // withdrawal partner - pay the gas, split the withdraw address payable public constant owner = address(0xA9E); uint timeLastWithdrawn; mapping(address => uint) withdrawPartnerBalances; // keep track of partners bal..
업그레이드 가능한 컨트랙트 작성해보기 이전에 작성했던 프록시 패턴을 실습해보도록 하겠습니다. https://dev-dean-k.tistory.com/86 [Solidity] 프록시 패턴(Proxy Pattern) 스마트 컨트랙트의 가장 큰 특징은 한번 배포되면 컨트랙트 코드의 수정이 불가하다는 것입니다. 그렇기 때문에 배포 전에 엄격한 테스트가 필요하며 만약 그랬다고 하더라도 예기치 못한 수정 dev-dean-k.tistory.com 먼저 필요한 패키지를 설치합니다. npm install @openzeppelin/contracts npm install --save-dev @openzeppelin/hardhat-upgrades 하드햇에서 2개의 컨트랙트 Box와 수정 버전인 BoxV2를 작성합니다. Box //SPDX-License-Ident..
솔리디티 프록시 패턴(Proxy Pattern) 스마트 컨트랙트의 가장 큰 특징은 한번 배포되면 컨트랙트 코드의 수정이 불가하다는 것입니다. 그렇기 때문에 배포 전에 엄격한 테스트가 필요하며 만약 그랬다고 하더라도 예기치 못한 수정사항이 발생할 수 있습니다. 이러한 경우 프록시 패턴을 이용하면 프로그램을 업데이트한 것처럼 상태 변수 값을 보존하면서 컨트랙트의 로직을 수정할 수 있습니다. 프록시 패턴 앞서 상태 변수의 값을 보존하면서 로직을 수정할 수 있다는 이유는 위와 같이 프록시 컨트랙트에 상태 변수의 값을 저장하고 로직 컨트랙트에는 수행할 로직만을 작성하기 때문에 상태 변수의 값을 보존할 수 있습니다. 다음은 Open Zeppelin에서 제공하는 프록시 패턴의 구조입니다. 사용자는 프록시 컨트랙트에 요청을 보내면 프록시 컨트랙트는 delegatec..
[Ethernaut] 19. Alien Codex 소스코드 // SPDX-License-Identifier: MIT pragma solidity ^0.5.0; import '../helpers/Ownable-05.sol'; contract AlienCodex is Ownable { bool public contact; bytes32[] public codex; modifier contacted() { assert(contact); _; } function make_contact() public { contact = true; } function record(bytes32 _content) contacted public { codex.push(_content); } function retract() contacted public { codex.length..
[npm 에러] Could not resolve dependency ... npm 으로 패키지 설치지시 Could not resolve dependency ... 라며 에러가 발생했다. 해결 방법 npm install --save --legacy-peer-deps {패키지 이름}
[Ethernaut] 18. MagicNumber 소스코드 // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; contract MagicNum { address public solver; constructor() public {} function setSolver(address _solver) public { solver = _solver; } /* ____________/\\\_______/\\\\\\\\\_____ __________/\\\\\_____/\\\///////\\\___ ________/\\\/\\\____\///______\//\\\__ ______/\\\/\/\\\______________/\\\/___ ____/\\\/__\/\\\___________/\\\//_____ __/\\\\..
Pinata로 IPFS 사용해보기 시중에 IPFS 서비스를 제공하는 서비스가 여러 개 있는데 (Pinanta, Temporal, Eternum 등) Pinata를 사용해서 리액트에서 이미지를 등록해보기로 하겠습니다. Pinanta Pinata | Your Home for NFT Media Pinata is the home of NFT media, used by nearly 200,000 creators including some of the world's biggest brands. Experience web3 media like never before. www.pinata.cloud 여러 플랜이 있으나 저는 무료 플랜으로 시작하겠습니다. 로그인을 하면 위와 같이 피나타 홈페이지에서도 이미지를 등록할 수 있습니다. 파란 Upload 버튼..
[Ethernaut] 17. Recovery 소스코드 // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import '@openzeppelin/contracts/math/SafeMath.sol'; contract Recovery { //generate tokens function generateToken(string memory _name, uint256 _initialSupply) public { new SimpleToken(_name, msg.sender, _initialSupply); } } contract SimpleToken { using SafeMath for uint256; // public variables string public name; mapping (address => uin..