Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gwyneth v0.0.1 #10

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "gwyneth",
"version": "1.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Taiko Labs",
"license": "MIT"
}
34 changes: 34 additions & 0 deletions packages/protocol/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
15 changes: 15 additions & 0 deletions packages/protocol/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Compiler files
cache/
out/
node_modules/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
66 changes: 66 additions & 0 deletions packages/protocol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Foundry

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

Foundry consists of:

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

## Documentation

https://book.getfoundry.sh/

## Usage

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

### Gas Snapshots

```shell
$ forge snapshot
```

### Anvil

```shell
$ anvil
```

### Deploy

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```

### Cast

```shell
$ cast <subcommand>
```

### Help

```shell
$ forge --help
$ anvil --help
$ cast --help
```
27 changes: 27 additions & 0 deletions packages/protocol/contracts/4844/BlobHashReader.yulp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
// _____ _ _ _ _
// |_ _|_ _(_) |_____ | | __ _| |__ ___
// | |/ _` | | / / _ \ | |__/ _` | '_ (_-<
// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/

// An implemenatation of IBlobHashReader
object "BlobHashReader" {
code {
datacopy(0, dataoffset("runtime"), datasize("runtime"))
return(0, datasize("runtime"))
}
object "runtime" {
code {
// Match against the keccak of the ABI function signature needed.
switch shr(0xe0,calldataload(0))
// bytes4(keccak("function getFirstBlobHash()"))
// Returns the versioned hash for the first blob in this transaction.
case 0xfd122ecf {
// DATAHASH opcode has hex value 0x49
let hash := verbatim_1i_1o(hex"49", 0)
mstore(0, hash)
return(0, 32)
}
}
}
}
17 changes: 17 additions & 0 deletions packages/protocol/contracts/4844/IBlobHashReader.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
// _____ _ _ _ _
// |_ _|_ _(_) |_____ | | __ _| |__ ___
// | |/ _` | | / / _ \ | |__/ _` | '_ (_-<
// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/

pragma solidity ^0.8.20;

/// @title IBlobHashReader
/// @dev Labeled in AddressResolver as "blob_hash_reader"
/// @dev This interface and its corresponding implementation may deprecate once
/// solidity supports the new BLOBHASH opcode natively.
interface IBlobHashReader {
/// @notice Returns the versioned hash for the first blob in this
/// transaction. If there is no blob found, 0x0 is returned.
function getFirstBlobHash() external view returns (bytes32);
}
46 changes: 46 additions & 0 deletions packages/protocol/contracts/4844/Lib4844.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: MIT
// _____ _ _ _ _
// |_ _|_ _(_) |_____ | | __ _| |__ ___
// | |/ _` | | / / _ \ | |__/ _` | '_ (_-<
// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/

pragma solidity ^0.8.20;

/// @title Lib4844
/// @notice A library for handling EIP-4844 blobs
/// `solc contracts/libs/Lib4844.sol --ir > contracts/libs/Lib4844.yul`
library Lib4844 {
address public constant POINT_EVALUATION_PRECOMPILE_ADDRESS = address(0x0A);
uint32 public constant FIELD_ELEMENTS_PERBLOB = 4096;
uint256 public constant BLS_MODULUS =
52_435_875_175_126_190_479_447_740_508_185_965_837_690_552_500_527_637_822_603_658_699_938_581_184_513;

error EVAL_FAILED();
error POINT_X_TOO_LARGE();
error POINT_Y_TOO_LARGE();

/// @notice Evaluates the 4844 point using the precompile.
/// @param blobHash The versioned hash
/// @param x The evaluation point
/// @param y The expected output
/// @param commitment The input kzg point
/// @param pointProof The quotient kzg
function evaluatePoint(
bytes32 blobHash,
uint256 x,
uint256 y,
bytes1[48] memory commitment,
bytes1[48] memory pointProof
)
internal
view
{
if (x >= BLS_MODULUS) revert POINT_X_TOO_LARGE();
if (y >= BLS_MODULUS) revert POINT_Y_TOO_LARGE();

(bool ok,) = POINT_EVALUATION_PRECOMPILE_ADDRESS.staticcall(
abi.encodePacked(blobHash, x, y, commitment, pointProof)
);
if (!ok) revert EVAL_FAILED();
}
}
Loading
Loading