Skip to content

Commit

Permalink
all: cleanup code that supported forks
Browse files Browse the repository at this point in the history
since we're using chain bumps now,
and the blockstore of LTS is pruned,
we don't need forks anymore.
  • Loading branch information
altergui authored and p4u committed Jun 16, 2024
1 parent 8fe8f43 commit 0696d74
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 104 deletions.
30 changes: 0 additions & 30 deletions config/forks.go

This file was deleted.

21 changes: 0 additions & 21 deletions crypto/zk/circuit/circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"sync"
"time"

"go.vocdoni.io/dvote/config"
"go.vocdoni.io/dvote/log"
)

Expand Down Expand Up @@ -91,26 +90,6 @@ func Init() error {
return SetGlobal(DefaultZkCircuitVersion)
}

// DownloadDefaultArtifacts ensures the default circuit is cached locally
func DownloadDefaultArtifacts() error {
_, err := LoadVersion(DefaultZkCircuitVersion)
if err != nil {
return fmt.Errorf("could not load zk verification keys: %w", err)
}
return nil
}

// DownloadArtifactsForChainID ensures all circuits needed for chainID are cached locally
func DownloadArtifactsForChainID(chainID string) error {
if config.ForksForChainID(chainID).VoceremonyForkBlock > 0 {
_, err := LoadVersion(PreVoceremonyForkZkCircuitVersion)
if err != nil {
return fmt.Errorf("could not load zk verification keys: %w", err)
}
}
return DownloadDefaultArtifacts()
}

// LoadVersion loads the circuit artifacts based on the version provided.
// First, tries to load the artifacts from local storage, if they are not
// available, tries to download from their remote location.
Expand Down
26 changes: 0 additions & 26 deletions crypto/zk/circuit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ func (conf *Config) SupportsCensusSize(maxCensusSize uint64) bool {
// DefaultZkCircuitVersion is the circuit version used by default
const DefaultZkCircuitVersion = V1_0_0

// PreVoceremonyForkZkCircuitVersion is the circuit version used before VoceremonyForkBlock
const PreVoceremonyForkZkCircuitVersion = V0_0_1

// Version strings
const (
V0_0_1 = "v0.0.1"
V1_0_0 = "v1.0.0"
)

Expand All @@ -90,28 +86,6 @@ const (
// the remote and local location of the circuits artifacts and their metadata
// such as artifacts hash or the number of parameters.
var CircuitsConfigurations = map[string]*Config{
V0_0_1: {
Version: V0_0_1,
URI: "https://raw.githubusercontent.com/vocdoni/zk-franchise-proof-circuit/master",
CircuitPath: "artifacts/zkCensus/dev/160",
Levels: 160, // ZkCircuit number of levels
ProvingKeyHash: hexToBytes("0xe359b256e5e3c78acaccf8dab5dc4bea99a2f07b2a05e935b5ca658c714dea4a"),
ProvingKeyFilename: "proving_key.zkey",
VerificationKeyHash: hexToBytes("0x235e55571812f8e324e73e37e53829db0c4ac8f68469b9b953876127c97b425f"),
VerificationKeyFilename: "verification_key.json",
WasmHash: hexToBytes("0x80a73567f6a4655d4332301efcff4bc5711bb48176d1c71fdb1e48df222ac139"),
WasmFilename: "circuit.wasm",
PublicSignals: map[string]int{
"electionId[0]": 0,
"electionId[1]": 1,
"nullifier": 2,
"voteHash[0]": 3,
"voteHash[1]": 4,
"sikRoot": 5,
"censusRoot": 6,
"voteWeight": 7,
},
},
V1_0_0: {
Version: V1_0_0,
URI: "https://raw.githubusercontent.com/vocdoni/zk-voceremony",
Expand Down
14 changes: 0 additions & 14 deletions vochain/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,6 @@ func (app *BaseApplication) beginBlock(t time.Time, height uint32) {
}
app.State.SetHeight(height)

err := app.SetZkCircuit()
if err != nil {
log.Fatalf("failed to set ZkCircuit: %w", err)
}
go app.State.CachePurge(height)
app.State.OnBeginBlock(vstate.BeginBlock{
Height: int64(height),
Expand Down Expand Up @@ -393,16 +389,6 @@ func (app *BaseApplication) Genesis() *genesis.Doc {
return app.genesisDoc
}

// SetZkCircuit ensures the global ZkCircuit is the correct for a chain that implements forks
func (app *BaseApplication) SetZkCircuit() error {
switch {
case app.Height() < config.ForksForChainID(app.chainID).VoceremonyForkBlock:
return circuit.SetGlobal(circuit.PreVoceremonyForkZkCircuitVersion)
default: // for example, if VoceremonyForkBlock == 0, or if Height is past the fork
return circuit.SetGlobal(circuit.DefaultZkCircuitVersion)
}
}

// IsSynchronizing informs if the blockchain is synchronizing or not.
func (app *BaseApplication) isSynchronizingTendermint() bool {
if app.Node == nil {
Expand Down
7 changes: 0 additions & 7 deletions vochain/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"go.vocdoni.io/dvote/config"
"go.vocdoni.io/dvote/crypto/ethereum"
"go.vocdoni.io/dvote/crypto/zk/circuit"
"go.vocdoni.io/dvote/vochain/genesis"

cometconfig "github.com/cometbft/cometbft/config"
Expand Down Expand Up @@ -281,12 +280,6 @@ func newTendermint(app *BaseApplication, localConfig *config.VochainCfg) (*comet
"nodeId", nodeKey.ID(),
"seed", tconfig.P2P.SeedMode)

// the chain might need additional ZkCircuits, now that we know the chainID ensure they are downloaded now,
// to avoid delays at beginBlock during a fork
if err := circuit.DownloadArtifactsForChainID(app.ChainID()); err != nil {
return nil, fmt.Errorf("cannot download zk circuits for chainID: %w", err)
}

// if GenesisEndOfChain cmdline flag was passed, override genesis
if localConfig.GenesisEndOfChain > 0 {
g := genesis.HardcodedForChainID(app.ChainID())
Expand Down
6 changes: 0 additions & 6 deletions vochain/transaction/vote_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"

"go.vocdoni.io/dvote/config"
"go.vocdoni.io/dvote/crypto/ethereum"
"go.vocdoni.io/dvote/log"
"go.vocdoni.io/dvote/util"
Expand Down Expand Up @@ -181,11 +180,6 @@ func (t *TransactionHandler) VoteTxCheck(vtx *vochaintx.Tx, forCommit bool) (*vs
if !valid {
return nil, fmt.Errorf("proof not valid")
}
// soft-fork: get nullifier from proof publicSignals
if nullifierCheckForkBlock := config.ForksForChainID(t.state.ChainID()).NullifierFromZkProof; nullifierCheckForkBlock > 0 &&
t.state.CurrentHeight() < nullifierCheckForkBlock {
vote.Nullifier = voteEnvelope.Nullifier
}
log.Debugw("new vote",
"type", "zkSNARK",
"weight", vote.Weight,
Expand Down

0 comments on commit 0696d74

Please sign in to comment.