mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Rename NetworkId to HashParameter
This commit is contained in:
parent
0e84fb487d
commit
758f77be3e
3 changed files with 29 additions and 29 deletions
|
|
@ -2,22 +2,22 @@ package vm
|
||||||
|
|
||||||
// Solidity interfaces for precompiles
|
// Solidity interfaces for precompiles
|
||||||
//
|
//
|
||||||
// enum NetworkId {
|
// enum HashParameter {
|
||||||
// MAINNET,
|
// MAINNET,
|
||||||
// TESTNET,
|
// TESTNET,
|
||||||
// NULLNET
|
// EMPTY
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// interface IHasher {
|
// interface IHasher {
|
||||||
// function poseidonHash(
|
// function poseidonHash(
|
||||||
// NetworkId networkId,
|
// HashParameter hashParameter,
|
||||||
// bytes32[] memory fields
|
// bytes32[] memory fields
|
||||||
// ) external view returns (bytes32);
|
// ) external view returns (bytes32);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// interface ISigner {
|
// interface ISigner {
|
||||||
// function verify(
|
// function verify(
|
||||||
// NetworkId networkId,
|
// HashParameter hashParameter,
|
||||||
// bytes32 pubKeyX,
|
// bytes32 pubKeyX,
|
||||||
// bytes32 pubKeyY,
|
// bytes32 pubKeyY,
|
||||||
// bytes32 signatureRX,
|
// bytes32 signatureRX,
|
||||||
|
|
@ -79,7 +79,7 @@ func (c *MinaPoseidon) Run(input []byte) ([]byte, error) {
|
||||||
calldata := input[4:]
|
calldata := input[4:]
|
||||||
|
|
||||||
unpacked, err := (abi.Arguments{{
|
unpacked, err := (abi.Arguments{{
|
||||||
Type: sol_uint8}, // networkId
|
Type: sol_uint8}, // hashParameter
|
||||||
{Type: sol_bytes32Arr}, // fields
|
{Type: sol_bytes32Arr}, // fields
|
||||||
}).Unpack(calldata)
|
}).Unpack(calldata)
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@ func (c *MinaPoseidon) Run(input []byte) ([]byte, error) {
|
||||||
return packErr("Unable to unpack calldata"), err
|
return packErr("Unable to unpack calldata"), err
|
||||||
}
|
}
|
||||||
|
|
||||||
networkId := unpacked[0].(uint8)
|
hashParameter := unpacked[0].(uint8)
|
||||||
fields := unpacked[1].([][32]uint8)
|
fields := unpacked[1].([][32]uint8)
|
||||||
|
|
||||||
output_buffer := [32]byte{}
|
output_buffer := [32]byte{}
|
||||||
|
|
@ -100,7 +100,7 @@ func (c *MinaPoseidon) Run(input []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !C.poseidon(
|
if !C.poseidon(
|
||||||
C.uint8_t(networkId),
|
C.uint8_t(hashParameter),
|
||||||
fields_ptr,
|
fields_ptr,
|
||||||
C.uintptr_t(len(fields)),
|
C.uintptr_t(len(fields)),
|
||||||
(*C.uint8_t)(&output_buffer[0]),
|
(*C.uint8_t)(&output_buffer[0]),
|
||||||
|
|
@ -128,7 +128,7 @@ func (c *MinaSigner) Run(input []byte) ([]byte, error) {
|
||||||
calldata := input[4:]
|
calldata := input[4:]
|
||||||
|
|
||||||
unpacked, err := (abi.Arguments{
|
unpacked, err := (abi.Arguments{
|
||||||
{Type: sol_uint8}, // networkId
|
{Type: sol_uint8}, // hashParameter
|
||||||
{Type: sol_bytes32}, // pubKeyX
|
{Type: sol_bytes32}, // pubKeyX
|
||||||
{Type: sol_bytes32}, // pubKeyY
|
{Type: sol_bytes32}, // pubKeyY
|
||||||
{Type: sol_bytes32}, // signatureRX
|
{Type: sol_bytes32}, // signatureRX
|
||||||
|
|
@ -140,7 +140,7 @@ func (c *MinaSigner) Run(input []byte) ([]byte, error) {
|
||||||
return packErr("Unable to unpack calldata"), err
|
return packErr("Unable to unpack calldata"), err
|
||||||
}
|
}
|
||||||
|
|
||||||
networkId := unpacked[0].(uint8)
|
hashParameter := unpacked[0].(uint8)
|
||||||
pubKeyX := unpacked[1].([32]uint8)
|
pubKeyX := unpacked[1].([32]uint8)
|
||||||
pubKeyY := unpacked[2].([32]uint8)
|
pubKeyY := unpacked[2].([32]uint8)
|
||||||
signatureRX := unpacked[3].([32]uint8)
|
signatureRX := unpacked[3].([32]uint8)
|
||||||
|
|
@ -157,7 +157,7 @@ func (c *MinaSigner) Run(input []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !C.verify(
|
if !C.verify(
|
||||||
C.uint8_t(networkId),
|
C.uint8_t(hashParameter),
|
||||||
(*C.uint8_t)(&pubKeyX[0]),
|
(*C.uint8_t)(&pubKeyX[0]),
|
||||||
(*C.uint8_t)(&pubKeyY[0]),
|
(*C.uint8_t)(&pubKeyY[0]),
|
||||||
(*C.uint8_t)(&signatureRX[0]),
|
(*C.uint8_t)(&signatureRX[0]),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ mod mina;
|
||||||
|
|
||||||
use std::array::TryFromSliceError;
|
use std::array::TryFromSliceError;
|
||||||
|
|
||||||
use mina::{Message, NetworkId};
|
use mina::{HashParameter, Message};
|
||||||
use mina_signer::{BaseField, CurvePoint, PubKey, ScalarField, Signature};
|
use mina_signer::{BaseField, CurvePoint, PubKey, ScalarField, Signature};
|
||||||
use o1_utils::FieldHelpers;
|
use o1_utils::FieldHelpers;
|
||||||
|
|
||||||
|
|
@ -24,9 +24,9 @@ pub unsafe extern "C" fn poseidon(
|
||||||
}
|
}
|
||||||
|
|
||||||
let network_id = match network_id {
|
let network_id = match network_id {
|
||||||
0x00 => NetworkId::Mainnet,
|
0x00 => HashParameter::Mainnet,
|
||||||
0x01 => NetworkId::Testnet,
|
0x01 => HashParameter::Testnet,
|
||||||
0x02 => NetworkId::Nullnet,
|
0x02 => HashParameter::Empty,
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -81,9 +81,9 @@ pub unsafe extern "C" fn verify(
|
||||||
}
|
}
|
||||||
|
|
||||||
let network_id = match network_id {
|
let network_id = match network_id {
|
||||||
0x00 => NetworkId::Mainnet,
|
0x00 => HashParameter::Mainnet,
|
||||||
0x01 => NetworkId::Testnet,
|
0x01 => HashParameter::Testnet,
|
||||||
0x02 => NetworkId::Nullnet,
|
0x02 => HashParameter::Empty,
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,19 @@ use o1_utils::{field_helpers::FieldHelpersError, FieldHelpers};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum NetworkId {
|
pub enum HashParameter {
|
||||||
Mainnet = 0x00,
|
Mainnet = 0x00,
|
||||||
Testnet = 0x01,
|
Testnet = 0x01,
|
||||||
Nullnet = 0x02,
|
Empty = 0x02,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<NetworkId> for u8 {
|
impl From<HashParameter> for u8 {
|
||||||
fn from(id: NetworkId) -> u8 {
|
fn from(id: HashParameter) -> u8 {
|
||||||
id as u8
|
id as u8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DomainParameter for NetworkId {
|
impl DomainParameter for HashParameter {
|
||||||
fn into_bytes(self) -> Vec<u8> {
|
fn into_bytes(self) -> Vec<u8> {
|
||||||
vec![self as u8]
|
vec![self as u8]
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +39,7 @@ impl Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hashable for Message {
|
impl Hashable for Message {
|
||||||
type D = NetworkId;
|
type D = HashParameter;
|
||||||
|
|
||||||
fn to_roinput(&self) -> ROInput {
|
fn to_roinput(&self) -> ROInput {
|
||||||
self.fields
|
self.fields
|
||||||
|
|
@ -47,16 +47,16 @@ impl Hashable for Message {
|
||||||
.fold(ROInput::new(), |roi, field| roi.append_field(*field))
|
.fold(ROInput::new(), |roi, field| roi.append_field(*field))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn domain_string(network_id: NetworkId) -> Option<String> {
|
fn domain_string(network_id: HashParameter) -> Option<String> {
|
||||||
match network_id {
|
match network_id {
|
||||||
NetworkId::Mainnet => "MinaSignatureMainnet".to_string().into(),
|
HashParameter::Mainnet => "MinaSignatureMainnet".to_string().into(),
|
||||||
NetworkId::Testnet => "CodaSignature".to_string().into(),
|
HashParameter::Testnet => "CodaSignature".to_string().into(),
|
||||||
NetworkId::Nullnet => None,
|
HashParameter::Empty => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn poseidon(msg: &Message, network_id: NetworkId) -> BaseField {
|
pub fn poseidon(msg: &Message, network_id: HashParameter) -> BaseField {
|
||||||
let mut hasher = mina_hasher::create_kimchi::<Message>(network_id);
|
let mut hasher = mina_hasher::create_kimchi::<Message>(network_id);
|
||||||
|
|
||||||
hasher.hash(msg)
|
hasher.hash(msg)
|
||||||
|
|
@ -66,7 +66,7 @@ pub fn verify(
|
||||||
signature: &Signature,
|
signature: &Signature,
|
||||||
pubkey: &PubKey,
|
pubkey: &PubKey,
|
||||||
msg: &Message,
|
msg: &Message,
|
||||||
network_id: NetworkId,
|
network_id: HashParameter,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut signer = mina_signer::create_kimchi::<Message>(network_id);
|
let mut signer = mina_signer::create_kimchi::<Message>(network_id);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue