# keccak256

Computes the Keccak-256 hash used by the EVM, returning a BYTES32 digest. Non-0x VARCHAR input is hashed as UTF-8, 0x-prefixed VARCHAR input is decoded to bytes first, and multi-argument overloads hash the exact unframed concatenation in argument order.

Canonical HTML: <https://determica.com/docs/functions/keccak256>

- Kind: scalar function
- Category: [EVM utilities](/docs/category/evm-utilities.md)
- Tags: Keccak

Computes the Keccak-256 hash used by the EVM, returning a BYTES32 digest. Non-0x VARCHAR input is hashed as UTF-8, 0x-prefixed VARCHAR input is decoded to bytes first, and multi-argument overloads hash the exact unframed concatenation in argument order.

## Overload 1: keccak256(VARCHAR)

```sql
keccak256(VARCHAR)
```

Accepts UTF-8 literals or 0x-prefixed hex strings. A VARCHAR beginning with 0x is decoded as hex bytes before hashing; use the BLOB overload when you need exact binary hashing.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `input` (VARCHAR; required; positional) — Non-0x VARCHAR values are hashed as UTF-8 bytes. 0x-prefixed VARCHAR values are decoded as hex bytes before hashing.

### Returns

Keccak-256 digest

Returns the 32-byte EVM hash as BYTES32.

- `hash` (BYTES32)

Keccak-256 digest. Returns the 32-byte EVM hash as BYTES32.

## Overload 2: keccak256(BLOB)

```sql
keccak256(BLOB)
```

Hashes a single BLOB (ADDRESS, BYTES32, or raw binary) exactly as it is stored.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `data` (BLOB; required; positional) — BLOB, ADDRESS, or BYTES32 bytes to hash exactly as stored.

### Returns

Keccak-256 digest

Returns the 32-byte EVM hash as BYTES32.

- `hash` (BYTES32)

Keccak-256 digest. Returns the 32-byte EVM hash as BYTES32.

## Overload 3: keccak256(BLOB, BLOB)

```sql
keccak256(BLOB, BLOB)
```

Concatenates two binary values without length delimiters before hashing, mirroring keccak256(abi.encodePacked(a, b)) for already-encoded byte segments.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `left` (BLOB; required; positional) — First BLOB segment in the concatenation.
- `right` (BLOB; required; positional) — Second BLOB segment in the concatenation.

### Returns

Keccak-256 digest

Returns keccak256(left || right) as BYTES32.

- `hash` (BYTES32)

Keccak-256 digest. Returns keccak256(left || right) as BYTES32.

## Overload 4: keccak256(BYTES32, BYTES32)

```sql
keccak256(BYTES32, BYTES32)
```

Concatenates two EVM word inputs before hashing. Use this for Solidity mapping slots such as keccak256(owner::BYTES32, slot::UINT256).

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `left` (BYTES32; required; positional) — First 32-byte ABI-style word in the concatenation.
- `right` (BYTES32; required; positional) — Second 32-byte ABI-style word in the concatenation.

### Returns

Keccak-256 digest

Returns keccak256(left || right) as BYTES32.

- `hash` (BYTES32)

Keccak-256 digest. Returns keccak256(left || right) as BYTES32.

## Overload 5: keccak256(BYTES32, UINT256)

```sql
keccak256(BYTES32, UINT256)
```

Concatenates two EVM word inputs before hashing. Use this for Solidity mapping slots such as keccak256(owner::BYTES32, slot::UINT256).

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `left` (BYTES32; required; positional) — First 32-byte ABI-style word in the concatenation.
- `right` (UINT256; required; positional) — Second 32-byte ABI-style word in the concatenation.

### Returns

Keccak-256 digest

Returns keccak256(left || right) as BYTES32.

- `hash` (BYTES32)

Keccak-256 digest. Returns keccak256(left || right) as BYTES32.

## Overload 6: keccak256(UINT256, BYTES32)

```sql
keccak256(UINT256, BYTES32)
```

