Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(encoding): implement EncodeProverAssignmentPayload()
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Oct 1, 2023
1 parent 355ced6 commit 34765da
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 37 deletions.
39 changes: 34 additions & 5 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,37 @@ var (

var (
// Evidence
EvidenceType, _ = abi.NewType("tuple", "TaikoData.BlockEvidence", evidenceComponents)
EvidenceArgs = abi.Arguments{{Name: "Evidence", Type: EvidenceType}}
evidenceType, _ = abi.NewType("tuple", "TaikoData.BlockEvidence", evidenceComponents)
evidenceArgs = abi.Arguments{{Name: "Evidence", Type: evidenceType}}
// ProverAssignment
proverAssignmentType, _ = abi.NewType("tuple", "ProverAssignment", proverAssignmentComponents)
proverAssignmentArgs = abi.Arguments{{Name: "ProverAssignment", Type: proverAssignmentType}}
// ProverAssignmentPayload
stringType, _ = abi.NewType("string", "", nil)
bytes32Type, _ = abi.NewType("bytes32", "", nil)
addressType, _ = abi.NewType("address", "", nil)
uint64Type, _ = abi.NewType("uint64", "", nil)
tierFeesType, _ = abi.NewType(
"tuple[]",
"",
[]abi.ArgumentMarshaling{
{
Name: "tier",
Type: "uint16",
},
{
Name: "fee",
Type: "uint256",
},
},
)
proverAssignmentPayloadArgs = abi.Arguments{
{Name: "PROVER_ASSIGNMENT", Type: stringType},
{Name: "txListHash", Type: bytes32Type},
{Name: "assignment.feeToken", Type: addressType},
{Name: "assignment.expiry", Type: uint64Type},
{Name: "assignment.tierFees", Type: tierFeesType},
}
)

// Contract ABIs.
Expand Down Expand Up @@ -114,7 +140,7 @@ func EncodeProverAssignment(assignment *ProverAssignment) ([]byte, error) {

// EncodeEvidence performs the solidity `abi.encode` for the given evidence.
func EncodeEvidence(e *BlockEvidence) ([]byte, error) {
b, err := EvidenceArgs.Pack(e)
b, err := evidenceArgs.Pack(e)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode evidence, %w", err)
}
Expand All @@ -128,8 +154,11 @@ func EncodeProverAssignmentPayload(
expiry uint64,
tierFees []TierFee,
) ([]byte, error) {
// TODO: implement this function.
return nil, nil
b, err := proverAssignmentPayloadArgs.Pack("PROVER_ASSIGNMENT", txListHash, feeToken, expiry, tierFees)
if err != nil {
return nil, fmt.Errorf("failed to abi.encode prover assignment hash payload, %w", err)
}
return b, nil
}

// UnpackTxListBytes unpacks the input data of a TaikoL1.proposeBlock transaction, and returns the txList bytes.
Expand Down
31 changes: 14 additions & 17 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,18 @@ func InitFromConfig(ctx context.Context, p *Proposer, cfg *Config) (err error) {
return err
}

log.Info("Protocol tiers", "tiers", p.tiers)

// TODO: use flags to set tier fees
for _, tier := range p.tiers {
log.Info(
"Protocol tier",
"id", tier.ID,
"name", string(tier.VerifierName[:]),
"validityBond", tier.ValidityBond,
"contestBond", tier.ContestBond,
"provingWindow", tier.ProvingWindow,
"cooldownWindow", tier.CooldownWindow,
)

p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: common.Big256})
}

Expand Down Expand Up @@ -343,7 +351,7 @@ func (p *Proposer) sendProposeBlockTx(
ctx context.Context,
txListBytes []byte,
nonce *uint64,
assignment *encoding.ProverAssignment,
signedAssignment []byte,
fee *big.Int,
isReplacement bool,
) (*types.Transaction, error) {
Expand Down Expand Up @@ -371,16 +379,11 @@ func (p *Proposer) sendProposeBlockTx(
}
}

encodedssignment, err := encoding.EncodeProverAssignment(assignment)
if err != nil {
return nil, err
}

