@@ -20,6 +20,7 @@ import (
20
20
"encoding/binary"
21
21
"errors"
22
22
"fmt"
23
+ gomath "math"
23
24
"math/big"
24
25
25
26
"github.com/ethereum/go-ethereum/common"
@@ -56,11 +57,11 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
56
57
return nil
57
58
}
58
59
59
- // DecodeHolocene1599Params extracts the Holcene 1599 parameters from the encoded form:
60
- // https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/holocene/exec-engine.md#eip1559params-encoding
60
+ // DecodeHolocene1599Params extracts the Holcene 1599 parameters from the encoded form defined here :
61
+ // https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/holocene/exec-engine.md#eip-1559-parameters-in-payloadattributesv3
61
62
//
62
- // Returns 0,0 if the format is invalid, though ValidateHolocene1559Params should be used instead of
63
- // this function for validity checking.
63
+ // Returns 0,0 if the format is invalid, though ValidateHolocene1559Params should be used instead of this function for
64
+ // validity checking.
64
65
func DecodeHolocene1559Params (params []byte ) (uint64 , uint64 ) {
65
66
if len (params ) != 8 {
66
67
return 0 , 0
@@ -70,26 +71,40 @@ func DecodeHolocene1559Params(params []byte) (uint64, uint64) {
70
71
return uint64 (denominator ), uint64 (elasticity )
71
72
}
72
73
73
- // Decodes holocene extra data without performing full validation.
74
+ // DecodeHoloceneExtraData decodes the Holocene 1559 parameters from the encoded form defined here:
75
+ // https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/holocene/exec-engine.md#eip-1559-parameters-in-block-header
76
+ //
77
+ // Returns 0,0 if the format is invalid, though ValidateHoloceneExtraData should be used instead of this function for
78
+ // validity checking.
74
79
func DecodeHoloceneExtraData (extra []byte ) (uint64 , uint64 ) {
75
80
if len (extra ) != 9 {
76
81
return 0 , 0
77
82
}
78
83
return DecodeHolocene1559Params (extra [1 :])
79
84
}
80
85
81
- func EncodeHolocene1559Params (denom , elasticity uint32 ) []byte {
86
+ // EncodeHolocene1559Params encodes the eip-1559 parameters into 'PayloadAttributes.EIP1559Params' format. Will panic if
87
+ // either value is outside uint32 range.
88
+ func EncodeHolocene1559Params (denom , elasticity uint64 ) []byte {
82
89
r := make ([]byte , 8 )
83
- binary .BigEndian .PutUint32 (r [:4 ], denom )
84
- binary .BigEndian .PutUint32 (r [4 :], elasticity )
90
+ if denom > gomath .MaxUint32 || elasticity > gomath .MaxUint32 {
91
+ panic ("eip-1559 parameters out of uint32 range" )
92
+ }
93
+ binary .BigEndian .PutUint32 (r [:4 ], uint32 (denom ))
94
+ binary .BigEndian .PutUint32 (r [4 :], uint32 (elasticity ))
85
95
return r
86
96
}
87
97
88
- func EncodeHoloceneExtraData (denom , elasticity uint32 ) []byte {
98
+ // EncodeHoloceneExtraData encodes the eip-1559 parameters into the header 'ExtraData' format. Will panic if either
99
+ // value is outside uint32 range.
100
+ func EncodeHoloceneExtraData (denom , elasticity uint64 ) []byte {
89
101
r := make ([]byte , 9 )
102
+ if denom > gomath .MaxUint32 || elasticity > gomath .MaxUint32 {
103
+ panic ("eip-1559 parameters out of uint32 range" )
104
+ }
90
105
// leave version byte 0
91
- binary .BigEndian .PutUint32 (r [1 :5 ], denom )
92
- binary .BigEndian .PutUint32 (r [5 :], elasticity )
106
+ binary .BigEndian .PutUint32 (r [1 :5 ], uint32 ( denom ) )
107
+ binary .BigEndian .PutUint32 (r [5 :], uint32 ( elasticity ) )
93
108
return r
94
109
}
95
110
0 commit comments