legacymimc

package
v1.71.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package legacymimc 提供 gnark-crypto v0.5.3 的旧版 MiMC 实现。 chain33 升级 go-ethereum v1.14.8 后 gnark-crypto 升至 v0.12.1, 其 MiMC round constants 从 sha3.Sum256 改为 keccak256,导致 hash 输出变化。 为保持 zksync/mix 链上已有数据兼容,保留旧实现。

Index

Constants

View Source
const BlockSize = fr.Bytes

BlockSize size that mimc consumes

Variables

This section is empty.

Functions

func NewMiMC

func NewMiMC(seed string) hash.Hash

NewMiMC returns a MiMCImpl object, pure-go reference implementation

func Sum

func Sum(seed string, msg []byte) ([]byte, error)

Sum computes the mimc hash of msg from seed

Types

type CircuitMiMC

type CircuitMiMC struct {
	// contains filtered or unexported fields
}

CircuitMiMC 电路内 MiMC 实现,使用旧版 round constants(sha3.Sum256 推导)。 参考 gnark v0.9.0 std/hash/mimc,但允许注入自定义 params 以保持链上协议兼容。

func NewCircuitMiMC

func NewCircuitMiMC(api frontend.API, seed string) (CircuitMiMC, error)

NewCircuitMiMC returns a CircuitMiMC instance with given seed's old constants. 返回 (CircuitMiMC, error) 以对齐 gnark 上游 NewMiMC 的签名风格;本实现参数派生不会失败,error 恒为 nil。

func (*CircuitMiMC) Reset

func (h *CircuitMiMC) Reset()

Reset resets the Hash to its initial state.

func (*CircuitMiMC) Sum

func (h *CircuitMiMC) Sum() frontend.Variable

Sum hash (in r1cs form) using Miyaguchi–Preneel: https://en.wikipedia.org/wiki/One-way_compression_function 与 gnark v0.5.2 电路实现保持一致:h = E(stream, h.h) + stream

func (*CircuitMiMC) Write

func (h *CircuitMiMC) Write(data ...frontend.Variable)

Write adds more data to the running hash.

type Params

type Params []fr.Element

Params constants for the mimc hash function

func NewParams

func NewParams(seed string) Params

NewParams creates new mimc object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL