mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
fix(libzkp): upgrade libzkp to v0.9.4 and add ccc SetLightMode (#522)
* Upgrade to prover `v0.9.4`, and add `SetLightMode` function. * set ccc light_mode = false for validator * fix * bump version --------- Co-authored-by: Zhang Zhuo <mycinbrin@gmail.com> Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
This commit is contained in:
parent
736cf7b1fb
commit
7cebee85a8
10 changed files with 98 additions and 20 deletions
|
|
@ -56,7 +56,7 @@ func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engin
|
||||||
bc: blockchain,
|
bc: blockchain,
|
||||||
checkCircuitCapacity: checkCircuitCapacity,
|
checkCircuitCapacity: checkCircuitCapacity,
|
||||||
db: db,
|
db: db,
|
||||||
circuitCapacityChecker: circuitcapacitychecker.NewCircuitCapacityChecker(),
|
circuitCapacityChecker: circuitcapacitychecker.NewCircuitCapacityChecker(false),
|
||||||
}
|
}
|
||||||
log.Info("created new BlockValidator", "CircuitCapacityChecker ID", validator.circuitCapacityChecker.ID)
|
log.Info("created new BlockValidator", "CircuitCapacityChecker ID", validator.circuitCapacityChecker.ID)
|
||||||
return validator
|
return validator
|
||||||
|
|
|
||||||
|
|
@ -243,7 +243,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
|
||||||
startCh: make(chan struct{}, 1),
|
startCh: make(chan struct{}, 1),
|
||||||
resubmitIntervalCh: make(chan time.Duration),
|
resubmitIntervalCh: make(chan time.Duration),
|
||||||
resubmitAdjustCh: make(chan *intervalAdjust, resubmitAdjustChanSize),
|
resubmitAdjustCh: make(chan *intervalAdjust, resubmitAdjustChanSize),
|
||||||
circuitCapacityChecker: circuitcapacitychecker.NewCircuitCapacityChecker(),
|
circuitCapacityChecker: circuitcapacitychecker.NewCircuitCapacityChecker(true),
|
||||||
}
|
}
|
||||||
log.Info("created new worker", "CircuitCapacityChecker ID", worker.circuitCapacityChecker.ID)
|
log.Info("created new worker", "CircuitCapacityChecker ID", worker.circuitCapacityChecker.ID)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 4 // Major version component of the current release
|
VersionMajor = 4 // Major version component of the current release
|
||||||
VersionMinor = 4 // Minor version component of the current release
|
VersionMinor = 4 // Minor version component of the current release
|
||||||
VersionPatch = 15 // Patch version component of the current release
|
VersionPatch = 16 // Patch version component of the current release
|
||||||
VersionMeta = "sepolia" // Version metadata to append to the version string
|
VersionMeta = "sepolia" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,14 @@ type CircuitCapacityChecker struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCircuitCapacityChecker creates a new CircuitCapacityChecker
|
// NewCircuitCapacityChecker creates a new CircuitCapacityChecker
|
||||||
func NewCircuitCapacityChecker() *CircuitCapacityChecker {
|
func NewCircuitCapacityChecker(lightMode bool) *CircuitCapacityChecker {
|
||||||
creationMu.Lock()
|
creationMu.Lock()
|
||||||
defer creationMu.Unlock()
|
defer creationMu.Unlock()
|
||||||
|
|
||||||
id := C.new_circuit_capacity_checker()
|
id := C.new_circuit_capacity_checker()
|
||||||
return &CircuitCapacityChecker{ID: uint64(id)}
|
ccc := &CircuitCapacityChecker{ID: uint64(id)}
|
||||||
|
ccc.SetLightMode(lightMode)
|
||||||
|
return ccc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset resets a CircuitCapacityChecker
|
// Reset resets a CircuitCapacityChecker
|
||||||
|
|
@ -169,3 +171,26 @@ func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error
|
||||||
|
|
||||||
return result.TxNum == uint64(expected), result.TxNum, nil
|
return result.TxNum == uint64(expected), result.TxNum, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLightMode sets to ccc light mode
|
||||||
|
func (ccc *CircuitCapacityChecker) SetLightMode(lightMode bool) error {
|
||||||
|
ccc.Lock()
|
||||||
|
defer ccc.Unlock()
|
||||||
|
|
||||||
|
log.Debug("ccc set_light_mode start", "id", ccc.ID)
|
||||||
|
rawResult := C.set_light_mode(C.uint64_t(ccc.ID), C.bool(lightMode))
|
||||||
|
defer func() {
|
||||||
|
C.free(unsafe.Pointer(rawResult))
|
||||||
|
}()
|
||||||
|
log.Debug("ccc set_light_mode end", "id", ccc.ID)
|
||||||
|
|
||||||
|
result := &WrappedCommonResult{}
|
||||||
|
if err := json.Unmarshal([]byte(C.GoString(rawResult)), result); err != nil {
|
||||||
|
return fmt.Errorf("fail to json unmarshal set_light_mode result, id: %d, err: %w", ccc.ID, err)
|
||||||
|
}
|
||||||
|
if result.Error != "" {
|
||||||
|
return fmt.Errorf("fail to set_light_mode in CircuitCapacityChecker, id: %d, err: %w", ccc.ID, result.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
24
rollup/circuitcapacitychecker/libzkp/Cargo.lock
generated
24
rollup/circuitcapacitychecker/libzkp/Cargo.lock
generated
|
|
@ -16,7 +16,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aggregator"
|
name = "aggregator"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ark-std",
|
"ark-std",
|
||||||
"env_logger 0.10.0",
|
"env_logger 0.10.0",
|
||||||
|
|
@ -297,7 +297,7 @@ checksum = "3c6ed94e98ecff0c12dd1b04c15ec0d7d9458ca8fe806cea6f12954efe74c63b"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bus-mapping"
|
name = "bus-mapping"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eth-types",
|
"eth-types",
|
||||||
"ethers-core",
|
"ethers-core",
|
||||||
|
|
@ -971,7 +971,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "eth-types"
|
name = "eth-types"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ethers-core",
|
"ethers-core",
|
||||||
"ethers-signers",
|
"ethers-signers",
|
||||||
|
|
@ -1128,7 +1128,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "external-tracer"
|
name = "external-tracer"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eth-types",
|
"eth-types",
|
||||||
"geth-utils",
|
"geth-utils",
|
||||||
|
|
@ -1308,7 +1308,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gadgets"
|
name = "gadgets"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"digest 0.7.6",
|
"digest 0.7.6",
|
||||||
"eth-types",
|
"eth-types",
|
||||||
|
|
@ -1340,7 +1340,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "geth-utils"
|
name = "geth-utils"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"env_logger 0.9.3",
|
"env_logger 0.9.3",
|
||||||
"gobuild 0.1.0-alpha.2 (git+https://github.com/scroll-tech/gobuild.git)",
|
"gobuild 0.1.0-alpha.2 (git+https://github.com/scroll-tech/gobuild.git)",
|
||||||
|
|
@ -1503,7 +1503,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "halo2-mpt-circuits"
|
name = "halo2-mpt-circuits"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/mpt-circuit.git?tag=v0.6.5#0bae9eeb813583c11f6db1f961a7e92f8c9bda82"
|
source = "git+https://github.com/scroll-tech/mpt-circuit.git?tag=v0.7.0#578c210ceb88d3c143ee2a013ad836d19285d9c1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ethers-core",
|
"ethers-core",
|
||||||
"halo2_proofs",
|
"halo2_proofs",
|
||||||
|
|
@ -1949,7 +1949,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "keccak256"
|
name = "keccak256"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"env_logger 0.9.3",
|
"env_logger 0.9.3",
|
||||||
"eth-types",
|
"eth-types",
|
||||||
|
|
@ -2157,7 +2157,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mock"
|
name = "mock"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eth-types",
|
"eth-types",
|
||||||
"ethers-core",
|
"ethers-core",
|
||||||
|
|
@ -2173,7 +2173,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mpt-zktrie"
|
name = "mpt-zktrie"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eth-types",
|
"eth-types",
|
||||||
"halo2-mpt-circuits",
|
"halo2-mpt-circuits",
|
||||||
|
|
@ -2595,7 +2595,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prover"
|
name = "prover"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aggregator",
|
"aggregator",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|
@ -4212,7 +4212,7 @@ checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zkevm-circuits"
|
name = "zkevm-circuits"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.2#2723b82fb5d538d6fcc7b2dd0d84d3df8818499f"
|
source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.4#40f4758f5b4b5a5c82fb312ee58492487f181185"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"array-init",
|
"array-init",
|
||||||
"bus-mapping",
|
"bus-mapping",
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ maingate = { git = "https://github.com/scroll-tech/halo2wrong", branch = "halo2-
|
||||||
halo2curves = { git = "https://github.com/scroll-tech/halo2curves.git", branch = "0.3.1-derive-serde" }
|
halo2curves = { git = "https://github.com/scroll-tech/halo2curves.git", branch = "0.3.1-derive-serde" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.9.2", default-features = false, features = ["parallel_syn", "scroll", "shanghai"] }
|
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.9.4", default-features = false, features = ["parallel_syn", "scroll", "shanghai"] }
|
||||||
|
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
|
#include <stdbool.h>
|
||||||
#include<stdint.h>
|
#include<stdint.h>
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
uint64_t new_circuit_capacity_checker();
|
uint64_t new_circuit_capacity_checker();
|
||||||
void reset_circuit_capacity_checker(uint64_t id);
|
void reset_circuit_capacity_checker(uint64_t id);
|
||||||
char* apply_tx(uint64_t id, char *tx_traces);
|
char* apply_tx(uint64_t id, char *tx_traces);
|
||||||
char* apply_block(uint64_t id, char *block_trace);
|
char* apply_block(uint64_t id, char *block_trace);
|
||||||
char* get_tx_num(uint64_t id);
|
char* get_tx_num(uint64_t id);
|
||||||
|
char* set_light_mode(uint64_t id, bool light_mode);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,11 @@ pub mod checker {
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::ptr::null;
|
use std::ptr::null;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
|
pub struct CommonResult {
|
||||||
|
pub error: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct RowUsageResult {
|
pub struct RowUsageResult {
|
||||||
pub acc_row_usage: Option<RowUsage>,
|
pub acc_row_usage: Option<RowUsage>,
|
||||||
|
|
@ -218,6 +223,40 @@ pub mod checker {
|
||||||
|result| result,
|
|result| result,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn set_light_mode(id: u64, light_mode: bool) -> *const c_char {
|
||||||
|
let result = set_light_mode_inner(id, light_mode);
|
||||||
|
let r = match result {
|
||||||
|
Ok(()) => CommonResult { error: None },
|
||||||
|
Err(e) => CommonResult {
|
||||||
|
error: Some(format!("{e:?}")),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
serde_json::to_vec(&r).map_or(null(), vec_to_c_char)
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn set_light_mode_inner(id: u64, light_mode: bool) -> Result<(), Error> {
|
||||||
|
log::debug!("ccc set_light_mode raw input, id: {id}");
|
||||||
|
panic::catch_unwind(|| {
|
||||||
|
CHECKERS
|
||||||
|
.get_mut()
|
||||||
|
.ok_or(anyhow!(
|
||||||
|
"fail to get circuit capacity checkers map in set_light_mode"
|
||||||
|
))?
|
||||||
|
.get_mut(&id)
|
||||||
|
.ok_or(anyhow!(
|
||||||
|
"fail to get circuit capacity checker (id: {id}) in set_light_mode"
|
||||||
|
))?
|
||||||
|
.set_light_mode(light_mode);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.map_or_else(
|
||||||
|
|e| bail!("circuit capacity checker (id: {id}) error in set_light_mode: {e:?}"),
|
||||||
|
|result| result,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) mod utils {
|
pub(crate) mod utils {
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,10 @@ type CircuitCapacityChecker struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCircuitCapacityChecker creates a new CircuitCapacityChecker
|
// NewCircuitCapacityChecker creates a new CircuitCapacityChecker
|
||||||
func NewCircuitCapacityChecker() *CircuitCapacityChecker {
|
func NewCircuitCapacityChecker(lightMode bool) *CircuitCapacityChecker {
|
||||||
return &CircuitCapacityChecker{ID: rand.Uint64()}
|
ccc := &CircuitCapacityChecker{ID: rand.Uint64()}
|
||||||
|
ccc.SetLightMode(lightMode)
|
||||||
|
return ccc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset resets a ccc, but need to do nothing in mock_ccc.
|
// Reset resets a ccc, but need to do nothing in mock_ccc.
|
||||||
|
|
@ -55,6 +57,11 @@ func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error
|
||||||
return true, uint64(expected), nil
|
return true, uint64(expected), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLightMode sets to ccc light mode
|
||||||
|
func (ccc *CircuitCapacityChecker) SetLightMode(lightMode bool) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// ScheduleError schedules an error for a tx (see `ApplyTransaction`), only used in tests.
|
// ScheduleError schedules an error for a tx (see `ApplyTransaction`), only used in tests.
|
||||||
func (ccc *CircuitCapacityChecker) ScheduleError(cnt int, err error) {
|
func (ccc *CircuitCapacityChecker) ScheduleError(cnt int, err error) {
|
||||||
ccc.countdown = cnt
|
ccc.countdown = cnt
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ var (
|
||||||
ErrBlockRowConsumptionOverflow = errors.New("block row consumption overflow")
|
ErrBlockRowConsumptionOverflow = errors.New("block row consumption overflow")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type WrappedCommonResult struct {
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type WrappedRowUsage struct {
|
type WrappedRowUsage struct {
|
||||||
AccRowUsage *types.RowUsage `json:"acc_row_usage,omitempty"`
|
AccRowUsage *types.RowUsage `json:"acc_row_usage,omitempty"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue