Skip to content

Commit

Permalink
Add frxUSD/sfrxUSD granite fork code change
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalex88 committed Jan 30, 2025
1 parent 50b3422 commit db35b2d
Show file tree
Hide file tree
Showing 18 changed files with 405 additions and 138 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

40 changes: 0 additions & 40 deletions .github/CONTRIBUTING.md

This file was deleted.

31 changes: 0 additions & 31 deletions .github/ISSUE_TEMPLATE/bug.md

This file was deleted.

17 changes: 0 additions & 17 deletions .github/ISSUE_TEMPLATE/feature.md

This file was deleted.

9 changes: 0 additions & 9 deletions .github/ISSUE_TEMPLATE/question.md

This file was deleted.

11 changes: 0 additions & 11 deletions .github/no-response.yml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/stale.yml

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release docker image

on:
workflow_dispatch:
inputs:
version:
description: Version to publish (will be the docker tag)
required: true

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: ghcr.io/fraxfinance/fraxtal-op-geth:${{ inputs.version }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
COMMIT=${{ github.sha }}
VERSION=${{ inputs.version }}
BUILDNUM=${{ github.run_number }}
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Multi arch target
ARG TARGETARCH

# Support setting various labels on the final image
ARG COMMIT=""
ARG VERSION=""
ARG BUILDNUM=""

# Build Geth in a stock Go builder container
FROM golang:1.23-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder

RUN apk add --no-cache gcc musl-dev linux-headers git

Expand All @@ -14,7 +17,7 @@ COPY go.sum /go-ethereum/
RUN cd /go-ethereum && go mod download

ADD . /go-ethereum
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth
RUN cd /go-ethereum && go run build/ci.go install -static -arch=$TARGETARCH ./cmd/geth

# Pull Geth into a second stage deploy alpine container
FROM alpine:latest
Expand Down
52 changes: 42 additions & 10 deletions consensus/misc/create2deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,59 @@ func TestEnsureCreate2Deployer(t *testing.T) {
tt.override(&cfg)
}
state := &stateDb{
codeExists: tt.codeExists,
codeMap: map[common.Address][]byte{},
}
EnsureCreate2Deployer(&cfg, tt.timestamp, state)
assert.Equal(t, tt.applied, state.codeSet)
assert.Equal(t, tt.applied, state.GetCodeSize(create2DeployerAddress) > 0)
})
}
}

type stateDb struct {
vm.StateDB
codeExists bool
codeSet bool
codeMap map[common.Address][]byte
storage map[common.Address]map[common.Hash]common.Hash
}

