NEWTON

NEWTON


Popular tags

    Is there a Cairo equivalent to Keccak256(abi.encode(parameters))?

    Asked

    3 months ago

    58

    views


    0

    I'm aware of starknet having a common--and unsafe--keccak library. Either way, I was wondering if there's a way to mimic the behavior of solidity's

    keccak256(abi.encode(parameters))
    

    Thank you very much.

      keccak256abi.encodeabi.decodecairo

    0x57B0...F5A4FD

    asked

    3 months ago


    1 answers

    1

    Accepted answer

    At the moment this is not possible since there is no real typing system, though this might change with Cairo 1.0.

    What you can do is to simply use structs to pass calldata between contracts instead of encoding/decoding.

    For reference, the same function with calldata on both EVM and Starknet with encode/decode:

    EVM (with encode/decode): https://github.com/CygnusDAO/periphery/blob/main/contracts/cygnus-periphery/CygnusAltairX.sol#L849

    Cairo (without encode/decode): https://github.com/CygnusDAO/starknet-periphery/blob/main/src/cygnus_periphery/cygnus_altair_x.cairo#L968

    Anubis

    answered

    3 months ago

    Your answer

    NEWTON

    NEWTON