Skip to content

Commit 905784a

Browse files
author
jagdeep sidhu
committed
rm blob verification precompile
use point eval in future integrations
1 parent 612126c commit 905784a

File tree

5 files changed

+1
-101
lines changed

5 files changed

+1
-101
lines changed

core/vm/contracts.go

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,65 +1078,9 @@ func (c *datahash) Run(input []byte, interpreter *EVMInterpreter) ([]byte, error
10781078
}
10791079

10801080
var PrecompiledContractsDanksharding = map[common.Address]PrecompiledContract{
1081-
common.BytesToAddress([]byte{0x13}): &blobVerification{},
10821081
common.BytesToAddress([]byte{0x14}): &pointEvaluation{},
10831082
}
10841083

1085-
var (
1086-
errBlobVerificationInputLength = errors.New("invalid input length")
1087-
errInvalidVersionedHash = errors.New("invalid versioned hash")
1088-
errInvalidChunk = errors.New("invalid chunk")
1089-
errBadBlobCommitment = errors.New("versioned hash did not match")
1090-
)
1091-
1092-
// DOCDOC
1093-
type blobVerification struct{}
1094-
1095-
// RequiredGas returns the gas required to execute the pre-compiled contract.
1096-
func (c *blobVerification) RequiredGas(input []byte) uint64 {
1097-
// 4096 (4096*32 + 32) is base gas (BlobVerificationGas), anything above should scale up the cost
1098-
return params.BlobVerificationGas * (uint64(len(input)) / 131104)
1099-
}
1100-
1101-
func (c *blobVerification) Run(input []byte, interpreter *EVMInterpreter) ([]byte, error) {
1102-
if len(input) < 32+(32*32) || len(input) > 32+(32*params.FieldElementsPerBlob) {
1103-
return nil, errBlobVerificationInputLength
1104-
}
1105-
1106-
var expectedVersionedHash [32]byte
1107-
copy(expectedVersionedHash[:], input[:32])
1108-
if expectedVersionedHash[0] != params.BlobCommitmentVersionKZG {
1109-
return nil, errInvalidVersionedHash
1110-
}
1111-
1112-
input = input[32:] // skip forward to the input points
1113-
lenInput := len(input)
1114-
if (lenInput % 32) != 0 {
1115-
return nil, errInvalidChunk
1116-
}
1117-
numElements := lenInput / 32
1118-
inputPoints := make([]bls.Fr, params.FieldElementsPerBlob)
1119-
var inputPoint [32]byte
1120-
for i := 0; i < numElements; i++ {
1121-
copy(inputPoint[:32], input[i*32:(i+1)*32])
1122-
ok := bls.FrFrom32(&inputPoints[i], inputPoint)
1123-
if !ok {
1124-
return nil, errInvalidChunk
1125-
}
1126-
}
1127-
1128-
// Get versioned hash out of input points
1129-
commitment := kzg.BlobToKzg(inputPoints)
1130-
var compressedCommitment types.KZGCommitment
1131-
copy(compressedCommitment[:], bls.ToCompressedG1(commitment))
1132-
1133-
versionedHash := compressedCommitment.ComputeVersionedHash()
1134-
if versionedHash != expectedVersionedHash {
1135-
return nil, errBadBlobCommitment
1136-
}
1137-
1138-
return []byte{}, nil
1139-
}
11401084

11411085
// DOCDOC
11421086
type pointEvaluation struct{}
@@ -1149,6 +1093,7 @@ var (
11491093
errPointEvaluationInvalidProof = errors.New("invalid proof")
11501094
errPointEvaluationMismatchVersionedHash = errors.New("mismatched versioned hash")
11511095
errPointEvaluationBadProof = errors.New("bad proof")
1096+
errInvalidVersionedHash = errors.New("invalid versioned hash")
11521097
)
11531098

11541099
// RequiredGas returns the gas required to execute the pre-compiled contract.

core/vm/contracts_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ var allPrecompiles = map[common.Address]PrecompiledContract{
6666
common.BytesToAddress([]byte{16}): &bls12381Pairing{},
6767
common.BytesToAddress([]byte{17}): &bls12381MapG1{},
6868
common.BytesToAddress([]byte{18}): &bls12381MapG2{},
69-
common.BytesToAddress([]byte{0x19}): &blobVerification{},
7069
common.BytesToAddress([]byte{0x20}): &pointEvaluation{},
7170
}
7271

@@ -398,5 +397,4 @@ func BenchmarkPrecompiledBLS12381G2MultiExpWorstCase(b *testing.B) {
398397
benchmarkPrecompiled("0f", testcase, b)
399398
}
400399

401-
func TestPrecompiledBlobVerification(t *testing.T) { testJson("blobVerification", "0x19", t) }
402400
func TestPrecompiledPointEvaluation(t *testing.T) { testJson("pointEvaluation", "0x20", t) }

core/vm/testdata/precompiles/blobVerification.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

params/protocol_params.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ const (
162162
SYSDataHashGas uint64 = 1400 // The cost of data hash retrieval
163163

164164
FieldElementsPerBlob = 65536 // each field element is 32 bytes
165-
BlobVerificationGas uint64 = 1800000
166165
BlobCommitmentVersionKZG uint8 = 0x01
167166
PointEvaluationGas uint64 = 50000
168167
)

tests/kzg_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"io/ioutil"
66
"math"
7-
"strings"
87
"testing"
98

109
"github.com/ethereum/go-ethereum/common"
@@ -238,38 +237,6 @@ func TestVerify(t *testing.T) {
238237
}
239238
}
240239

241-
// Helper: Create test vector for the BlobVerification precompile
242-
func TestBlobVerificationTestVector(t *testing.T) {
243-
data := []byte(strings.Repeat("HELPMELOVEME ", 322639))[:params.FieldElementsPerBlob*32]
244-
t.Logf("test-vector: %x", data)
245-
inputPoints := make([]bls.Fr, params.FieldElementsPerBlob)
246-
247-
var inputPoint [32]byte
248-
for i := 0; i < params.FieldElementsPerBlob; i++ {
249-
copy(inputPoint[:32], data[i*32:(i+1)*32])
250-
ok := bls.FrFrom32(&inputPoints[i], inputPoint)
251-
if !ok {
252-
t.Fatalf("Invalid chunk")
253-
}
254-
}
255-
256-
var commitment types.KZGCommitment
257-
copy(commitment[:], bls.ToCompressedG1(kzg.BlobToKzg(inputPoints)))
258-
versionedHash := commitment.ComputeVersionedHash()
259-
260-
calldata := append(versionedHash[:], data[:]...)
261-
//t.Logf("test-vector: %x", calldata)
262-
263-
precompile := vm.PrecompiledContractsDanksharding[common.BytesToAddress([]byte{0x13})]
264-
if _, err := precompile.Run(calldata, nil); err != nil {
265-
t.Fatalf("expected blob verification to succeed")
266-
}
267-
// change a byte of the versioned hash
268-
calldata[3] ^= 42
269-
if _, err := precompile.Run(calldata, nil); err == nil {
270-
t.Fatalf("expected blob verification to fail")
271-
}
272-
}
273240

274241
// Helper: Create test vector for the PointEvaluation precompile
275242
func TestPointEvaluationTestVector(t *testing.T) {

0 commit comments

Comments
 (0)