Compare commits

...

14 Commits

Author SHA1 Message Date
6ea035f208 Update c-kzg-4844
Prevents conflict in dependent packages
2024-04-23 18:29:58 +08:00
b748b08558 Fix rlp package 2024-03-28 17:53:19 +08:00
2bd23e1f3c Merge remote-tracking branch 'upstream/master' into statediff-additions 2024-03-28 17:27:14 +08:00
AusIV
07f17cdd7e
Merge pull request #34 from openrelayxyz/hardfork/cancun
Hardfork/cancun
2024-01-22 14:46:08 -06:00
cd41de354c Fix various build errors and bugs
- bug in hex decoding in bls12381 package
- correct interfaces
- missing test variables
2023-07-07 00:01:22 +08:00
068e70f417 go mod tidy 2023-06-22 15:37:31 +08:00
1d3da8ce80 add GetContractCode 2023-06-22 15:20:28 +08:00
d8d1347863 conditionally link against geth's libsecp256k1 2023-06-14 21:42:22 +08:00
47ca0cc89f update TrieHasher 2023-06-14 21:42:22 +08:00
a6ae549ce2 copy effectivegasprice changes (871861) 2023-06-14 21:42:20 +08:00
de5e13f848 port consensus receipt encoding PR 2023-06-14 21:42:18 +08:00
8d228c14f6 add path encoding funcs 2023-06-14 19:22:23 +08:00
c89f6309f8 add trie iterators 2023-06-14 19:22:23 +08:00
0aa866f534 copyedit docs 2023-06-14 19:22:23 +08:00
20 changed files with 150 additions and 83 deletions

2
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/consensys/gnark-crypto v0.12.1
github.com/crate-crypto/go-kzg-4844 v0.7.0
github.com/davecgh/go-spew v1.1.1
github.com/ethereum/c-kzg-4844/bindings/go v0.0.0-20230126171313-363c7d7593b4
github.com/ethereum/c-kzg-4844 v0.4.0
github.com/google/gofuzz v1.2.0
github.com/holiman/uint256 v1.2.4
github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267

4
go.sum
View File

@ -18,8 +18,8 @@ github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/ethereum/c-kzg-4844/bindings/go v0.0.0-20230126171313-363c7d7593b4 h1:B2mpK+MNqgPqk2/KNi1LbqwtZDy5F7iy0mynQiBr8VA=
github.com/ethereum/c-kzg-4844/bindings/go v0.0.0-20230126171313-363c7d7593b4/go.mod h1:y4GA2JbAUama1S4QwYjC2hefgGLU8Ul0GMtL/ADMF1c=
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=

View File