proposeTx, err := p.rpc.TaikoL1.ProposeBlock(
opts,
crypto.Keccak256Hash(txListBytes),
rpc.StringToBytes32(p.cfg.ExtraData),
encodedssignment,
signedAssignment,
txListBytes,
)
if err != nil {
Expand All @@ -397,7 +400,7 @@ func (p *Proposer) ProposeTxList(
txNum uint,
nonce *uint64,
) error {
signature, prover, fee, err := p.proverSelector.AssignProver(
signedAssignment, fee, err := p.proverSelector.AssignProver(
ctx,
p.tierFees,
crypto.Keccak256Hash(txListBytes),
Expand All @@ -419,13 +422,7 @@ func (p *Proposer) ProposeTxList(
ctx,
txListBytes,
nonce,
&encoding.ProverAssignment{
Prover: prover,
FeeToken: common.Address{},
TierFees: p.tierFees,
Expiry: uint64(proverAssignmentTimeout.Seconds()),
Signature: signature,
},
signedAssignment,
fee,
isReplacement,
); err != nil {
Expand Down
13 changes: 3 additions & 10 deletions proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/stretchr/testify/suite"
"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-client/testutils"
)

Expand Down Expand Up @@ -161,7 +160,7 @@ func (s *ProposerTestSuite) TestSendProposeBlockTx() {
encoded, err := rlp.EncodeToBytes(emptyTxs)
s.Nil(err)

signature, prover, fee, err := s.p.proverSelector.AssignProver(
signedAssignment, fee, err := s.p.proverSelector.AssignProver(
context.Background(),
s.p.tierFees,
testutils.RandomHash(),
Expand All @@ -172,13 +171,7 @@ func (s *ProposerTestSuite) TestSendProposeBlockTx() {
context.Background(),
encoded,
&nonce,
&encoding.ProverAssignment{
Prover: prover,
FeeToken: common.Address{},
TierFees: s.p.tierFees,
Expiry: uint64(proverAssignmentTimeout.Seconds()),
Signature: signature,
},
signedAssignment,
fee,
true,
)
Expand All @@ -190,7 +183,7 @@ func (s *ProposerTestSuite) TestAssignProverSuccessFirstRound() {
s.SetL1Automine(false)
defer s.SetL1Automine(true)

_, _, fee, err := s.p.proverSelector.AssignProver(context.Background(), s.p.tierFees, testutils.RandomHash())
_, fee, err := s.p.proverSelector.AssignProver(context.Background(), s.p.tierFees, testutils.RandomHash())

s.Nil(err)
s.Equal(fee.Uint64(), s.p.cfg.BlockProposalFee.Uint64())
Expand Down
10 changes: 6 additions & 4 deletions proposer/prover_selector/eth_fee_eoa_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ func (s *ETHFeeEOASelector) AssignProver(
ctx context.Context,
tierFees []encoding.TierFee,
txListHash common.Hash,
) ([]byte, common.Address, *big.Int, error) {
) ([]byte, *big.Int, error) {
guardianProverAddress, err := s.rpc.TaikoL1.Resolve0(
&bind.CallOpts{Context: ctx},
rpc.StringToBytes32("guardian"),
true,
)
if err != nil {
return nil, common.Address{}, nil, err
return nil, nil, err
}
// Iterate over each configured endpoint, and see if someone wants to accept this block.
// If it is denied, we continue on to the next endpoint.
Expand Down Expand Up @@ -134,11 +134,11 @@ func (s *ETHFeeEOASelector) AssignProver(
}

// TODO: fix fee value
return encodedAssignment, proverAddress, common.Big1, nil
return encodedAssignment, common.Big256, nil
}
}

return nil, common.Address{}, nil, errUnableToFindProver
return nil, nil, errUnableToFindProver
}

// shuffleProverEndpoints shuffles the current selector's prover endpoints.
Expand Down Expand Up @@ -220,7 +220,9 @@ func assignProver(
}

// Convert signature to one solidity can recover by adding 27 to 65th byte
log.Info("Prover signature", "signature", result.SignedPayload, "len", len(result.SignedPayload))
result.SignedPayload[64] = uint8(uint(result.SignedPayload[64])) + 27
log.Info("Prover signature2", "signature", result.SignedPayload, "len", len(result.SignedPayload))

encoded, err := encoding.EncodeProverAssignment(&encoding.ProverAssignment{
Prover: result.Prover,
Expand Down
2 changes: 1 addition & 1 deletion proposer/prover_selector/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ type ProverSelector interface {
ctx context.Context,
tierFees []encoding.TierFee,
txListHash common.Hash,
) (signedPayload []byte, prover common.Address, fee *big.Int, err error)
) (signedPayload []byte, fee *big.Int, err error)
ProverEndpoints() []*url.URL
}

0 comments on commit 34765da

Please sign in to comment.