1
1
package encoding
2
2
3
3
import (
4
+ "bytes"
5
+ "encoding/binary"
4
6
"errors"
5
7
"fmt"
6
8
7
9
"github.com/ethereum/go-ethereum/accounts/abi"
8
10
"github.com/ethereum/go-ethereum/common"
11
+ "github.com/ethereum/go-ethereum/crypto"
9
12
"github.com/ethereum/go-ethereum/log"
10
13
11
14
"github.com/taikoxyz/taiko-client/bindings"
12
15
)
13
16
14
17
// ABI arguments marshaling components.
15
18
var (
16
- blockMetadataComponents = []abi.ArgumentMarshaling {
19
+ assignmentPayloadPrefix = "PROVER_ASSIGNMENT"
20
+ assignmentPayloadPrefixSize = len ([]byte (assignmentPayloadPrefix ))
21
+ paddedAssignmentPayloadPrefixBytes = common .LeftPadBytes ([]byte (assignmentPayloadPrefix ), assignmentPayloadPrefixSize )
22
+ blockMetadataComponents = []abi.ArgumentMarshaling {
17
23
{
18
24
Name : "l1Hash" ,
19
25
Type : "bytes32" ,
@@ -198,7 +204,6 @@ var (
198
204
blockParamsComponentsType , _ = abi .NewType ("tuple" , "TaikoData.BlockParams" , blockParamsComponents )
199
205
blockParamsComponentsArgs = abi.Arguments {{Name : "TaikoData.BlockParams" , Type : blockParamsComponentsType }}
200
206
// ProverAssignmentPayload
201
- stringType , _ = abi .NewType ("string" , "" , nil )
202
207
bytes32Type , _ = abi .NewType ("bytes32" , "" , nil )
203
208
addressType , _ = abi .NewType ("address" , "" , nil )
204
209
uint64Type , _ = abi .NewType ("uint64" , "" , nil )
@@ -216,19 +221,14 @@ var (
216
221
},
217
222
},
218
223
)
219
- proverAssignmentPayloadArgs = abi.Arguments {
220
- {Name : "PROVER_ASSIGNMENT" , Type : stringType },
221
- {Name : "chainID" , Type : uint64Type },
222
- {Name : "taikoAddress" , Type : addressType },
223
- {Name : "assignmentHookAddress" , Type : addressType },
224
- {Name : "metaHash" , Type : bytes32Type },
225
- {Name : "parentMetaHash" , Type : bytes32Type },
226
- {Name : "blobHash" , Type : bytes32Type },
227
- {Name : "assignment.feeToken" , Type : addressType },
228
- {Name : "assignment.expiry" , Type : uint64Type },
229
- {Name : "assignment.maxBlockId" , Type : uint64Type },
230
- {Name : "assignment.maxProposedIn" , Type : uint64Type },
231
- {Name : "assignment.tierFees" , Type : tierFeesType },
224
+ proverAssignmentHashPayloadArgs = abi.Arguments {
225
+ {Name : "_assignment.metaHash" , Type : bytes32Type },
226
+ {Name : "_assignment.parentMetaHash" , Type : bytes32Type },
227
+ {Name : "_assignment.feeToken" , Type : addressType },
228
+ {Name : "_assignment.expiry" , Type : uint64Type },
229
+ {Name : "_assignment.maxBlockId" , Type : uint64Type },
230
+ {Name : "_assignment.maxProposedIn" , Type : uint64Type },
231
+ {Name : "_assignment.tierFees" , Type : tierFeesType },
232
232
}
233
233
blockMetadataComponentsType , _ = abi .NewType ("tuple" , "TaikoData.BlockMetadata" , blockMetadataComponents )
234
234
transitionComponentsType , _ = abi .NewType ("tuple" , "TaikoData.Transition" , transitionComponents )
@@ -341,21 +341,18 @@ func EncodeProverAssignmentPayload(
341
341
chainID uint64 ,
342
342
taikoAddress common.Address ,
343
343
assignmentHookAddress common.Address ,
344
- txListHash common.Hash ,
344
+ blockProposer common.Address ,
345
+ assignedProver common.Address ,
346
+ blobHash common.Hash ,
345
347
feeToken common.Address ,
346
348
expiry uint64 ,
347
349
maxBlockID uint64 ,
348
350
maxProposedIn uint64 ,
349
351
tierFees []TierFee ,
350
352
) ([]byte , error ) {
351
- b , err := proverAssignmentPayloadArgs .Pack (
352
- "PROVER_ASSIGNMENT" ,
353
- chainID ,
354
- taikoAddress ,
355
- assignmentHookAddress ,
353
+ hashBytesPayload , err := proverAssignmentHashPayloadArgs .Pack (
356
354
common.Hash {},
357
355
common.Hash {},
358
- txListHash ,
359
356
feeToken ,
360
357
expiry ,
361
358
maxBlockID ,
@@ -365,7 +362,20 @@ func EncodeProverAssignmentPayload(
365
362
if err != nil {
366
363
return nil , fmt .Errorf ("failed to abi.encode prover assignment hash payload, %w" , err )
367
364
}
368
- return b , nil
365
+
366
+ chainIDBytes := make ([]byte , 8 )
367
+ binary .BigEndian .PutUint64 (chainIDBytes , chainID )
368
+
369
+ return bytes .Join ([][]byte {
370
+ paddedAssignmentPayloadPrefixBytes [len (paddedAssignmentPayloadPrefixBytes )- assignmentPayloadPrefixSize :],
371
+ chainIDBytes ,
372
+ taikoAddress .Bytes (),
373
+ blockProposer .Bytes (),
374
+ assignedProver .Bytes (),
375
+ blobHash .Bytes (),
376
+ crypto .Keccak256Hash (hashBytesPayload ).Bytes (),
377
+ assignmentHookAddress .Bytes (),
378
+ }, nil ), nil
369
379
}
370
380
371
381
// EncodeProveBlockInput performs the solidity `abi.encode` for the given TaikoL1.proveBlock input.
0 commit comments