From 0dda5b1dd3cf062e51968cd4bc5f72a5789f35c6 Mon Sep 17 00:00:00 2001 From: pavelkrolevets Date: Tue, 24 Sep 2024 23:01:04 +0300 Subject: [PATCH] update init message accordning to EIP-7251: Increase the MAX_EFFECTIVE_BALANCE --- crypto/beacon.go | 6 ++-- init.go | 14 +++++++- initiator.go | 4 +++ operator.go | 5 ++- reshare.go | 6 +++- resign.go | 9 +++++ result.go | 16 ++++++--- testing/fixtures/common.go | 1 + testing/fixtures/common_test.go | 2 +- testing/fixtures/reshare.go | 41 ++++++++++++--------- testing/init_test.go | 2 ++ testing/reshare_test.go | 64 ++++++++++++++++++--------------- testing/result_test.go | 31 ++++++++++++++++ types.go | 6 ++++ types_encoding.go | 53 ++++++++++++++++++++------- 15 files changed, 191 insertions(+), 69 deletions(-) diff --git a/crypto/beacon.go b/crypto/beacon.go index 42bfbe0..b05aa29 100644 --- a/crypto/beacon.go +++ b/crypto/beacon.go @@ -10,8 +10,10 @@ import ( ) const ( - MaxEffectiveBalanceInGwei phase0.Gwei = 32000000000 - ETH1WithdrawalPrefixByte = byte(1) + // https://eips.ethereum.org/EIPS/eip-7251 + MIN_ACTIVATION_BALANCE phase0.Gwei = 32000000000 + MAX_EFFECTIVE_BALANCE phase0.Gwei = 2048000000000 + ETH1WithdrawalPrefixByte = byte(1) ) // GetNetworkByFork translates the network fork bytes into name diff --git a/init.go b/init.go index 9f8a4f4..efe7172 100644 --- a/init.go +++ b/init.go @@ -3,6 +3,9 @@ package spec import ( "bytes" "fmt" + + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/ssvlabs/dkg-spec/crypto" ) // ValidateInitMessage returns nil if init message is valid @@ -13,7 +16,9 @@ func ValidateInitMessage(init *Init) error { if !ValidThresholdSet(init.T, init.Operators) { return fmt.Errorf("threshold set is invalid") } - + if !ValidAmountSet(phase0.Gwei(init.Amount)) { + return fmt.Errorf("amount should be in range between 32 ETH and 2048 ETH") + } return nil } @@ -78,3 +83,10 @@ func EqualOperators(a, b []*Operator) bool { } return true } + +func ValidAmountSet(amount phase0.Gwei) bool { + if amount >= crypto.MIN_ACTIVATION_BALANCE && amount <= crypto.MAX_EFFECTIVE_BALANCE { + return true + } + return false +} diff --git a/initiator.go b/initiator.go index cf37953..d7839e3 100644 --- a/initiator.go +++ b/initiator.go @@ -1,6 +1,7 @@ package spec import ( + "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/ssvlabs/dkg-spec/eip1271" "github.com/google/uuid" @@ -22,6 +23,7 @@ func RunDKG(init *Init) ([]*Result, error) { init.Fork, init.Owner, init.Nonce, + phase0.Gwei(init.Amount), id, results) return results, err @@ -48,6 +50,7 @@ func RunReshare( fork, signedReshare.Reshare.Owner, signedReshare.Reshare.Nonce, + phase0.Gwei(signedReshare.Reshare.Amount), id, results) return results, err @@ -77,6 +80,7 @@ func RunResign( fork, signedResign.Resign.Owner, signedResign.Resign.Nonce, + phase0.Gwei(signedResign.Resign.Amount), id, results) return results, err diff --git a/operator.go b/operator.go index fab8d5d..e35b93d 100644 --- a/operator.go +++ b/operator.go @@ -3,6 +3,7 @@ package spec import ( "crypto/rsa" + "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/herumi/bls-eth-go-binary/bls" "github.com/ssvlabs/dkg-spec/crypto" "github.com/ssvlabs/dkg-spec/eip1271" @@ -30,7 +31,7 @@ func (op *Operator) Init( init.Fork, validatorPK, init.WithdrawalCredentials, - crypto.MaxEffectiveBalanceInGwei, + phase0.Gwei(init.Amount), ) if err != nil { return nil, err @@ -106,6 +107,7 @@ func (op *Operator) Reshare( signedReshare.Reshare.WithdrawalCredentials, signedReshare.Reshare.Fork, signedReshare.Reshare.Nonce, + phase0.Gwei(signedReshare.Reshare.Amount), ) } @@ -140,5 +142,6 @@ func (op *Operator) Resign( signedResign.Resign.WithdrawalCredentials, signedResign.Resign.Fork, signedResign.Resign.Nonce, + phase0.Gwei(signedResign.Resign.Amount), ) } diff --git a/reshare.go b/reshare.go index e0ac071..78205b0 100644 --- a/reshare.go +++ b/reshare.go @@ -3,6 +3,8 @@ package spec import ( "fmt" "sort" + + "github.com/attestantio/go-eth2-client/spec/phase0" ) // ValidateReshareMessage returns nil if re-share message is valid @@ -31,7 +33,9 @@ func ValidateReshareMessage( if !ValidThresholdSet(reshare.NewT, reshare.NewOperators) { return fmt.Errorf("new threshold set is invalid") } - + if !ValidAmountSet(phase0.Gwei(reshare.Amount)) { + return fmt.Errorf("amount should be in range between 32 ETH and 2048 ETH") + } return nil } diff --git a/resign.go b/resign.go index c664ac6..83637ce 100644 --- a/resign.go +++ b/resign.go @@ -1,11 +1,20 @@ package spec +import ( + "fmt" + + "github.com/attestantio/go-eth2-client/spec/phase0" +) + // ValidateResignMessage returns nil if re-sign message is valid func ValidateResignMessage( resign *Resign, operator *Operator, proof *SignedProof, ) error { + if !ValidAmountSet(phase0.Gwei(resign.Amount)) { + return fmt.Errorf("amount should be in range between 32 ETH and 2048 ETH") + } if err := ValidateCeremonyProof(resign.Owner, resign.ValidatorPubKey, operator, *proof); err != nil { return err } diff --git a/result.go b/result.go index f6cf127..578d147 100644 --- a/result.go +++ b/result.go @@ -22,19 +22,19 @@ func BuildResult( withdrawalCredentials []byte, fork [4]byte, nonce uint64, + amount phase0.Gwei, ) (*Result, error) { // sign deposit data depositDataRoot, err := crypto.DepositDataRootForFork( fork, validatorPK, withdrawalCredentials, - crypto.MaxEffectiveBalanceInGwei, + phase0.Gwei(amount), ) if err != nil { return nil, err } depositDataSig := share.SignByte(depositDataRoot[:]) - // sign proof encryptedShare, err := crypto.Encrypt(&sk.PublicKey, []byte(share.SerializeToHexStr())) if err != nil { @@ -75,6 +75,7 @@ func ValidateResults( fork [4]byte, ownerAddress [20]byte, nonce uint64, + amount phase0.Gwei, requestID [24]byte, results []*Result, ) (*bls.PublicKey, *phase0.DepositData, *bls.Sign, error) { @@ -102,7 +103,7 @@ func ValidateResults( // validate individual result for _, result := range results { - if err := ValidateResult(operators, ownerAddress, requestID, withdrawalCredentials, validatorPK, fork, nonce, result); err != nil { + if err := ValidateResult(operators, ownerAddress, requestID, withdrawalCredentials, validatorPK, fork, nonce, amount, result); err != nil { return nil, nil, nil, err } pub, deposit, ownerNonce, err := GetPartialSigsFromResult(result) @@ -130,7 +131,7 @@ func ValidateResults( } depositData := &phase0.DepositData{ PublicKey: phase0.BLSPubKey(validatorRecoveredPK.Serialize()), - Amount: crypto.MaxEffectiveBalanceInGwei, + Amount: phase0.Gwei(amount), WithdrawalCredentials: crypto.ETH1WithdrawalCredentials(withdrawalCredentials), Signature: phase0.BLSSignature(masterDepositSig.Serialize()), } @@ -155,6 +156,7 @@ func ValidateResult( validatorPK []byte, fork [4]byte, nonce uint64, + amount phase0.Gwei, result *Result, ) error { // verify operator @@ -173,6 +175,7 @@ func ValidateResult( fork, ownerAddress, nonce, + amount, result, ); err != nil { return fmt.Errorf("failed to verify partial signatures: %v", err) @@ -218,6 +221,7 @@ func VerifyPartialSignatures( fork [4]byte, ownerAddress [20]byte, nonce uint64, + amount phase0.Gwei, result *Result, ) error { pk, err := BLSPKEncode(result.SignedProof.Proof.SharePubKey) @@ -241,6 +245,7 @@ func VerifyPartialSignatures( result.SignedProof.Proof.ValidatorPubKey, []*bls.Sign{depositSig}, []*bls.PublicKey{pk}, + amount, ); err != nil { return err } @@ -280,6 +285,7 @@ func VerifyPartialDepositDataSignatures( validatorPubKey []byte, sigs []*bls.Sign, pks []*bls.PublicKey, + amount phase0.Gwei, ) error { network, err := crypto.GetNetworkByFork(fork) if err != nil { @@ -288,7 +294,7 @@ func VerifyPartialDepositDataSignatures( shareRoot, err := crypto.ComputeDepositMessageSigningRoot(network, &phase0.DepositMessage{ PublicKey: phase0.BLSPubKey(validatorPubKey), - Amount: crypto.MaxEffectiveBalanceInGwei, + Amount: amount, WithdrawalCredentials: crypto.ETH1WithdrawalCredentials(withdrawalCredentials)}) if err != nil { return fmt.Errorf("failed to compute deposit data root: %w", err) diff --git a/testing/fixtures/common.go b/testing/fixtures/common.go index 0b799dc..e183a43 100644 --- a/testing/fixtures/common.go +++ b/testing/fixtures/common.go @@ -19,6 +19,7 @@ var ( TestNonce = uint64(0) TestOwnerAddress = common.Address{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} TestRequestID = [24]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24} + TestAmount = crypto.MIN_ACTIVATION_BALANCE ) func GenerateOperators(amount int) []*spec.Operator { diff --git a/testing/fixtures/common_test.go b/testing/fixtures/common_test.go index e196613..609031f 100644 --- a/testing/fixtures/common_test.go +++ b/testing/fixtures/common_test.go @@ -120,7 +120,7 @@ func TestSignDeposit(t *testing.T) { require.NoError(t, err) shareRoot, err := crypto.ComputeDepositMessageSigningRoot(network, &phase0.DepositMessage{ PublicKey: phase0.BLSPubKey(ShareSK(TestValidator13Operators).GetPublicKey().Serialize()), - Amount: crypto.MaxEffectiveBalanceInGwei, + Amount: crypto.MIN_ACTIVATION_BALANCE, WithdrawalCredentials: crypto.ETH1WithdrawalCredentials(TestWithdrawalCred)}) require.NoError(t, err) diff --git a/testing/fixtures/reshare.go b/testing/fixtures/reshare.go index 0be89d4..4e82ae4 100644 --- a/testing/fixtures/reshare.go +++ b/testing/fixtures/reshare.go @@ -1,6 +1,9 @@ package fixtures -import spec "github.com/ssvlabs/dkg-spec" +import ( + spec "github.com/ssvlabs/dkg-spec" + "github.com/ssvlabs/dkg-spec/crypto" +) var ( TestReshare4Operators = spec.Reshare{ @@ -12,10 +15,11 @@ var ( GenerateOperators(4)[2], GenerateOperators(7)[4], }, - OldT: 3, - NewT: 3, - Owner: TestOwnerAddress, - Nonce: 1, + OldT: 3, + NewT: 3, + Owner: TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), } TestReshare7Operators = spec.Reshare{ ValidatorPubKey: ShareSK(TestValidator7Operators).GetPublicKey().Serialize(), @@ -29,10 +33,11 @@ var ( GenerateOperators(7)[5], GenerateOperators(10)[7], }, - OldT: 5, - NewT: 5, - Owner: TestOwnerAddress, - Nonce: 1, + OldT: 5, + NewT: 5, + Owner: TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), } TestReshare10Operators = spec.Reshare{ ValidatorPubKey: ShareSK(TestValidator10Operators).GetPublicKey().Serialize(), @@ -49,10 +54,11 @@ var ( GenerateOperators(10)[8], GenerateOperators(13)[10], }, - OldT: 7, - NewT: 7, - Owner: TestOwnerAddress, - Nonce: 1, + OldT: 7, + NewT: 7, + Owner: TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), } TestReshare13Operators = spec.Reshare{ ValidatorPubKey: ShareSK(TestValidator13Operators).GetPublicKey().Serialize(), @@ -75,9 +81,10 @@ var ( PubKey: EncodedOperatorPK(TestOperator14SK), }, }, - OldT: 9, - NewT: 9, - Owner: TestOwnerAddress, - Nonce: 1, + OldT: 9, + NewT: 9, + Owner: TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), } ) diff --git a/testing/init_test.go b/testing/init_test.go index 2b00a94..16da6c6 100644 --- a/testing/init_test.go +++ b/testing/init_test.go @@ -4,6 +4,7 @@ import ( "testing" spec "github.com/ssvlabs/dkg-spec" + "github.com/ssvlabs/dkg-spec/crypto" "github.com/ssvlabs/dkg-spec/testing/fixtures" "github.com/stretchr/testify/require" @@ -41,6 +42,7 @@ func TestValidateInitMessage(t *testing.T) { Fork: fixtures.TestFork, Owner: fixtures.TestOwnerAddress, Nonce: 0, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), })) }) diff --git a/testing/reshare_test.go b/testing/reshare_test.go index fb78c8a..9039d4c 100644 --- a/testing/reshare_test.go +++ b/testing/reshare_test.go @@ -239,10 +239,11 @@ func TestValidateReshare(t *testing.T) { fixtures.GenerateOperators(7)[5], fixtures.GenerateOperators(10)[7], }, - OldT: 3, - NewT: 5, - Owner: fixtures.TestOwnerAddress, - Nonce: 1, + OldT: 3, + NewT: 5, + Owner: fixtures.TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), }, fixtures.GenerateOperators(4)[0], &fixtures.TestOperator1Proof4Operators, @@ -259,6 +260,7 @@ func TestValidateReshare(t *testing.T) { NewT: 3, Owner: fixtures.TestOwnerAddress, Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), }, fixtures.GenerateOperators(7)[0], &fixtures.TestOperator1Proof7Operators, @@ -280,10 +282,11 @@ func TestValidateReshare(t *testing.T) { fixtures.GenerateOperators(4)[2], fixtures.GenerateOperators(7)[4], }, - OldT: 3, - NewT: 3, - Owner: fixtures.TestOwnerAddress, - Nonce: 1, + OldT: 3, + NewT: 3, + Owner: fixtures.TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), }, fixtures.GenerateOperators(4)[0], &fixtures.TestOperator1Proof4Operators, @@ -306,10 +309,11 @@ func TestValidateReshare(t *testing.T) { fixtures.GenerateOperators(4)[2], fixtures.GenerateOperators(7)[4], }, - OldT: 3, - NewT: 3, - Owner: fixtures.TestOwnerAddress, - Nonce: 1, + OldT: 3, + NewT: 3, + Owner: fixtures.TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), }, fixtures.GenerateOperators(4)[0], &fixtures.TestOperator2Proof4Operators, @@ -332,10 +336,11 @@ func TestValidateReshare(t *testing.T) { fixtures.GenerateOperators(4)[2], fixtures.GenerateOperators(4)[2], }, - OldT: 3, - NewT: 3, - Owner: fixtures.TestOwnerAddress, - Nonce: 1, + OldT: 3, + NewT: 3, + Owner: fixtures.TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), }, fixtures.GenerateOperators(4)[0], &fixtures.TestOperator1Proof4Operators, @@ -358,10 +363,11 @@ func TestValidateReshare(t *testing.T) { fixtures.GenerateOperators(4)[2], fixtures.GenerateOperators(7)[3], }, - OldT: 3, - NewT: 3, - Owner: fixtures.TestOwnerAddress, - Nonce: 1, + OldT: 3, + NewT: 3, + Owner: fixtures.TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), }, fixtures.GenerateOperators(4)[0], &fixtures.TestOperator1Proof4Operators, @@ -384,10 +390,11 @@ func TestValidateReshare(t *testing.T) { fixtures.GenerateOperators(4)[2], fixtures.GenerateOperators(7)[5], }, - OldT: 2, - NewT: 3, - Owner: fixtures.TestOwnerAddress, - Nonce: 1, + OldT: 2, + NewT: 3, + Owner: fixtures.TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), }, fixtures.GenerateOperators(4)[0], &fixtures.TestOperator1Proof4Operators, @@ -410,10 +417,11 @@ func TestValidateReshare(t *testing.T) { fixtures.GenerateOperators(4)[2], fixtures.GenerateOperators(7)[5], }, - OldT: 3, - NewT: 2, - Owner: fixtures.TestOwnerAddress, - Nonce: 1, + OldT: 3, + NewT: 2, + Owner: fixtures.TestOwnerAddress, + Nonce: 1, + Amount: uint64(crypto.MIN_ACTIVATION_BALANCE), }, fixtures.GenerateOperators(4)[0], &fixtures.TestOperator1Proof4Operators, diff --git a/testing/result_test.go b/testing/result_test.go index 58d27ea..6a6bf43 100644 --- a/testing/result_test.go +++ b/testing/result_test.go @@ -23,6 +23,7 @@ func TestBuildResult(t *testing.T) { fixtures.TestWithdrawalCred, fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, ) require.NoError(t, err) require.NoError(t, spec.ValidateResult( @@ -33,6 +34,7 @@ func TestBuildResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator4Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, result, )) decryptedShare, err := spec_crypto.Decrypt(fixtures.OperatorSK(fixtures.TestOperator1SK), result.SignedProof.Proof.EncryptedShare) @@ -50,6 +52,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results4Operators()[:3], ) @@ -64,6 +67,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results4Operators(), ) @@ -78,6 +82,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results7Operators()[:5], ) @@ -91,6 +96,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results7Operators()[:6], ) @@ -104,6 +110,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results7Operators(), ) @@ -118,6 +125,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results10Operators()[:7], ) @@ -131,6 +139,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results10Operators()[:8], ) @@ -144,6 +153,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results10Operators()[:9], ) @@ -157,6 +167,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results10Operators(), ) @@ -171,6 +182,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results13Operators()[:9], ) @@ -184,6 +196,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results13Operators()[:10], ) @@ -197,6 +210,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results13Operators()[:11], ) @@ -210,6 +224,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results13Operators()[:12], ) @@ -223,6 +238,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, fixtures.Results13Operators(), ) @@ -250,6 +266,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, res, ) @@ -265,6 +282,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, res, ) @@ -280,6 +298,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, res, ) @@ -302,6 +321,7 @@ func TestValidateResults(t *testing.T) { fixtures.TestFork, fixtures.TestOwnerAddress, fixtures.TestNonce, + fixtures.TestAmount, fixtures.TestRequestID, res, ) @@ -319,6 +339,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator4Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 1, RequestID: fixtures.TestRequestID, @@ -338,6 +359,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator7Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 1, RequestID: fixtures.TestRequestID, @@ -357,6 +379,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator10Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 1, RequestID: fixtures.TestRequestID, @@ -376,6 +399,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator13Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 1, RequestID: fixtures.TestRequestID, @@ -395,6 +419,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator4Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 5, RequestID: fixtures.TestRequestID, @@ -414,6 +439,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator4Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 1, RequestID: spec.NewID(), @@ -433,6 +459,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator4Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 1, RequestID: fixtures.TestRequestID, @@ -452,6 +479,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator4Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 1, RequestID: fixtures.TestRequestID, @@ -471,6 +499,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator4Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 1, RequestID: fixtures.TestRequestID, @@ -496,6 +525,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator4Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 1, RequestID: fixtures.TestRequestID, @@ -522,6 +552,7 @@ func TestValidateResult(t *testing.T) { fixtures.ShareSK(fixtures.TestValidator7Operators).GetPublicKey().Serialize(), fixtures.TestFork, fixtures.TestNonce, + fixtures.TestAmount, &spec.Result{ OperatorID: 1, RequestID: fixtures.TestRequestID, diff --git a/types.go b/types.go index 072e621..3aeacac 100644 --- a/types.go +++ b/types.go @@ -18,6 +18,8 @@ type Init struct { Owner [20]byte `ssz-size:"20"` // Owner nonce Nonce uint64 + // Amount in Gwei (https://eips.ethereum.org/EIPS/eip-7251) + Amount uint64 } type Reshare struct { @@ -39,6 +41,8 @@ type Reshare struct { Owner [20]byte `ssz-size:"20"` // Owner nonce Nonce uint64 + // Amount in Gwei (https://eips.ethereum.org/EIPS/eip-7251) + Amount uint64 } type SignedReshare struct { @@ -58,6 +62,8 @@ type Resign struct { Owner [20]byte `ssz-size:"20"` // Owner nonce Nonce uint64 + // Amount in Gwei (https://eips.ethereum.org/EIPS/eip-7251) + Amount uint64 } type SignedResign struct { diff --git a/types_encoding.go b/types_encoding.go index 44fa6dc..e78e05e 100644 --- a/types_encoding.go +++ b/types_encoding.go @@ -1,5 +1,5 @@ // Code generated by fastssz. DO NOT EDIT. -// Hash: dad4e96f547c2aefe2f3c7d15e3191b7c23ceadf57f79bb3f668635d3dac24f9 +// Hash: d1586e3e944c269663f50fd16300549efae35200db7402998e8cb7103365efa0 // Version: 0.1.3 package spec @@ -122,7 +122,7 @@ func (i *Init) MarshalSSZ() ([]byte, error) { // MarshalSSZTo ssz marshals the Init object to a target array func (i *Init) MarshalSSZTo(buf []byte) (dst []byte, err error) { dst = buf - offset := int(48) + offset := int(56) // Offset (0) 'Operators' dst = ssz.WriteOffset(dst, offset) @@ -147,6 +147,9 @@ func (i *Init) MarshalSSZTo(buf []byte) (dst []byte, err error) { // Field (5) 'Nonce' dst = ssz.MarshalUint64(dst, i.Nonce) + // Field (6) 'Amount' + dst = ssz.MarshalUint64(dst, i.Amount) + // Field (0) 'Operators' if size := len(i.Operators); size > 13 { err = ssz.ErrListTooBigFn("Init.Operators", size, 13) @@ -179,7 +182,7 @@ func (i *Init) MarshalSSZTo(buf []byte) (dst []byte, err error) { func (i *Init) UnmarshalSSZ(buf []byte) error { var err error size := uint64(len(buf)) - if size < 48 { + if size < 56 { return ssz.ErrSize } @@ -191,7 +194,7 @@ func (i *Init) UnmarshalSSZ(buf []byte) error { return ssz.ErrOffset } - if o0 < 48 { + if o0 < 56 { return ssz.ErrInvalidVariableOffset } @@ -212,6 +215,9 @@ func (i *Init) UnmarshalSSZ(buf []byte) error { // Field (5) 'Nonce' i.Nonce = ssz.UnmarshallUint64(buf[40:48]) + // Field (6) 'Amount' + i.Amount = ssz.UnmarshallUint64(buf[48:56]) + // Field (0) 'Operators' { buf = tail[o0:o2] @@ -250,7 +256,7 @@ func (i *Init) UnmarshalSSZ(buf []byte) error { // SizeSSZ returns the ssz encoded size in bytes for the Init object func (i *Init) SizeSSZ() (size int) { - size = 48 + size = 56 // Field (0) 'Operators' for ii := 0; ii < len(i.Operators); ii++ { @@ -313,6 +319,9 @@ func (i *Init) HashTreeRootWith(hh ssz.HashWalker) (err error) { // Field (5) 'Nonce' hh.PutUint64(i.Nonce) + // Field (6) 'Amount' + hh.PutUint64(i.Amount) + hh.Merkleize(indx) return } @@ -330,7 +339,7 @@ func (r *Reshare) MarshalSSZ() ([]byte, error) { // MarshalSSZTo ssz marshals the Reshare object to a target array func (r *Reshare) MarshalSSZTo(buf []byte) (dst []byte, err error) { dst = buf - offset := int(108) + offset := int(116) // Field (0) 'ValidatorPubKey' if size := len(r.ValidatorPubKey); size != 48 { @@ -372,6 +381,9 @@ func (r *Reshare) MarshalSSZTo(buf []byte) (dst []byte, err error) { // Field (8) 'Nonce' dst = ssz.MarshalUint64(dst, r.Nonce) + // Field (9) 'Amount' + dst = ssz.MarshalUint64(dst, r.Amount) + // Field (1) 'OldOperators' if size := len(r.OldOperators); size > 13 { err = ssz.ErrListTooBigFn("Reshare.OldOperators", size, 13) @@ -422,7 +434,7 @@ func (r *Reshare) MarshalSSZTo(buf []byte) (dst []byte, err error) { func (r *Reshare) UnmarshalSSZ(buf []byte) error { var err error size := uint64(len(buf)) - if size < 108 { + if size < 116 { return ssz.ErrSize } @@ -440,7 +452,7 @@ func (r *Reshare) UnmarshalSSZ(buf []byte) error { return ssz.ErrOffset } - if o1 < 108 { + if o1 < 116 { return ssz.ErrInvalidVariableOffset } @@ -469,6 +481,9 @@ func (r *Reshare) UnmarshalSSZ(buf []byte) error { // Field (8) 'Nonce' r.Nonce = ssz.UnmarshallUint64(buf[100:108]) + // Field (9) 'Amount' + r.Amount = ssz.UnmarshallUint64(buf[108:116]) + // Field (1) 'OldOperators' { buf = tail[o1:o2] @@ -529,7 +544,7 @@ func (r *Reshare) UnmarshalSSZ(buf []byte) error { // SizeSSZ returns the ssz encoded size in bytes for the Reshare object func (r *Reshare) SizeSSZ() (size int) { - size = 108 + size = 116 // Field (1) 'OldOperators' for ii := 0; ii < len(r.OldOperators); ii++ { @@ -624,6 +639,9 @@ func (r *Reshare) HashTreeRootWith(hh ssz.HashWalker) (err error) { // Field (8) 'Nonce' hh.PutUint64(r.Nonce) + // Field (9) 'Amount' + hh.PutUint64(r.Amount) + hh.Merkleize(indx) return } @@ -769,7 +787,7 @@ func (r *Resign) MarshalSSZ() ([]byte, error) { // MarshalSSZTo ssz marshals the Resign object to a target array func (r *Resign) MarshalSSZTo(buf []byte) (dst []byte, err error) { dst = buf - offset := int(84) + offset := int(92) // Field (0) 'ValidatorPubKey' if size := len(r.ValidatorPubKey); size != 48 { @@ -791,6 +809,9 @@ func (r *Resign) MarshalSSZTo(buf []byte) (dst []byte, err error) { // Field (4) 'Nonce' dst = ssz.MarshalUint64(dst, r.Nonce) + // Field (5) 'Amount' + dst = ssz.MarshalUint64(dst, r.Amount) + // Field (2) 'WithdrawalCredentials' if size := len(r.WithdrawalCredentials); size > 32 { err = ssz.ErrBytesLengthFn("Resign.WithdrawalCredentials", size, 32) @@ -805,7 +826,7 @@ func (r *Resign) MarshalSSZTo(buf []byte) (dst []byte, err error) { func (r *Resign) UnmarshalSSZ(buf []byte) error { var err error size := uint64(len(buf)) - if size < 84 { + if size < 92 { return ssz.ErrSize } @@ -826,7 +847,7 @@ func (r *Resign) UnmarshalSSZ(buf []byte) error { return ssz.ErrOffset } - if o2 < 84 { + if o2 < 92 { return ssz.ErrInvalidVariableOffset } @@ -836,6 +857,9 @@ func (r *Resign) UnmarshalSSZ(buf []byte) error { // Field (4) 'Nonce' r.Nonce = ssz.UnmarshallUint64(buf[76:84]) + // Field (5) 'Amount' + r.Amount = ssz.UnmarshallUint64(buf[84:92]) + // Field (2) 'WithdrawalCredentials' { buf = tail[o2:] @@ -852,7 +876,7 @@ func (r *Resign) UnmarshalSSZ(buf []byte) error { // SizeSSZ returns the ssz encoded size in bytes for the Resign object func (r *Resign) SizeSSZ() (size int) { - size = 84 + size = 92 // Field (2) 'WithdrawalCredentials' size += len(r.WithdrawalCredentials) @@ -897,6 +921,9 @@ func (r *Resign) HashTreeRootWith(hh ssz.HashWalker) (err error) { // Field (4) 'Nonce' hh.PutUint64(r.Nonce) + // Field (5) 'Amount' + hh.PutUint64(r.Amount) + hh.Merkleize(indx) return }