【问题标题】:how to read lines of ECDSA recover public key from signature in assembly?如何读取 ECDSA 行从程序集中的签名中恢复公钥?
【发布时间】: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);
        }
    }

有什么办法我可以读取操作码来获得这个输出?

提前致谢

【问题讨论】:

标签: assembly ethereum solidity opcode


【解决方案1】:

该库可帮助您从 ECDSA 签名消息中恢复公钥 https://github.com/0xcyphered/secp256k1-solidity

【讨论】:

    猜你喜欢
    • 2013-11-09
    • 2018-11-14
    • 2011-04-12
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    • 2016-02-05
    相关资源
    最近更新 更多