-
Notifications
You must be signed in to change notification settings - Fork 37
/
onchain_test.go
104 lines (89 loc) · 3.22 KB
/
onchain_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package eigenpodproofs_test
import (
"math/big"
"testing"
contractBeaconChainProofsWrapper "github.com/Layr-Labs/eigenpod-proofs-generation/bindings/BeaconChainProofsWrapper"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/assert"
)
func TestValidatorContainersProofOnChain(t *testing.T) {
validators, err := beaconState.Validators()
if err != nil {
t.Fatal(err)
}
validatorIndices := []uint64{}
for i := int(0); i < len(validators); i += 100000 {
validatorIndices = append(validatorIndices, uint64(i))
}
verifyValidatorFieldsCallParams, err := epp.ProveValidatorContainers(beaconHeader, beaconState, validatorIndices)
if err != nil {
t.Fatal(err)
}
blockRoot, err := beaconHeader.HashTreeRoot()
if err != nil {
t.Fatal(err)
}
err = beaconChainProofsWrapper.VerifyStateRoot(
&bind.CallOpts{},
blockRoot,
contractBeaconChainProofsWrapper.BeaconChainProofsStateRootProof{
BeaconStateRoot: verifyValidatorFieldsCallParams.StateRootProof.BeaconStateRoot,
Proof: verifyValidatorFieldsCallParams.StateRootProof.Proof.ToByteSlice(),
},
)
assert.Nil(t, err)
for i := 0; i < len(verifyValidatorFieldsCallParams.ValidatorFields); i++ {
validatorFields := [][32]byte{}
for _, field := range verifyValidatorFieldsCallParams.ValidatorFields[i] {
validatorFields = append(validatorFields, field)
}
err = beaconChainProofsWrapper.VerifyValidatorFields(
&bind.CallOpts{},
verifyValidatorFieldsCallParams.StateRootProof.BeaconStateRoot,
validatorFields,
verifyValidatorFieldsCallParams.ValidatorFieldsProofs[i].ToByteSlice(),
new(big.Int).SetUint64(verifyValidatorFieldsCallParams.ValidatorIndices[i]),
)
assert.Nil(t, err)
}
}
func TestValidatorBalancesProofOnChain(t *testing.T) {
validators, err := beaconState.Validators()
if err != nil {
t.Fatal(err)
}
validatorIndices := []uint64{}
for i := int(0); i < len(validators); i += 100000 {
validatorIndices = append(validatorIndices, uint64(i))
}
verifyCheckpointProofsCallParams, err := epp.ProveCheckpointProofs(beaconHeader, beaconState, validatorIndices)
if err != nil {
t.Fatal(err)
}
blockRoot, err := beaconHeader.HashTreeRoot()
if err != nil {
t.Fatal(err)
}
err = beaconChainProofsWrapper.VerifyBalanceContainer(
&bind.CallOpts{},
blockRoot,
contractBeaconChainProofsWrapper.BeaconChainProofsBalanceContainerProof{
BalanceContainerRoot: verifyCheckpointProofsCallParams.ValidatorBalancesRootProof.ValidatorBalancesRoot,
Proof: verifyCheckpointProofsCallParams.ValidatorBalancesRootProof.Proof.ToByteSlice(),
},
)
assert.Nil(t, err)
for i := 0; i < len(verifyCheckpointProofsCallParams.BalanceProofs); i++ {
err = beaconChainProofsWrapper.VerifyValidatorBalance(
&bind.CallOpts{},
verifyCheckpointProofsCallParams.ValidatorBalancesRootProof.ValidatorBalancesRoot,
new(big.Int).SetUint64(validatorIndices[i]),
contractBeaconChainProofsWrapper.BeaconChainProofsBalanceProof{
PubkeyHash: verifyCheckpointProofsCallParams.BalanceProofs[i].PubkeyHash,
BalanceRoot: verifyCheckpointProofsCallParams.BalanceProofs[i].BalanceRoot,
Proof: verifyCheckpointProofsCallParams.BalanceProofs[i].Proof.ToByteSlice(),
},
)
assert.Nil(t, err)
}
}