Skip to content

Example of How to make Cairo's Keccak hash to match with Solidity’s Keccak and vice-versa?

Notifications You must be signed in to change notification settings

0xSpaceShard/Keccak_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solidity <> Cairo Keccak example

Example repo on how to make Cairo's Keccak hash match with Solidity’s Keccak and vice-versa!

Contracts

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(...));

Functions

  • 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));

Running the tests

  1. Make sure to have docker installed and running.

  2. 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

  1. yarn compile to create ./starknet-artifacts/ with the compiled contracts.

  2. Open another terminal, then run npx hardhat node.

make sure you are running devnet version at least 0.4.4

  1. Open another terminal, then run starknet-devnet --seed 0.

  2. yarn test to execute the test.

Exercises

In the ./exercises folder you can find couple of tests to play with and try to get the same hash!

About

Example of How to make Cairo's Keccak hash to match with Solidity’s Keccak and vice-versa?

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published