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

Setup of hardhat for precompiles #12

Merged
Merged
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
build/_workspace
build/_bin
tests/testdata

vendor
contracts/node_modules
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ jobs:
with:
go-version: '1.21.4'
- name: build all binaries from cmd
run: go run build/ci.go install
run: make all
- name: build dev version of geth
run: make geth-dev

test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -86,3 +88,22 @@ jobs:
# - name: run simulation result parser
# working-directory: ./hive
# run: result_parser -path_to_results ./workspace/logs

precompile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21.4'
- name: build geth docker image
run: make docker-build-dev
- name: run geth docker container
run: docker-compose up -d
- name: install hardhat
working-directory: ./contracts
run: npm install --save-dev hardhat
- name: run precompile tests
working-directory: ./contracts
run: npx hardhat test
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ profile.cov
/dashboard/assets/package-lock.json

**/yarn-error.log
logs/

tests/spec-tests/

contracts/artifacts
contracts/cache
contracts/node_modules
12 changes: 12 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.20-alpine

RUN apk add bash make curl

RUN mkdir -p $GOPATH/src/github.com/Kava-Labs/go-ethereum
WORKDIR $GOPATH/src/github.com/Kava-Labs/go-ethereum

COPY . .
RUN make geth-dev
RUN cp ./build/bin/geth $GOPATH/bin/

CMD ["geth", "--dev", "--http", "--http.addr=0.0.0.0"]
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ geth:
@echo "Done building."
@echo "Run \"$(GOBIN)/geth\" to launch geth."

geth-dev:
$(GORUN) build/ci.go install -dev ./cmd/geth
@echo "Done building."
@echo "Run \"$(GOBIN)/geth\" to launch geth."

all:
$(GORUN) build/ci.go install

Expand Down Expand Up @@ -48,3 +53,6 @@ devtools:
env GOBIN= go install ./cmd/abigen
@type "solc" 2> /dev/null || echo 'Please install solc'
@type "protoc" 2> /dev/null || echo 'Please install protoc'

docker-build-dev:
docker build -t go-ethereum-dev -f Dockerfile.dev .
6 changes: 6 additions & 0 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func doInstall(cmdline []string) {
arch = flag.String("arch", "", "Architecture to cross build for")
cc = flag.String("cc", "", "C compiler to cross build with")
staticlink = flag.Bool("static", false, "Create statically-linked executable")
dev = flag.Bool("dev", false, "Build dev version")
)
flag.CommandLine.Parse(cmdline)

Expand All @@ -216,6 +217,11 @@ func doInstall(cmdline []string) {
// Disable CLI markdown doc generation in release builds.
buildTags := []string{"urfave_cli_no_docs"}

// Build dev version of geth. Build version includes additional precompiles.
if *dev {
buildTags = append(buildTags, "geth_test_precompile")
}

// Configure the build.
env := build.Env()
gobuild := tc.Go("build", buildFlags(env, *staticlink, buildTags)...)
Expand Down
14 changes: 14 additions & 0 deletions contracts/contracts/ExampleStatelessSum3.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pragma solidity ^0.8.0;

import "hardhat/console.sol";

address constant PRECOMPILED_STATELESS_SUM3_CONTRACT_ADDRESS = address(0x0b);

contract ExampleStatelessSum3 {
function sum3(uint256 a, uint256 b, uint256 c) public view returns (bytes memory) {
(bool ok, bytes memory data) = address(PRECOMPILED_STATELESS_SUM3_CONTRACT_ADDRESS).staticcall(abi.encode(a,b,c));
require(ok, "call to precompiled contract failed");

return data;
}
}
15 changes: 15 additions & 0 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
defaultNetwork: "geth",
networks: {
hardhat: {},
geth: {
url: "http://localhost:8545",
}
},
solidity: "0.8.19",
};

export default config;
Loading
Loading