Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,11 @@ func (m callMsg) IsL1MessageTx() bool { return false }
func (m callMsg) SetCodeAuthorizations() []types.SetCodeAuthorization {
return m.CallMsg.AuthorizationList
}
func (m callMsg) FeeTokenID() uint16 { return m.CallMsg.FeeTokenID }
func (m callMsg) FeeLimit() *big.Int { return m.CallMsg.FeeLimit }
func (m callMsg) FeeTokenID() uint16 { return m.CallMsg.FeeTokenID }
func (m callMsg) FeeLimit() *big.Int { return m.CallMsg.FeeLimit }
func (m callMsg) Version() byte { return m.CallMsg.Version }
func (m callMsg) Reference() *common.Reference { return m.CallMsg.Reference }
func (m callMsg) Memo() *[]byte { return m.CallMsg.Memo }

// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
Expand Down
29 changes: 23 additions & 6 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ type TransactOpts struct {
GasTipCap *big.Int // Gas priority fee cap to use for the 1559 transaction execution (nil = gas price oracle)
GasLimit uint64 // Gas limit to set for the transaction execution (0 = estimate)

FeeTokenID uint16 // alt fee token id of transaction execution
FeeLimit *big.Int // alt fee token limit of transaction execution
FeeTokenID uint16 // alt fee token id of transaction execution
FeeLimit *big.Int // alt fee token limit of transaction execution
Version uint8 // version of morph tx
Reference *common.Reference // reference key for the transaction (optional)
Memo *[]byte // memo for the transaction (optional)

Context context.Context // Network context to support cancellation and timeouts (nil = no timeout)

Expand Down Expand Up @@ -290,7 +293,7 @@ func (c *BoundContract) createDynamicTx(opts *TransactOpts, contract *common.Add
return types.NewTx(baseTx), nil
}

func (c *BoundContract) createAltFeeTx(opts *TransactOpts, contract *common.Address, input []byte, head *types.Header) (*types.Transaction, error) {
func (c *BoundContract) createMorphTx(opts *TransactOpts, contract *common.Address, input []byte, head *types.Header) (*types.Transaction, error) {
// Normalize value
value := opts.Value
if value == nil {
Expand Down Expand Up @@ -334,14 +337,25 @@ func (c *BoundContract) createAltFeeTx(opts *TransactOpts, contract *common.Addr
if err != nil {
return nil, err
}
baseTx := &types.AltFeeTx{
// Determine version:
// - If Version is explicitly set (> 0), use it
// - If Version is 0 and FeeTokenID > 0, keep Version 0 (backward compatible legacy format)
// - If Version is 0 and FeeTokenID == 0, default to Version 1 (new format)
version := opts.Version
if version == 0 && opts.FeeTokenID == 0 {
version = types.MorphTxVersion1
}
baseTx := &types.MorphTx{
To: contract,
Nonce: nonce,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
FeeTokenID: opts.FeeTokenID,
FeeLimit: opts.FeeLimit,
Gas: gasLimit,
Version: version,
Reference: opts.Reference,
Memo: opts.Memo,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
Value: value,
Data: input,
}
Expand Down Expand Up @@ -438,8 +452,11 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
if head, errHead := c.transactor.HeaderByNumber(ensureContext(opts.Context), nil); errHead != nil {
return nil, errHead
} else if head.BaseFee != nil {
if opts.FeeTokenID != 0 {
rawTx, err = c.createAltFeeTx(opts, contract, input, head)
if opts.FeeTokenID != 0 ||
opts.Version != 0 ||
(opts.Reference != nil && *opts.Reference != (common.Reference{})) ||
(opts.Memo != nil && len(*opts.Memo) > 0) {
rawTx, err = c.createMorphTx(opts, contract, input, head)
} else {
rawTx, err = c.createDynamicTx(opts, contract, input, head)
}
Expand Down
7 changes: 6 additions & 1 deletion accounts/external/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,17 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
case types.DynamicFeeTxType, types.SetCodeTxType:
args.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap())
args.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap())
case types.AltFeeTxType:
case types.MorphTxType:
args.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap())
args.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap())
feeTokenID := hexutil.Uint16(tx.FeeTokenID())
args.FeeTokenID = &feeTokenID
args.FeeLimit = (*hexutil.Big)(tx.FeeLimit())
version := hexutil.Uint64(tx.Version())
args.Version = &version
args.Reference = tx.Reference()
memo := hexutil.Bytes(*tx.Memo())
args.Memo = &memo
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
default:
return nil, fmt.Errorf("unsupported tx type %d", tx.Type())
}
Expand Down
22 changes: 16 additions & 6 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,22 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
receipt.TxHash = tx.Hash()
receipt.GasUsed = msgResult.UsedGas
receipt.L1Fee = msgResult.L1DataFee
if msg.FeeTokenID() != 0 {
tokenID := msg.FeeTokenID()
receipt.FeeTokenID = &tokenID
receipt.FeeLimit = msg.FeeLimit()
receipt.FeeRate = msgResult.FeeRate
receipt.TokenScale = msgResult.TokenScale

if msg.FeeTokenID() != 0 ||
msg.Version() != 0 ||
(msg.Reference() != nil && *msg.Reference() != (common.Reference{})) ||
(msg.Memo() != nil && len(*msg.Memo()) > 0) {
if msg.FeeTokenID() != 0 {
tokenID := msg.FeeTokenID()
receipt.FeeTokenID = &tokenID
receipt.FeeLimit = msg.FeeLimit()
receipt.FeeRate = msgResult.FeeRate
receipt.TokenScale = msgResult.TokenScale
}
version := msg.Version()
receipt.Version = version
receipt.Reference = msg.Reference()
receipt.Memo = msg.Memo()
}

// If the transaction created a contract, store the creation address in the receipt.
Expand Down
165 changes: 163 additions & 2 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,174 @@ const (
HashLength = 32
// AddressLength is the expected length of the address
AddressLength = 20
// ReferenceLength is the expected length of the reference
ReferenceLength = 32
// MaxMemoLength is the maximum length of the memo in MorphTx
MaxMemoLength = 64
)

var (
hashT = reflect.TypeOf(Hash{})
addressT = reflect.TypeOf(Address{})
hashT = reflect.TypeOf(Hash{})
addressT = reflect.TypeOf(Address{})
referenceT = reflect.TypeOf(Reference{})
)

// Reference represents the 32 byte reference of a transaction.
type Reference [ReferenceLength]byte

// BytesToReference sets b to reference.
// If b is larger than len(r), b will be cropped from the left.
func BytesToReference(b []byte) Reference {
var r Reference
r.SetBytes(b)
return r
}

// BigToReference sets byte representation of b to reference.
// If b is larger than len(r), b will be cropped from the left.
func BigToReference(b *big.Int) Reference { return BytesToReference(b.Bytes()) }

// HexToReference sets byte representation of s to reference.
// If b is larger than len(r), b will be cropped from the left.
func HexToReference(s string) Reference { return BytesToReference(FromHex(s)) }

// Bytes gets the byte representation of the underlying reference.
func (r Reference) Bytes() []byte { return r[:] }

// Big converts a reference to a big integer.
func (r Reference) Big() *big.Int { return new(big.Int).SetBytes(r[:]) }

// Hex converts a reference to a hex string.
func (r Reference) Hex() string { return hexutil.Encode(r[:]) }

// TerminalString implements log.TerminalStringer, formatting a string for console
// output during logging.
func (r Reference) TerminalString() string {
return fmt.Sprintf("%x..%x", r[:3], r[29:])
}

// String implements the stringer interface and is used also by the logger when
// doing full logging into a file.
func (r Reference) String() string {
return r.Hex()
}

// Format implements fmt.Formatter.
// Reference supports the %v, %s, %q, %x, %X and %d format verbs.
func (r Reference) Format(s fmt.State, c rune) {
hexb := make([]byte, 2+len(r)*2)
copy(hexb, "0x")
hex.Encode(hexb[2:], r[:])

switch c {
case 'x', 'X':
if !s.Flag('#') {
hexb = hexb[2:]
}
if c == 'X' {
hexb = bytes.ToUpper(hexb)
}
fallthrough
case 'v', 's':
s.Write(hexb)
case 'q':
q := []byte{'"'}
s.Write(q)
s.Write(hexb)
s.Write(q)
case 'd':
fmt.Fprint(s, ([len(r)]byte)(r))
default:
fmt.Fprintf(s, "%%!%c(reference=%x)", c, r)
}
}

// SetBytes sets the reference to the value of b.
// If b is larger than len(r), b will be cropped from the left.
func (r *Reference) SetBytes(b []byte) {
if len(b) > len(r) {
b = b[len(b)-ReferenceLength:]
}
copy(r[:], b)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// UnmarshalText parses a reference in hex syntax.
func (r *Reference) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedText("Reference", input, r[:])
}

// UnmarshalJSON parses a reference in hex syntax.
func (r *Reference) UnmarshalJSON(input []byte) error {
return hexutil.UnmarshalFixedJSON(referenceT, input, r[:])
}

// MarshalText returns the hex representation of r.
func (r Reference) MarshalText() ([]byte, error) {
return hexutil.Bytes(r[:]).MarshalText()
}

// MarshalJSON marshals the original value

// MarshalJSON marshals the original value
func (r Reference) MarshalJSON() ([]byte, error) {
return json.Marshal(r.Hex())
}

// Generate implements testing/quick.Generator.
func (r Reference) Generate(rand *rand.Rand, size int) reflect.Value {
m := rand.Intn(len(r))
for i := len(r) - 1; i > m; i-- {
r[i] = byte(rand.Uint32())
}
return reflect.ValueOf(r)
}

// Scan implements Scanner for database/sql.
func (r *Reference) Scan(src interface{}) error {
srcB, ok := src.([]byte)
if !ok {
return fmt.Errorf("can't scan %T into Reference", src)
}
if len(srcB) != ReferenceLength {
return fmt.Errorf("can't scan []byte of len %d into Reference, want %d", len(srcB), ReferenceLength)
}
copy(r[:], srcB)
return nil
}

// Value implements valuer for database/sql.
func (r Reference) Value() (driver.Value, error) {
return r[:], nil
}

// ImplementsGraphQLType returns true if Reference implements the specified GraphQL type.
func (Reference) ImplementsGraphQLType(name string) bool { return name == "Bytes32" }

// UnmarshalGraphQL unmarshals the provided GraphQL query data.
func (r *Reference) UnmarshalGraphQL(input interface{}) error {
var err error
switch input := input.(type) {
case string:
err = r.UnmarshalText([]byte(input))
default:
err = fmt.Errorf("unexpected type %T for Reference", input)
}
return err
}

// UnprefixedReference allows marshaling a Reference without 0x prefix.
type UnprefixedReference Reference

// UnmarshalText decodes the reference from hex. The 0x prefix is optional.
func (r *UnprefixedReference) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedUnprefixedText("UnprefixedReference", input, r[:])
}

// MarshalText encodes the reference as hex.
func (r UnprefixedReference) MarshalText() ([]byte, error) {
return []byte(hex.EncodeToString(r[:])), nil
}

// Hash represents the 32 byte Keccak256 hash of arbitrary data.
type Hash [HashLength]byte

Expand Down
11 changes: 11 additions & 0 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
if !v.config.Morph.IsValidBlockSize(block.PayloadSize()) {
return ErrInvalidBlockPayloadSize
}
// Validate MorphTx for all transactions
for _, tx := range block.Transactions() {
// Validate memo length
if err := tx.ValidateMemo(); err != nil {
return err
}
// Validate version and associated field requirements
if err := tx.ValidateMorphTxVersion(); err != nil {
return err
}
}
// Header validity is known at this point, check the uncles and transactions
header := block.Header()
if err := v.engine.VerifyUncles(v.bc, block); err != nil {
Expand Down
Loading