Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ecrecover report error code -51 #175

Open
zzhengzhuo opened this issue Mar 8, 2022 · 7 comments
Open

ecrecover report error code -51 #175

zzhengzhuo opened this issue Mar 8, 2022 · 7 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@zzhengzhuo
Copy link

With godwoken-kicker branch master, ecrecover report error code -51.

solidity code

function verifyk1(bytes memory sig, bytes32 message)
        public
        returns (address)
    {
        bytes32 r;
        bytes32 s;
        uint8 v;
        assembly {
            r := mload(add(sig, 0x20))
            s := mload(add(sig, 0x40))
            v := byte(0, mload(add(sig, 0x60)))
        }

        if (v == 0 || v == 1) {
            v = v + 27;
        }

        require(
            uint256(s) <=
                0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
            "invalid s"
        );

        emit event_log_bytes32("verify secp256k1 r: ", r);
        emit event_log_bytes32("verify secp256k1 s: ", s);
        address addr = ecrecover(message, v, r, s);
        return addr;
    }

test data

sig: 0xaaa99f644a5c4447314c5b7fcfac80deb186218aca1edaa63711aa75eb36585b47743901ce20f32768c7108bf85457ee0f16020f9bebc2bf456d6094c1c923c11c
message: 0x8ab0890f028c9502cc20d441b4c4bb116f48ea632f522ac84e965d1dadf918e1

With data in https://github.com/nervosnetwork/godwoken-polyjuice/blob/6760d08e4e9c6f6bb926d45bacf443700f12bd71/polyjuice-tests/src/test_cases/ecrecover.rs#L68 .

godwoken ecrecover log

godwoken_1           | [2022-03-08T06:15:13Z DEBUG gw_generator::syscalls] [contract debug]: call.destination 0x0000000000000000000000000000000000000001
godwoken_1           | [2022-03-08T06:15:13Z DEBUG gw_generator::syscalls] [contract debug]: data hash not exist
godwoken_1           | [2022-03-08T06:15:13Z DEBUG gw_generator::syscalls] [contract debug]: call pre-compiled contract failed => -51
godwoken_1           | [2022-03-08T06:15:13Z DEBUG gw_generator::syscalls] [contract debug]: [execute_in_evmone] context.error_code => -51
godwoken_1           | [2022-03-08T06:15:13Z DEBUG gw_generator::syscalls] [contract debug]: evmc_result.output_size => 0
godwoken_1           | [2022-03-08T06:15:13Z DEBUG gw_generator::syscalls] [contract debug]: evmc_result.output_data: 0x
godwoken_1           | [2022-03-08T06:15:13Z DEBUG gw_generator::syscalls] [contract debug]: handle message failed
@RetricSu

This comment was marked as resolved.

@zzhengzhuo
Copy link
Author

zzhengzhuo commented Mar 8, 2022

@RetricSu

This comment was marked as resolved.

@Flouse
Copy link
Collaborator

Flouse commented Mar 8, 2022

But in https://github.com/nervosnetwork/godwoken-polyjuice#features , polyjuice has ecrecover.

Yes, we do have ecrecover precompiled contract in Polyjuice.
see:
https://github.com/nervosnetwork/godwoken-polyjuice/blob/main/c/contracts.h#L58-L77

And the test case is here.

@Flouse
Copy link
Collaborator

Flouse commented Mar 8, 2022

solidity code

function verifyk1(bytes memory sig, bytes32 message)
        public
        returns (address)
    {
        bytes32 r;
        bytes32 s;
        uint8 v;
        assembly {
            r := mload(add(sig, 0x20))
            s := mload(add(sig, 0x40))
            v := byte(0, mload(add(sig, 0x60)))
        }

        if (v == 0 || v == 1) {
            v = v + 27;
        }

        require(
            uint256(s) <=
                0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
            "invalid s"
        );

        emit event_log_bytes32("verify secp256k1 r: ", r);
        emit event_log_bytes32("verify secp256k1 s: ", s);
        address addr = ecrecover(message, v, r, s);
        return addr;
    }

Does this Solidity code work fine on ETH testnet?
@zzhengzhuo

@Flouse Flouse self-assigned this Mar 8, 2022
@zzhengzhuo
Copy link
Author

Yes, it works well.

@Flouse

@Flouse
Copy link
Collaborator

Flouse commented Mar 8, 2022

  1. Please use the latest version of Kicker (v0), which is develop branch.
  2. Or, would you provide a demo repo which includes the entire Solidity contract code, and show me the commands that you interact with Godwoken Web3?

@Flouse Flouse added the good first issue Good for newcomers label Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants