开源项目 malleable-signatures
使用教程
1. 项目的目录结构及介绍
malleable-signatures/
├── LICENSE
├── README.md
├── foundry.toml
├── gas-snapshot
├── gitignore
├── gitmodules
├── prettierignore
├── remappings.txt
├── github/
│ └── workflows/
├── lib/
├── test/
└── contract/
└── SignatureMalleability.sol
- LICENSE: 项目许可证文件,采用 WTFPL 许可证。
- README.md: 项目说明文档。
- foundry.toml: Foundry 配置文件。
- gas-snapshot: 用于记录 gas 消耗的快照文件。
- gitignore: Git 忽略文件配置。
- gitmodules: Git 子模块配置。
- prettierignore: Prettier 忽略文件配置。
- remappings.txt: Solidity 重映射配置。
- github/workflows: GitHub Actions 工作流配置。
- lib: 项目依赖库目录。
- test: 测试文件目录。
- contract: 智能合约文件目录,包含
SignatureMalleability.sol
。
2. 项目的启动文件介绍
项目的启动文件位于 contract/SignatureMalleability.sol
,这是一个 Solidity 智能合约文件,主要用于演示签名可塑性攻击。
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SignatureMalleability {
function verify(bytes32 _messageHash, bytes memory _sig, address _expectedSigner) public pure returns (bool) {
bytes32 ethSignedHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash));
address signer = recoverSigner(ethSignedHash, _sig);
return signer == _expectedSigner;
}
function recoverSigner(bytes32 _ethSignedHash, bytes memory _sig) public pure returns (address) {
require(_sig.length == 65, "Invalid signature length");
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(_sig, 32))
s := mload(add(_sig, 64))
v := byte(0, mload(add(_sig, 96)))
}
return ecrecover(_ethSignedHash, v, r, s);
}
}
3. 项目的配置文件介绍
- foundry.toml: 该文件是 Foundry 工具的配置文件,用于配置 Solidity 开发环境。
- remappings.txt: 该文件用于配置 Solidity 编译器的路径重映射,以便正确引用外部库和依赖。
以上是 malleable-signatures
项目的基本使用教程,涵盖了项目的目录结构、启动文件和配置文件的介绍。希望这些信息能帮助你更好地理解和使用该项目。