Skip to content

Commit

Permalink
🧹
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Jan 5, 2024
1 parent cdc4ad1 commit 34e499d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# `lib-keccak`

wtf is even that
Implementation of the `Keccak-f[1600]` permutation in Solidity.

## Examples

**Differential test vs. `tiny-keccak`**

```sh
just rust-fuzz
```

**Run contract tests**
```sh
just sol-test
```
13 changes: 7 additions & 6 deletions contracts/lib/LibKeccak.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ library LibKeccak {

// xor five elements of the state matrix and store the result in `out`
function xorFive(ptr, a, b, c, d, e) -> out {
out :=
xor(
stateElem(ptr, a),
xor(xor(stateElem(ptr, b), stateElem(ptr, c)), xor(stateElem(ptr, d), stateElem(ptr, e)))
)
a := stateElem(ptr, a)
b := stateElem(ptr, b)
c := stateElem(ptr, c)
d := stateElem(ptr, d)
e := stateElem(ptr, e)
out := xor(a, xor(xor(b, c), xor(d, e)))
}

// Performs an indivudual rho + pi computation, to be used in the full `thetaRhoPi` chain.
Expand Down Expand Up @@ -182,7 +183,7 @@ library LibKeccak {

// set a state element in the passed `StateMatrix` struct memory ptr.
function setStateElem(ptr, idx, data) {
mstore(add(ptr, shl(0x05, idx)), and(data, 0xFFFFFFFFFFFFFFFF))
mstore(add(ptr, shl(0x05, idx)), and(data, U64_MASK))
}

// fetch a state element from the passed `StateMatrix` struct memory ptr.
Expand Down
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ testdata:
echo $(cat out/StatefulSponge.sol/StatefulSponge.json | jq -r '.deployedBytecode.object' | cut -c3-) > testdata/stateful_sponge

# lint the Rust code
rust-lint:
rust-lint: testdata
cargo +nightly fmt -- && cargo +nightly clippy --all --all-features -- -D warnings

# build the fuzzing tool binary
rust-build:
rust-build: testdata
cargo build --release

# run the fuzzing tool
rust-fuzz:
rust-fuzz: testdata
cargo run --release

# run the solidity tests
Expand Down

0 comments on commit 34e499d

Please sign in to comment.