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

docs: Better document the usage/behavior of contextOrHash for .sign() and .verify() #331

Open
matevz opened this issue Jul 8, 2024 · 0 comments
Labels
contracts Pull requests that update sapphire-contracts docs Documentation

Comments

@matevz
Copy link
Member

matevz commented Jul 8, 2024

Someone on discord asked:

My question mainly about the use of contextOrHash as bytes in functions like sign(), verify() in Sapphire.sol

For example, in sign function:

function sign(
SigningAlg alg,
bytes memory secretKey,
@> bytes memory contextOrHash,
bytes memory message
) internal view returns (bytes memory signature) {
(bool success, bytes memory sig) = SIGN_DIGEST.staticcall(
abi.encode(alg, secretKey, contextOrHash, message)
);
require(success, "sign: failed");
return sig;
}

contextOrHash is expected to be passed as bytes argument but the comment states:

@param contextOrHash Domain-Separator Context, or precomputed hash bytes.

and as per Sapphire documentation for Secp256k1PrehashedKeccak256 alg:

(Secp256k1PrehashedKeccak256): 3,000 gas, pre-existing hash (32 bytes) as context, empty message.

What does exactly mean by pre-existing hash (32 bytes) as context?

If one of my function is returning contextOrHash as bytes data type then would that need to be converted to bytes32 hash >using keccak256 OR that contextOrHash as bytes can be directly used in sign() or verify() function.

Document better the behavior of contextOrHash based on which signature scheme is used. Check out the implementation here: https://github.com/oasisprotocol/oasis-sdk/blob/main/runtime-sdk/src/crypto/signature/mod.rs#L544-L621

@matevz matevz added contracts Pull requests that update sapphire-contracts docs Documentation labels Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contracts Pull requests that update sapphire-contracts docs Documentation
Projects
None yet
Development

No branches or pull requests

1 participant