Skip to content

Commit

Permalink
Merge branch 'develop' into env1-sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop authored Apr 11, 2024
2 parents fcbf83b + b52d43c commit 133547c
Show file tree
Hide file tree
Showing 42 changed files with 487 additions and 170 deletions.
1 change: 1 addition & 0 deletions bridge-history-api/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type FetcherConfig struct {
DAIGatewayAddr string `json:"DAIGatewayAddr"`
USDCGatewayAddr string `json:"USDCGatewayAddr"`
LIDOGatewayAddr string `json:"LIDOGatewayAddr"`
PufferGatewayAddr string `json:"PufferGatewayAddr"`
ERC721GatewayAddr string `json:"ERC721GatewayAddr"`
ERC1155GatewayAddr string `json:"ERC1155GatewayAddr"`
ScrollChainAddr string `json:"ScrollChainAddr"`
Expand Down
5 changes: 5 additions & 0 deletions bridge-history-api/internal/logic/l1_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func NewL1FetcherLogic(cfg *config.FetcherConfig, db *gorm.DB, client *ethclient
gatewayList = append(gatewayList, common.HexToAddress(cfg.LIDOGatewayAddr))
}

if common.HexToAddress(cfg.PufferGatewayAddr) != (common.Address{}) {
addressList = append(addressList, common.HexToAddress(cfg.PufferGatewayAddr))
gatewayList = append(gatewayList, common.HexToAddress(cfg.PufferGatewayAddr))
}

log.Info("L1 Fetcher configured with the following address list", "addresses", addressList, "gateways", gatewayList)

f := &L1FetcherLogic{
Expand Down
7 changes: 6 additions & 1 deletion bridge-history-api/internal/logic/l2_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ func NewL2FetcherLogic(cfg *config.FetcherConfig, db *gorm.DB, client *ethclient

if common.HexToAddress(cfg.LIDOGatewayAddr) != (common.Address{}) {
addressList = append(addressList, common.HexToAddress(cfg.LIDOGatewayAddr))
gatewayList = append(gatewayList, common.HexToAddress(cfg.USDCGatewayAddr))
gatewayList = append(gatewayList, common.HexToAddress(cfg.LIDOGatewayAddr))
}

if common.HexToAddress(cfg.PufferGatewayAddr) != (common.Address{}) {
addressList = append(addressList, common.HexToAddress(cfg.PufferGatewayAddr))
gatewayList = append(gatewayList, common.HexToAddress(cfg.PufferGatewayAddr))
}

log.Info("L2 Fetcher configured with the following address list", "addresses", addressList, "gateways", gatewayList)
Expand Down
48 changes: 32 additions & 16 deletions common/libzkp/impl/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion common/libzkp/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ bls12_381 = { git = "https://github.com/scroll-tech/bls12_381", branch = "feat/i

[dependencies]
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.1" }
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.10.0rc3", default-features = false, features = ["parallel_syn", "scroll", "shanghai"] }
snark-verifier-sdk = { git = "https://github.com/scroll-tech/snark-verifier", branch = "develop", default-features = false, features = ["loader_halo2", "loader_evm", "halo2-pse"] }
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.10.2", default-features = false, features = ["parallel_syn", "scroll", "shanghai"] }

base64 = "0.13.0"
env_logger = "0.9.0"
Expand Down
29 changes: 26 additions & 3 deletions common/libzkp/impl/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use prover::{
utils::{chunk_trace_to_witness_block, init_env_and_log},
BatchProof, BlockTrace, ChunkHash, ChunkProof,
};
use snark_verifier_sdk::verify_evm_calldata;
use std::{cell::OnceCell, env, ptr::null};

static mut PROVER: OnceCell<Prover> = OnceCell::new();
Expand Down Expand Up @@ -148,11 +149,33 @@ pub unsafe extern "C" fn gen_batch_proof(

/// # Safety
#[no_mangle]
pub unsafe extern "C" fn verify_batch_proof(proof: *const c_char) -> c_char {
pub unsafe extern "C" fn verify_batch_proof(
proof: *const c_char,
fork_name: *const c_char,
) -> c_char {
let proof = c_char_to_vec(proof);
let proof = serde_json::from_slice::<BatchProof>(proof.as_slice()).unwrap();

let verified = panic_catch(|| VERIFIER.get().unwrap().verify_agg_evm_proof(proof));
let fork_name_str = c_char_to_str(fork_name);
let fork_id = match fork_name_str {
"" => 0,
"shanghai" => 0,
"bernoulli" => 1,
_ => {
log::warn!("unexpected fork_name {fork_name_str}, treated as bernoulli");
1
}
};
let verified = panic_catch(|| {
if fork_id == 0 {
// before upgrade#2(EIP4844)
verify_evm_calldata(
include_bytes!("evm_verifier_fork_1.bin").to_vec(),
proof.calldata(),
)
} else {
VERIFIER.get().unwrap().verify_agg_evm_proof(proof)
}
});
verified.unwrap_or(false) as c_char
}

Expand Down
Binary file added common/libzkp/impl/src/evm_verifier_fork_1.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion common/libzkp/interface/libzkp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ void init_batch_verifier(char* params_dir, char* assets_dir);
char* get_batch_vk();
char* check_chunk_proofs(char* chunk_proofs);
char* gen_batch_proof(char* chunk_hashes, char* chunk_proofs);
char verify_batch_proof(char* proof);
char verify_batch_proof(char* proof, char* fork_name);

void init_chunk_prover(char* params_dir, char* assets_dir);
void init_chunk_verifier(char* params_dir, char* assets_dir);
Expand Down
2 changes: 2 additions & 0 deletions common/types/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type Identity struct {
ProverVersion string `json:"prover_version"`
// Challenge unique challenge generated by manager
Challenge string `json:"challenge"`
// HardForkName the hard fork name
HardForkName string `json:"hard_fork_name"`
}

// GenerateToken generates token
Expand Down
2 changes: 1 addition & 1 deletion common/types/message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestIdentityHash(t *testing.T) {
hash, err := identity.Hash()
assert.NoError(t, err)

expectedHash := "83f5e0ad023e9c1de639ab07b9b4cb972ec9dbbd2524794c533a420a5b137721"
expectedHash := "9b8b00f5655411ec1d68ba1666261281c5414aedbda932e5b6a9f7f1b114fdf2"
assert.Equal(t, expectedHash, hex.EncodeToString(hash))
}

Expand Down
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.3.84"
var tag = "v4.3.88"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
12 changes: 7 additions & 5 deletions contracts/src/L1/rollup/IScrollChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

pragma solidity ^0.8.24;

/// @title IScrollChain
/// @notice The interface for ScrollChain.
interface IScrollChain {
/**********
* Events *
Expand Down Expand Up @@ -43,23 +45,23 @@ interface IScrollChain {
* Public View Functions *
*************************/

/// @notice The latest finalized batch index.
/// @return The latest finalized batch index.
function lastFinalizedBatchIndex() external view returns (uint256);

/// @notice Return the batch hash of a committed batch.
/// @param batchIndex The index of the batch.
/// @return The batch hash of a committed batch.
function committedBatches(uint256 batchIndex) external view returns (bytes32);

/// @notice Return the state root of a committed batch.
/// @param batchIndex The index of the batch.
/// @return The state root of a committed batch.
function finalizedStateRoots(uint256 batchIndex) external view returns (bytes32);

/// @notice Return the message root of a committed batch.
/// @param batchIndex The index of the batch.
/// @return The message root of a committed batch.
function withdrawRoots(uint256 batchIndex) external view returns (bytes32);

/// @notice Return whether the batch is finalized by batch index.
/// @param batchIndex The index of the batch.
/// @return Whether the batch is finalized by batch index.
function isBatchFinalized(uint256 batchIndex) external view returns (bool);

/*****************************
Expand Down
10 changes: 8 additions & 2 deletions contracts/src/L1/rollup/MultipleVersionRollupVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {IScrollChain} from "./IScrollChain.sol";
import {IRollupVerifier} from "../../libraries/verifier/IRollupVerifier.sol";
import {IZkEvmVerifier} from "../../libraries/verifier/IZkEvmVerifier.sol";

/// @title MultipleVersionRollupVerifier
/// @notice Verifies aggregate zk proofs using the appropriate verifier.
contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
/**********
* Events *
Expand Down Expand Up @@ -37,7 +39,7 @@ contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
*************/

/// @notice The address of ScrollChain contract.
address immutable scrollChain;
address public immutable scrollChain;

/***********
* Structs *
Expand All @@ -58,7 +60,7 @@ contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
/// The verifiers are sorted by batchIndex in increasing order.
mapping(uint256 => Verifier[]) public legacyVerifiers;

/// @notice Mapping from verifier version to the lastest used zkevm verifier.
/// @notice Mapping from verifier version to the latest used zkevm verifier.
mapping(uint256 => Verifier) public latestVerifier;

/***************
Expand Down Expand Up @@ -86,13 +88,16 @@ contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
*************************/

/// @notice Return the number of legacy verifiers.
/// @param _version The version of legacy verifiers.
/// @return The number of legacy verifiers.
function legacyVerifiersLength(uint256 _version) external view returns (uint256) {
return legacyVerifiers[_version].length;
}

/// @notice Compute the verifier should be used for specific batch.
/// @param _version The version of verifier to query.
/// @param _batchIndex The batch index to query.
/// @return The address of verifier.
function getVerifier(uint256 _version, uint256 _batchIndex) public view returns (address) {
// Normally, we will use the latest verifier.
Verifier memory _verifier = latestVerifier[_version];
Expand Down Expand Up @@ -144,6 +149,7 @@ contract MultipleVersionRollupVerifier is IRollupVerifier, Ownable {
************************/

/// @notice Update the address of zkevm verifier.
/// @param _version The version of the verifier.
/// @param _startBatchIndex The start batch index when the verifier will be used.
/// @param _verifier The address of new verifier.
function updateVerifier(
Expand Down
Loading

0 comments on commit 133547c

Please sign in to comment.