[Solidity] Panic exception code

  1. 0x00: Used for generic compiler inserted panics.
  2. 0x01: If you call assert with an argument that evaluates to false.
  3. 0x11: If an arithmetic operation results in underflow or overflow outside of an unchecked { ... } block.
  4. 0x12; If you divide or modulo by zero (e.g. 5 / 0 or 23 % 0).
  5. 0x21: If you convert a value that is too big or negative into an enum type.
  6. 0x22: If you access a storage byte array that is incorrectly encoded.
  7. 0x31: If you call .pop() on an empty array.
  8. 0x32: If you access an array, bytesN or an array slice at an out-of-bounds or negative index (i.e. x[i] where i >= x.length or i < 0).
  9. 0x41: If you allocate too much memory or create an array that is too large.
  10. 0x51: If you call a zero-initialized variable of internal function type.

from https://docs.soliditylang.org/en/latest/control-structures.html#panic-via-assert-and-error-via-require

[hardhat] hardhat network에서 다른 계정인 척 쓰기

const hwwallet = "0xda50da50da50da50da50da50da50da50da50da50";

//  impersonating HW wallet
await network.provider.request({
  method: "hardhat_impersonateAccount",
  params: [hwwallet],
});

const _master = await ethers.getSigner(hwwallet);
_master.getFeeData = async () => {
  return {
    gasPrice: ethers.BigNumber.from(0),
    lastBaseFeePerGas: ethers.BigNumber.from(0),
    maxFeePerGas: ethers.utils.parseUnits("800", "gwei"),
    maxPriorityFeePerGas: ethers.utils.parseUnits("800", "gwei"),
  };
};
master = _master;

console.log('master: ', await master.getAddress());

[ethers.js] bytecode(=creationCode) 얻기

contract 컴파일 후 bytecode(creationCode)를 얻으려면:

(await ethers.getContractFactory("DasomOLIContract")).bytecode

이걸 keccak256()으로 돌리면(ethersV5 기준)

> ethers.utils.keccak256((await ethers.getContractFactory("DasomOLIContract")).bytecode)

위는 solidity에서 다음을 하는 것과 동일하다.

keccak256(abi.encodePacked(type(DasomOLIContract).creationCode));

[git] @{ } 표기법

Git에서는 @{} 표기법을 사용하여 다양한 브랜치 및 커밋 참조를 지정할 수 있습니다. 여기서 몇 가지 일반적으로 사용되는 표기법을 설명하겠습니다:

  1. @{u} 또는 @{upstream}: 현재 브랜치의 upstream 브랜치를 가리킵니다. 예를 들어, main 브랜치의 upstream 브랜치가 origin/main인 경우, main@{u} 또는 main@{upstream}origin/main을 가리킵니다.
  2. @{1} 또는 @{2} 등의 숫자: 브랜치의 이전 위치를 가리킵니다. 예를 들어, main@{1}main 브랜치의 바로 이전 커밋을 가리킵니다.
  3. @{yesterday} 또는 @{1.week.ago}와 같이 시간 범위를 지정할 수도 있습니다. 이를 통해 특정 시점의 커밋을 가리킬 수 있습니다.
  4. @{commit-hash}: 직접 커밋 해시(해당 커밋의 고유 식별자)를 지정하여 특정 커밋을 가리킬 수 있습니다.
  5. @{branch-name}: 특정 브랜치의 위치를 가리킬 수 있습니다.

이러한 표기법을 사용하면 Git에서 다양한 상황에서 브랜치, 커밋 및 이력을 참조할 수 있으며, 특정 시점이나 이전 위치에 대한 정보를 쉽게 얻을 수 있습니다.

[hardhat/ethers.js] HW Ledger 체크

ethers.js v5 기준 hardhat 태스크

import { LedgerSigner } from "@anders-t/ethers-ledger";
import { task } from "hardhat/config";

task("checkHW", "Check HW Wallet")
  .addOptionalPositionalParam("accountNumber", "Index of the address of the HW wallet")
  .setAction(async (taskArgs) => {
  const accountNumber = taskArgs.accountNumber;
    const _master = new LedgerSigner(ethers.provider, `m/44'/60'/${accountNumber}'/0/0`);
  _master.getFeeData = async () => {
    return {
      gasPrice: ethers.BigNumber.from(0),
      lastBaseFeePerGas: ethers.BigNumber.from(0),
      maxFeePerGas: ethers.utils.parseUnits("800", "gwei"),
      maxPriorityFeePerGas: ethers.utils.parseUnits("800", "gwei"),
    };
  };
  const master = _master;

  console.log(`HW Ledger: [${accountNumber}]:${await master.getAddress()}: ${ethers.utils.formatEther(await master.getBalance())} ETH`);
});

사용은 hh checkHW 0 와 같이 한다.

[ethers.js] ERC20 balance 체크

hardhat task로 만든 ERC20 잔액 확인 태스크

task("balanceERC20", "Check the balance of ERC20 token")
  .addPositionalParam("tokenAddress", "ERC20 Token contract address")
  .addPositionalParam("address", "Address to be checked")
  .setAction(async (taskArgs) => {
    const ERC20 = await ethers.getContractFactory("@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20");
    const erc20 = await ERC20.attach(taskArgs.tokenAddress);
    console.log(ethers.formatEther(await erc20.balanceOf(taskArgs.address)), await erc20.symbol());
  });