【发布时间】:2022-10-20 17:27:31
【问题描述】:
我正在研究如何在 etherscan 中读取汇编中的 ECDSA 恢复输出
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return tryRecover(hash, r, vs);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
有什么办法我可以读取操作码来获得这个输出?
提前致谢
【问题讨论】:
-
我不认为你可以从 etherscan 获得它,因为它是一个内部函数。通过操作码查看跟踪操作码应该是可能的,但这很困难。我推荐这个工具github.com/dapphub/dapptools/tree/master/src/hevm
标签: assembly ethereum solidity opcode