AstarNetwork / astar-frame

Core frame modules for Astar & Shiden network.
Other
58 stars 38 forks source link

what's the address of the precompiled contract SR25519.sol? #39

Closed LaceLetho closed 2 years ago

LaceLetho commented 2 years ago

Description

I'm trying to utilize the SR25519.sol interface to verify a sr25519 encrypted message

I have tried on Shiden at 0x0000000000000000000000000000000000005001 but it threw a VM exception: revert

Dinonard commented 2 years ago

Hello,

You can find the exact address used in the precompiles.rs file in Astar repo. E.g. for Shiden: https://github.com/AstarNetwork/Astar/blob/master/runtime/shiden/src/precompiles.rs

Please note that even though you might see that e.g. Astar has some precompiles, that doesn't mean it's already live on chain. Make sure also to compare spec_version of the code in the repo to the one that's deployed on-chain.

LaceLetho commented 2 years ago

Thanks for your detailed explanation, now I know the address is 0x5002 and it's live on Shiden.

But when I test it, I can't get expected result.

const c = await ethers.getContractAt("SR25519","0x0000000000000000000000000000000000005002");

const r = await c.verify("0xcae65573cd7522dbed18547b872d66f663b1765b3ee1544d84a5b34c38038f6e",
"0xf4101bf19623d82998e4e55324127f056b8af7b81da17716ce630534d857583259efb40626529e4b09afbe6a0edf1549de0c36a59b6bbcac2dd2ed07bae47586",
"0x6f");

console.log(r);

the code above return false, but I get true while verify the message in polkadot.js portal

image

Is it caused by any mistake in the verify's param type?

ps: the "ethers" object is in hardhat context

Dinonard commented 2 years ago

Could be the encoding of the data in your script.

verify signature looks like:

    function verify(
        bytes32 public_key,
        bytes calldata signature,
        bytes calldata message
    ) external view returns (bool);

I haven't used this myself but perhaps @Maar-io can help.

Dinonard commented 2 years ago

You can check https://github.com/AstarNetwork/astarbase for code examples on how the contract is used.

I will close this ticket since it's not a bug.

Maar-io commented 2 years ago

@LaceLetho please check how the message is built before you sign it. you need to have PREFIX and POSTFIX, just like astarbase contract is using it

LaceLetho commented 2 years ago

Got it, thanks for your explanation