aeternity / aesophia

Stand alone compiler for the Sophia smart contract language
https://docs.aeternity.com/aesophia
ISC License
51 stars 19 forks source link

[CERES] cannot verify global AENS delegation signature #479

Closed marc0olo closed 1 year ago

marc0olo commented 1 year ago

I am currently trying to implement a check in Sophia that verifies if the provided AENS delegation signature is valid. after some discussions with @hanssv it turns out that this is currently impossible.

I have following logic implemented right now:

    /// @notice provides delegation signature to let the contract manage all existing and future AENS names on behalf of the owner
    /// @param delegation_sig the global delegation signature (network id + owner address + string "AENS" + Contract.address)
    stateful entrypoint provide_delegation_sig(delegation_sig: signature) : unit =
        let expected : bytes() = Bytes.concat(
            Bytes.concat(String.to_bytes(Chain.network_id), Address.to_bytes(Call.caller)),
            Bytes.concat(String.to_bytes("AENS"), Address.to_bytes(Contract.address)))
        require(Crypto.verify_sig(Crypto.blake2b(expected), Call.caller, delegation_sig), "INVALID_DELEGATION_SIGNATURE")
        put(state{ account_to_signature[Call.caller] @sig = delegation_sig })

with this logic I always run into INVALID_DELEGATION_SIGNATURE, even if providing a correct signature.

I would need to be able to verify the signature for the unhashed bytes as follows:

obviously this currently leads to following compiler error:

CompilerError: compile error:
type_error:253:17: Cannot unify `bytes(32)` and `bytes()` (when checking the application of
  `Crypto.verify_sig : (hash, address, signature) => bool`
to arguments
  `expected : bytes()`
  `Call.caller : address`
  `delegation_sig : bytes(64)`)