Example repo on how to make Cairo's Keccak hash match with Solidity’s Keccak and vice-versa!
The contracts
directory contains the following sub-folders:
contracts/cairo
utils/ - contains utility functions as bytes and some other common functions
example.cairo - the main contract that calculate keccak256(abi.encodePacked(...)) in cairo.
contracts/solidity
example.sol - the main contract that return keccak256(abi.encodePacked(...));
getKeccakOnlyUint
return keccak256(abi.encodePacked(uint256, uint256));
getKeccakUintAddress
return keccak256(abi.encodePacked(uint256, address));
getKeccakAddressUint
return keccak256(abi.encodePacked(address, uint256));
getKeccakUint8
return keccak256(abi.encodePacked(uint8, uint8));
-
Make sure to have docker installed and running.
-
yarn install
to install the required packages including StarkNet.js, HardHat, and the StarkNet Hardhat Plugin.
make sure you have at least cairo lang version 0.10.3, check with -> starknet --version
-
yarn compile
to create./starknet-artifacts/
with the compiled contracts. -
Open another terminal, then run
npx hardhat node
.
make sure you are running devnet version at least 0.4.4
-
Open another terminal, then run
starknet-devnet --seed 0
. -
yarn test
to execute the test.
In the ./exercises
folder you can find couple of tests to play with and try to get the same hash!