MCPcopy
hub / github.com/ethereum/EIPs / TestPrecompiledVectorOp

Function TestPrecompiledVectorOp

assets/eip-7885/op-geth/cgo/contracts_test.go:588–777  ·  view source on GitHub ↗

Test NTT_VECMULMOD and NTT_VECADDMOD precompiles with valid inputs

(t *testing.T)

Source from the content-addressed store, hash-verified

586
587// Test NTT_VECMULMOD and NTT_VECADDMOD precompiles with valid inputs
588func TestPrecompiledVectorOp(t *testing.T) {
589 t.Run("NTT_VECMULMOD", func(t *testing.T) {
590 t.Run("Falcon-512-simple", func(t *testing.T) {
591 p := allPrecompiles[common.HexToAddress("14")]
592 // Simple test: multiply small values
593 // Ring degree = 512, modulus = 12289
594 // vecA = [1, 2], vecB = [3, 4], rest zeros
595 // Expected: [3, 8], rest zeros (in Montgomery domain)
596 header := "000002000000000000003001" // ringDegree=512, modulus=12289
597
598 // Create two vectors of 512 uint16 elements each
599 vecA := make([]byte, 512*2)
600 vecB := make([]byte, 512*2)
601
602 // Set first two elements: vecA[0]=1, vecA[1]=2
603 binary.BigEndian.PutUint16(vecA[0:2], 1)
604 binary.BigEndian.PutUint16(vecA[2:4], 2)
605
606 // Set first two elements: vecB[0]=3, vecB[1]=4
607 binary.BigEndian.PutUint16(vecB[0:2], 3)
608 binary.BigEndian.PutUint16(vecB[2:4], 4)
609
610 input := common.Hex2Bytes(header)
611 input = append(input, vecA...)
612 input = append(input, vecB...)
613
614 gas := p.RequiredGas(input)
615
616 result, _, err := RunPrecompiledContract(p, input, gas, nil)
617 if err != nil {
618 t.Errorf("Failed to run VECMULMOD: %v", err)
619 }
620
621 if len(result) != 512*2 {
622 t.Errorf("Expected result length %d, got %d", 512*2, len(result))
623 }
624
625 // Verify result[0] and result[1] are non-zero (Montgomery multiplication of small values)
626 r0 := binary.BigEndian.Uint16(result[0:2])
627 r1 := binary.BigEndian.Uint16(result[2:4])
628
629 if r0 == 0 || r1 == 0 {
630 t.Errorf("Expected non-zero results for multiplication, got r0=%d, r1=%d", r0, r1)
631 }
632 })
633
634 t.Run("ML-DSA-256-simple", func(t *testing.T) {
635 p := allPrecompiles[common.HexToAddress("14")]
636 // Simple test: multiply small values
637 // Ring degree = 256, modulus = 8380417
638 // vecA = [1, 2], vecB = [3, 4], rest zeros
639 // Expected: [3, 8], rest zeros
640 header := "0000010000000000007fe001" // ringDegree=256, modulus=8380417
641
642 // Create two vectors of 256 int32 elements each
643 vecA := make([]byte, 256*4)
644 vecB := make([]byte, 256*4)
645

Callers

nothing calls this directly

Calls 3

RunPrecompiledContractFunction · 0.70
RunMethod · 0.65
RequiredGasMethod · 0.65

Tested by

no test coverage detected