🗺️

Solidity

  • go-ethereum生成solidity calldata非常容易:
    • contractABI, err := abi.JSON(strings.NewReader(ABI)) encodedData, err := contractABI.Pack(method, args...)
  • go-ethereum中crypto.Sign默认签出来的v是0, 1需要加27
  • A delegateCall B, 如果B会修改数据那势必会修改到A上, 如果B本身就没有storage就不会有问题. B也可以是A, 这样也不会数据corrupt的风险
  • solidity计算implementation合约的方法:
    • bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
  • solidity使用abi.encodePacked来生成calldata, 链接string以及hash数组类数据
  • solidity使用bytes32(uint256(keccak256(abi.encode(k, p)))) 来计算mapping某个key的storage slot
  • solidity使用bytes32(uint256(keccak256(abi.encode(p))) + k) 来计算array某个index的storage slot
  • solidity中的abi.encode等价于ethers中的defaultAbiCoder.encode, abi.encodePacked 等价于ethers中的solidityPack
  • 如何decode returndata?
    • 0x08c379a0 // Function selector of "Error(string)" 0000000000000000000000000000000000000000000000000000000000000020 // Offset of string return value 0000000000000000000000000000000000000000000000000000000000000047 // Length of string return value (the revert reason) 6d7946756e6374696f6e206f6e6c79206163636570747320617267756d656e74 // first 32 bytes of the revert reason 7320776869636820617265206772656174686572207468616e206f7220657175 // next 32 bytes of the revert reason 616c20746f203500000000000000000000000000000000000000000000000000 // last 7 bytes of the revert reason
  • 根据salt和creationCode计算合约地址
    • address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( bytes1(0xff), address(this), salt, keccak256(abi.encodePacked( type(D).creationCode, arg )) )))));
  • 合约事件检索
    • indexed非数值类型会被hash
    • 非indexed数据会原封不动放到data中
  • 重要的EIP
    • EIP1559
    • EIP712, EIP2612
    • EIP1822, EIP1967, EIP2535
    • EIP3156, EIP4626
    • EIP4337: 抽象钱包
    • EIP4844: 坎昆升级
    • EIP1271: contract signature
  • 为什么mload(0x40)初始返回0x80?
  • solidity中bytes在memory里仅仅包含length + data,但是作为calldata或者returndata则会包含offset