Concatenates two EVM word inputs before hashing. Use this for Solidity mapping slots such as keccak256(owner::BYTES32, slot::UINT256).

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `left` (UINT256; required; positional) — First 32-byte ABI-style word in the concatenation.
- `right` (BYTES32; required; positional) — Second 32-byte ABI-style word in the concatenation.

### Returns

Keccak-256 digest

Returns keccak256(left || right) as BYTES32.

- `hash` (BYTES32)

Keccak-256 digest. Returns keccak256(left || right) as BYTES32.

## Overload 7: keccak256(UINT256, UINT256)

```sql
keccak256(UINT256, UINT256)
```

Concatenates two EVM word inputs before hashing. Use this for Solidity mapping slots such as keccak256(owner::BYTES32, slot::UINT256).

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `left` (UINT256; required; positional) — First 32-byte ABI-style word in the concatenation.
- `right` (UINT256; required; positional) — Second 32-byte ABI-style word in the concatenation.

### Returns

Keccak-256 digest

Returns keccak256(left || right) as BYTES32.

- `hash` (BYTES32)

Keccak-256 digest. Returns keccak256(left || right) as BYTES32.

## Overload 8: keccak256(BLOB, BLOB, BLOB)

```sql
keccak256(BLOB, BLOB, BLOB)
```

Hashes three BLOB inputs as the unframed concatenation a || b || c. Callers must supply unambiguous framing when segment boundaries matter.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `a` (BLOB; required; positional) — First BLOB segment in the concatenation.
- `b` (BLOB; required; positional) — Second BLOB segment in the concatenation.
- `c` (BLOB; required; positional) — Third BLOB segment in the concatenation.

### Returns

Keccak-256 digest

Returns keccak256(a || b || c) as BYTES32.

- `hash` (BYTES32)

Keccak-256 digest. Returns keccak256(a || b || c) as BYTES32.

## Guidance

### Text, hex, and EVM words

keccak256 accepts both text-oriented and binary-oriented overloads. A VARCHAR beginning with 0x is treated as hex bytes, while other VARCHAR input is hashed as UTF-8.

- Use keccak256('hello') for UTF-8 text.
- Use keccak256('0x68656c6c6f') for hex encoded bytes.
- Use keccak256(blob_value) when the bytes are already binary.
- Do not use the VARCHAR overload when a 0x-prefixed string must be hashed as literal text.
- Use explicit ADDRESS::BYTES32 and UINT256 casts when computing Solidity mapping slots.

```sql
SELECT
  keccak256('hello') AS utf8_hash,
  keccak256('0x68656c6c6f') AS hex_hash,
  keccak256('0x68656c6c6f'::BLOB) AS blob_hash;
```

```sql
SELECT keccak256(
  '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'::ADDRESS::BYTES32,
  3::UINT256
) AS mapping_slot;
```

### String and binary inputs

The VARCHAR overload treats 0x-prefixed strings as hex bytes before hashing. Non-0x VARCHAR inputs are hashed as UTF-8 bytes. Use the BLOB overload for exact binary hashing.

## Additional examples

```sql
-- Derive the ERC-20 Transfer event topic from its canonical signature
SELECT keccak256('Transfer(address,address,uint256)')::VARCHAR AS topic0;
-- => [{"topic0":"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"}]
```

```sql
-- A 0x VARCHAR is decoded before hashing; plain text is UTF-8
SELECT
  keccak256('0x68656c6c6f')::VARCHAR AS hex_bytes_hash,
  keccak256('hello')::VARCHAR AS utf8_hash;
-- => [{"hex_bytes_hash":"0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8","utf8_hash":"0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"}]
```

```sql
-- Derive a Solidity mapping slot from a padded owner word and slot number
SELECT keccak256(
  '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'::ADDRESS::BYTES32,
  3::UINT256
)::VARCHAR AS mapping_slot;
-- => [{"mapping_slot":"0x3a988d762a24303c37d08f1543db6143453b579691d5c20fed39629ff1334cca"}]
```

## Related functions

- [create2_predict](/docs/functions/create2_predict.md) — Usually Before
- [create2_mine](/docs/functions/create2_mine.md) — Usually Before