func (s *stateDb) GetCodeSize(_ common.Address) int {
if s.codeExists {
return 1
func (s *stateDb) GetCode(addr common.Address) []byte {
s.initCodeMap()
return s.codeMap[addr]
}

func (s *stateDb) GetCodeSize(addr common.Address) int {
s.initCodeMap()
return len(s.codeMap[addr])
}

func (s *stateDb) SetCode(addr common.Address, code []byte) {
s.initCodeMap()
s.codeMap[addr] = code
}

func (s *stateDb) initCodeMap() {
if s.codeMap == nil {
s.codeMap = make(map[common.Address][]byte)
}
return 0
}

func (s *stateDb) SetCode(_ common.Address, _ []byte) {
s.codeSet = true
func (s *stateDb) GetState(addr common.Address, key common.Hash) common.Hash {
if s.storage == nil {
return common.Hash{}
}
if _, ok := s.storage[addr]; !ok {
return common.Hash{}
}

return s.storage[addr][key]
}

func (s *stateDb) SetState(addr common.Address, key common.Hash, value common.Hash) {
if s.storage == nil {
s.storage = make(map[common.Address]map[common.Hash]common.Hash)
}
if _, ok := s.storage[addr]; !ok {
s.storage[addr] = map[common.Hash]common.Hash{key: value}
} else {
s.storage[addr][key] = value
}
}
22 changes: 22 additions & 0 deletions consensus/misc/frxusd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package misc

import (
"github.com/ethereum/go-ethereum/consensus/misc/frxusd"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
)

func EnsureFrxUSD(c *params.ChainConfig, timestamp uint64, db vm.StateDB) {
if !c.IsOptimism() || c.GraniteTime == nil || *c.GraniteTime != timestamp {
return
}

switch c.ChainID.Uint64() {
case 2521:
frxusd.RunDevnetMigration(c, timestamp, db)
case 2522:
frxusd.RunTestnetMigration(c, timestamp, db)
default:
frxusd.RunMainnetMigration(c, timestamp, db)
}
}
28 changes: 28 additions & 0 deletions consensus/misc/frxusd/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package frxusd

import "github.com/ethereum/go-ethereum/common"

var frxUSDMigrationProxyCodeAddress = common.HexToAddress("0xfc0000000000000000000000000000000000000a")
var frxUSDProxyAdminAddress = common.HexToAddress("0xfc0000000000000000000000000000000000000a")
var frxUSDProxyAdminSlot = common.HexToHash("0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103")
var frxUSDProxyImplementationSlot = common.HexToHash("0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc")

var frxUSDAddress = common.HexToAddress("0xfc00000000000000000000000000000000000001")
var frxUSDImplementationAddress = common.HexToAddress("0xfcc0d30000000000000000000000000000000001")
var frxUSDNameBytes = common.HexToHash("0x4672617820555344000000000000000000000000000000000000000000000010") // Frax USD
var frxUSDSymbolBytes = common.HexToHash("0x667278555344000000000000000000000000000000000000000000000000000c") // frxUSD
var frxUSDL1Token = common.FromHex("0xCAcd6fd266aF91b8AeD52aCCc382b4e165586E29")

var sfrxUSDAddress = common.HexToAddress("0xfc00000000000000000000000000000000000008")
var sfrxUSDImplementationAddress = common.HexToAddress("0xfcc0d30000000000000000000000000000000008")
var sfrxUSDNameBytes = common.HexToHash("0x5374616b6564204672617820555344000000000000000000000000000000001e") // Staked Frax USD
var sfrxUSDSymbolBytes = common.HexToHash("0x736672785553440000000000000000000000000000000000000000000000000e") // sfrxUSD
var sfrxUSDL1Token = common.FromHex("0xcf62F905562626CfcDD2261162a51fd02Fc9c5b6")

var frxUSDL1TokenReplacementIndexes = []uint{2137, 6850, 7218}
var sfrxUSDL1TokenReplacementIndexes = []uint{2137, 6850, 7218}

var testnetFrxUSDL1TokenReplacementIndexes = []uint{2137, 6962, 7330}

var devnetFrxUSDL1TokenReplacementIndexes = []uint{693, 1303}
var devnetSfrxUSDL1TokenReplacementIndexes = []uint{693, 1303}
41 changes: 41 additions & 0 deletions consensus/misc/frxusd/devnet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package frxusd

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)

func RunDevnetMigration(c *params.ChainConfig, timestamp uint64, db vm.StateDB) {
log.Info("Getting frxUSD/sfrxUSD proxy code", "address", frxUSDMigrationProxyCodeAddress)
proxyCode := db.GetCode(frxUSDMigrationProxyCodeAddress)
log.Info("Moving frxUSD implementation", "from", frxUSDAddress, "to", frxUSDImplementationAddress)
frxUSDImplementationCode := db.GetCode(frxUSDAddress)
for _, i := range devnetFrxUSDL1TokenReplacementIndexes {
copy(frxUSDImplementationCode[i:], frxUSDL1Token)
}
db.SetCode(frxUSDImplementationAddress, frxUSDImplementationCode)
log.Info("Setting frxUSD proxy", "address", frxUSDAddress)
db.SetCode(frxUSDAddress, proxyCode)
log.Info("Setting frxUSD storage variables", "address", frxUSDAddress)
db.SetState(frxUSDAddress, frxUSDProxyAdminSlot, common.BytesToHash(common.LeftPadBytes(frxUSDProxyAdminAddress.Bytes(), common.HashLength)))
db.SetState(frxUSDAddress, frxUSDProxyImplementationSlot, common.BytesToHash(common.LeftPadBytes(frxUSDImplementationAddress.Bytes(), common.HashLength)))
db.SetState(frxUSDAddress, common.HexToHash("0x03"), frxUSDNameBytes)
db.SetState(frxUSDAddress, common.HexToHash("0x04"), frxUSDSymbolBytes)
db.SetState(frxUSDAddress, common.HexToHash("0x04"), frxUSDSymbolBytes)

log.Info("Moving sfrxUSD implementation", "from", sfrxUSDAddress, "to", sfrxUSDImplementationAddress)
sfrxUSDImplementationCode := db.GetCode(sfrxUSDAddress)
for _, i := range devnetSfrxUSDL1TokenReplacementIndexes {
copy(sfrxUSDImplementationCode[i:], sfrxUSDL1Token)
}
db.SetCode(sfrxUSDImplementationAddress, sfrxUSDImplementationCode)
log.Info("Setting sfrxUSD proxy", "address", frxUSDAddress)
db.SetCode(sfrxUSDAddress, proxyCode)
log.Info("Setting sfrxUSD proxy and storage", "address", sfrxUSDAddress)
db.SetState(sfrxUSDAddress, frxUSDProxyAdminSlot, common.BytesToHash(common.LeftPadBytes(frxUSDProxyAdminAddress.Bytes(), common.HashLength)))
db.SetState(sfrxUSDAddress, frxUSDProxyImplementationSlot, common.BytesToHash(common.LeftPadBytes(sfrxUSDImplementationAddress.Bytes(), common.HashLength)))
db.SetState(sfrxUSDAddress, common.HexToHash("0x03"), sfrxUSDNameBytes)
db.SetState(sfrxUSDAddress, common.HexToHash("0x04"), sfrxUSDSymbolBytes)
}
Loading

0 comments on commit db35b2d

Please sign in to comment.