@ -98,6 +98,9 @@ static int secp256k1_ext_reencode_pubkey(
// In: point: pointer to a 64-byte public point,
// encoded as two 256bit big-endian numbers.
// scalar: a 32-byte scalar with which to multiply the point
int secp256k1_ext_scalar_mul(const secp256k1_context* ctx, unsigned char *point, const unsigned char *scalar);
#ifndef PLUGETH_LINK_GETH
int secp256k1_ext_scalar_mul(const secp256k1_context* ctx, unsigned char *point, const unsigned char *scalar) {
int ret = 0;
int overflow = 0;
@ -128,3 +131,4 @@ int secp256k1_ext_scalar_mul(const secp256k1_context* ctx, unsigned char *point,
secp256k1_scalar_clear(&s);
return ret;
}
#endif

View File

@ -68,7 +68,7 @@ static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_GE_CONST(
0xFD17B448UL, 0xA6855419UL, 0x9C47D08FUL, 0xFB10D4B8UL
);
const int CURVE_B = 7;
static const int CURVE_B = 7;
#endif
static void secp256k1_ge_set_gej_zinv(secp256k1_ge *r, const secp256k1_gej *a, const secp256k1_fe *zi) {

View File

@ -4,26 +4,7 @@
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
**********************************************************************/
#include "include/secp256k1.h"
#include "util.h"
#include "num_impl.h"
#include "field_impl.h"
#include "scalar_impl.h"
#include "group_impl.h"
#include "ecmult_impl.h"
#include "ecmult_const_impl.h"
#include "ecmult_gen_impl.h"
#include "ecdsa_impl.h"
#include "eckey_impl.h"
#include "hash_impl.h"
#define ARG_CHECK(cond) do { \
if (EXPECT(!(cond), 0)) { \
secp256k1_callback_call(&ctx->illegal_callback, #cond); \
return 0; \
} \
} while(0)
#include "secp256k1_impl.h"
static void default_illegal_callback_fn(const char* str, void* data) {
fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str);
@ -46,13 +27,6 @@ static const secp256k1_callback default_error_callback = {
};
struct secp256k1_context_struct {
secp256k1_ecmult_context ecmult_ctx;
secp256k1_ecmult_gen_context ecmult_gen_ctx;
secp256k1_callback illegal_callback;
secp256k1_callback error_callback;
};
secp256k1_context* secp256k1_context_create(unsigned int flags) {
secp256k1_context* ret = (secp256k1_context*)checked_malloc(&default_error_callback, sizeof(secp256k1_context));
ret->illegal_callback = default_illegal_callback;
@ -131,20 +105,6 @@ static int secp256k1_pubkey_load(const secp256k1_context* ctx, secp256k1_ge* ge,
return 1;
}
static void secp256k1_pubkey_save(secp256k1_pubkey* pubkey, secp256k1_ge* ge) {
if (sizeof(secp256k1_ge_storage) == 64) {
secp256k1_ge_storage s;
secp256k1_ge_to_storage(&s, ge);
memcpy(&pubkey->data[0], &s, 64);
} else {
VERIFY_CHECK(!secp256k1_ge_is_infinity(ge));
secp256k1_fe_normalize_var(&ge->x);
secp256k1_fe_normalize_var(&ge->y);
secp256k1_fe_get_b32(pubkey->data, &ge->x);
secp256k1_fe_get_b32(pubkey->data + 32, &ge->y);
}
}
int secp256k1_ec_pubkey_parse(const secp256k1_context* ctx, secp256k1_pubkey* pubkey, const unsigned char *input, size_t inputlen) {
secp256k1_ge Q;
@ -197,16 +157,6 @@ static void secp256k1_ecdsa_signature_load(const secp256k1_context* ctx, secp256
}
}
static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature* sig, const secp256k1_scalar* r, const secp256k1_scalar* s) {
if (sizeof(secp256k1_scalar) == 32) {
memcpy(&sig->data[0], r, 32);
memcpy(&sig->data[32], s, 32);
} else {
secp256k1_scalar_get_b32(&sig->data[0], r);
secp256k1_scalar_get_b32(&sig->data[32], s);
}
}
int secp256k1_ecdsa_signature_parse_der(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) {
secp256k1_scalar r, s;
@ -545,15 +495,3 @@ int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey *
secp256k1_pubkey_save(pubnonce, &Q);
return 1;
}
#ifdef ENABLE_MODULE_ECDH
# include "modules/ecdh/main_impl.h"
#endif
#ifdef ENABLE_MODULE_SCHNORR
# include "modules/schnorr/main_impl.h"
#endif
#ifdef ENABLE_MODULE_RECOVERY
# include "modules/recovery/main_impl.h"
#endif

View File

@ -0,0 +1,74 @@
/**********************************************************************
* Copyright (c) 2013-2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
**********************************************************************/
#ifndef _SECP256K1_IMPL_H_
#define _SECP256K1_IMPL_H_
#include "include/secp256k1.h"
#include "util.h"
#include "num_impl.h"
#include "field_impl.h"
#include "scalar_impl.h"
#include "group_impl.h"
#include "ecmult_impl.h"
#include "ecmult_const_impl.h"
#include "ecmult_gen_impl.h"
#include "ecdsa_impl.h"
#include "eckey_impl.h"
#include "hash_impl.h"
#define ARG_CHECK(cond) do { \
if (EXPECT(!(cond), 0)) { \
secp256k1_callback_call(&ctx->illegal_callback, #cond); \
return 0; \
} \
} while(0)
struct secp256k1_context_struct {
secp256k1_ecmult_context ecmult_ctx;
secp256k1_ecmult_gen_context ecmult_gen_ctx;
secp256k1_callback illegal_callback;
secp256k1_callback error_callback;
};
static void secp256k1_ecdsa_signature_save(secp256k1_ecdsa_signature* sig, const secp256k1_scalar* r, const secp256k1_scalar* s) {
if (sizeof(secp256k1_scalar) == 32) {
memcpy(&sig->data[0], r, 32);
memcpy(&sig->data[32], s, 32);
} else {
secp256k1_scalar_get_b32(&sig->data[0], r);
secp256k1_scalar_get_b32(&sig->data[32], s);
}
}
static void secp256k1_pubkey_save(secp256k1_pubkey* pubkey, secp256k1_ge* ge) {
if (sizeof(secp256k1_ge_storage) == 64) {
secp256k1_ge_storage s;
secp256k1_ge_to_storage(&s, ge);
memcpy(&pubkey->data[0], &s, 64);
} else {
VERIFY_CHECK(!secp256k1_ge_is_infinity(ge));
secp256k1_fe_normalize_var(&ge->x);
secp256k1_fe_normalize_var(&ge->y);
secp256k1_fe_get_b32(pubkey->data, &ge->x);
secp256k1_fe_get_b32(pubkey->data + 32, &ge->y);
}
}
#ifdef ENABLE_MODULE_ECDH
# include "modules/ecdh/main_impl.h"
#endif
#ifdef ENABLE_MODULE_SCHNORR
# include "modules/schnorr/main_impl.h"
#endif
#ifdef ENABLE_MODULE_RECOVERY
# include "modules/recovery/main_impl.h"
#endif
#endif

View File

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
// +build !gofuzz
// +build cgo
//go:build !gofuzz && cgo && !linkgeth
// +build !gofuzz,cgo,!linkgeth
package secp256k1

View File

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
// +build !gofuzz
// +build cgo
//go:build !gofuzz && cgo
// +build !gofuzz,cgo
// Package secp256k1 wraps the bitcoin secp256k1 C library.
package secp256k1
@ -26,8 +26,13 @@ package secp256k1
#define USE_FIELD_INV_BUILTIN
#define USE_SCALAR_INV_BUILTIN
#define NDEBUG
#include "./libsecp256k1/src/secp256k1.c"
#include "./libsecp256k1/src/modules/recovery/main_impl.h"
#ifdef PLUGETH_LINK_GETH
# include "./libsecp256k1/src/secp256k1_impl.h"
# include "./libsecp256k1/include/secp256k1_recovery.h"
#else
# include "./libsecp256k1/src/secp256k1.c"
# include "./libsecp256k1/src/modules/recovery/main_impl.h"
#endif
#include "ext.h"
typedef void (*callbackFunc) (const char* msg, void* data);

View File

@ -0,0 +1,14 @@
// Copyright 2015 Jeffrey Wilcke, Felix Lange, Gustav Simonsson. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//go:build !gofuzz && cgo && linkgeth
// +build !gofuzz,cgo,linkgeth
// Package secp256k1 wraps the bitcoin secp256k1 C library.
package secp256k1
/*
#cgo CFLAGS: -DPLUGETH_LINK_GETH
*/
import "C"

View File

@ -0,0 +1,31 @@
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package rlp
import (
"encoding/hex"
"fmt"
"strings"
)
func unhex(str string) []byte {
b, err := hex.DecodeString(strings.ReplaceAll(str, " ", ""))
if err != nil {
panic(fmt.Sprintf("invalid hex string: %q", str))
}
return b
}

View File

@ -27,7 +27,7 @@ import (
"golang.org/x/tools/go/packages"
)
const pathOfPackageRLP = "github.com/ethereum/go-ethereum/rlp"
const pathOfPackageRLP = "github.com/openrelayxyz/plugeth-utils/restricted/rlp"
func main() {
var (

View File

@ -1,6 +1,6 @@
package test
import "github.com/ethereum/go-ethereum/rlp"
import "github.com/openrelayxyz/plugeth-utils/restricted/rlp"
import "io"
func (obj *Test) EncodeRLP(_w io.Writer) error {

View File

@ -1,6 +1,6 @@
package test
import "github.com/ethereum/go-ethereum/rlp"
import "github.com/openrelayxyz/plugeth-utils/restricted/rlp"
import "io"
func (obj *Test) EncodeRLP(_w io.Writer) error {

View File

@ -1,6 +1,6 @@
package test
import "github.com/ethereum/go-ethereum/rlp"
import "github.com/openrelayxyz/plugeth-utils/restricted/rlp"
import "io"
func (obj *Test) EncodeRLP(_w io.Writer) error {

View File

@ -2,7 +2,7 @@
package test
import "github.com/ethereum/go-ethereum/rlp"
import "github.com/openrelayxyz/plugeth-utils/restricted/rlp"
type Test struct {
RawValue rlp.RawValue

View File

@ -1,6 +1,6 @@
package test
import "github.com/ethereum/go-ethereum/rlp"
import "github.com/openrelayxyz/plugeth-utils/restricted/rlp"
import "io"
func (obj *Test) EncodeRLP(_w io.Writer) error {

View File

@ -1,7 +1,7 @@
package test
import "github.com/ethereum/go-ethereum/rlp"
import "github.com/holiman/uint256"
import "github.com/openrelayxyz/plugeth-utils/restricted/rlp"
import "io"
func (obj *Test) EncodeRLP(_w io.Writer) error {

View File

@ -1,6 +1,6 @@
package test
import "github.com/ethereum/go-ethereum/rlp"
import "github.com/openrelayxyz/plugeth-utils/restricted/rlp"
import "io"
func (obj *Test) EncodeRLP(_w io.Writer) error {

View File

@ -64,7 +64,7 @@ func prefixedRlpHash(prefix byte, x interface{}) (h core.Hash) {
// This is internal, do not use.
type TrieHasher interface {
Reset()
Update([]byte, []byte)
Update([]byte, []byte) error
Hash() core.Hash
}

View File

@ -136,9 +136,10 @@ func (d *hashToHumanReadable) Reset() {
d.data = make([]byte, 0)
}
func (d *hashToHumanReadable) Update(i []byte, i2 []byte) {
func (d *hashToHumanReadable) Update(i []byte, i2 []byte) error {
l := fmt.Sprintf("%x %x\n", i, i2)
d.data = append(d.data, []byte(l)...)
return nil
}
func (d *hashToHumanReadable) Hash() core.Hash {