forked from OffchainLabs/nitro
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry picks recent commits from celestia-integration (#394)
* Move tee address (#392) * move espressoTeeVerifierAddr to transaction streamer This commit moves the TEE verifier contract address to the transaction streamer, configurable via the batch posters config. * Fix tests and transaction_streamer * use a string for tee verifier address Koanf cannot parse a common.Address by default, so we should use a string when taking in this config option. * fix compilation * fix e2e test * Fix config parsing * Fix lint and run formatter * Remove outdated test (cherry picked from commit 30689d6) * Add attestation quote to Espresso payload (#385) * Add attestation quote to Espresso payload * cleanup code * fix lint * add position * fix verify namespace proof bug * Increase hotshot transaction limit * build hotshot payload and add unitests for it * Verify merkle proof first * Rename * push minor fixes --------- Co-authored-by: ImJeremyHe <[email protected]> (cherry picked from commit 47e6010) --------- Co-authored-by: Zach Showalter <[email protected]> Co-authored-by: Sneh Koul <[email protected]>
- Loading branch information
1 parent
c6b3883
commit 8790a1f
Showing
7 changed files
with
424 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package arbnode | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
"errors" | ||
|
||
espressoTypes "github.com/EspressoSystems/espresso-sequencer-go/types" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/offchainlabs/nitro/arbutil" | ||
) | ||
|
||
const MAX_ATTESTATION_QUOTE_SIZE int = 4 * 1024 | ||
const LEN_SIZE int = 8 | ||
const INDEX_SIZE int = 8 | ||
|
||
func buildRawHotShotPayload( | ||
msgPositions []arbutil.MessageIndex, | ||
msgFetcher func(arbutil.MessageIndex) ([]byte, error), | ||
maxSize uint64, | ||
) ([]byte, int) { | ||
|
||
payload := []byte{} | ||
msgCnt := 0 | ||
|
||
for _, p := range msgPositions { | ||
msgBytes, err := msgFetcher(p) | ||
if err != nil { | ||
log.Warn("failed to fetch the message", "pos", p) | ||
break | ||
} | ||
|
||
sizeBuf := make([]byte, LEN_SIZE) | ||
positionBuf := make([]byte, INDEX_SIZE) | ||
|
||
if len(payload)+len(sizeBuf)+len(msgBytes)+len(positionBuf)+MAX_ATTESTATION_QUOTE_SIZE > int(maxSize) { | ||
break | ||
} | ||
binary.BigEndian.PutUint64(sizeBuf, uint64(len(msgBytes))) | ||
binary.BigEndian.PutUint64(positionBuf, uint64(p)) | ||
|
||
// Add the submitted txn position and the size of the message along with the message | ||
payload = append(payload, positionBuf...) | ||
payload = append(payload, sizeBuf...) | ||
payload = append(payload, msgBytes...) | ||
msgCnt += 1 | ||
} | ||
return payload, msgCnt | ||
} | ||
|
||
func signHotShotPayload( | ||
unsigned []byte, | ||
signer func([]byte) ([]byte, error), | ||
) ([]byte, error) { | ||
quote, err := signer(unsigned) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
quoteSizeBuf := make([]byte, LEN_SIZE) | ||
binary.BigEndian.PutUint64(quoteSizeBuf, uint64(len(quote))) | ||
// Put the signature first. That would help easier parsing. | ||
result := quoteSizeBuf | ||
result = append(result, quote...) | ||
result = append(result, unsigned...) | ||
|
||
return result, nil | ||
} | ||
|
||
func validateIfPayloadIsInBlock(p []byte, payloads []espressoTypes.Bytes) bool { | ||
validated := false | ||
for _, payload := range payloads { | ||
if bytes.Equal(p, payload) { | ||
validated = true | ||
break | ||
} | ||
} | ||
return validated | ||
} | ||
|
||
func ParseHotShotPayload(payload []byte) (signature []byte, indices []uint64, messages [][]byte, err error) { | ||
if len(payload) < LEN_SIZE { | ||
return nil, nil, nil, errors.New("payload too short to parse signature size") | ||
} | ||
|
||
// Extract the signature size | ||
signatureSize := binary.BigEndian.Uint64(payload[:LEN_SIZE]) | ||
currentPos := LEN_SIZE | ||
|
||
if len(payload[currentPos:]) < int(signatureSize) { | ||
return nil, nil, nil, errors.New("payload too short for signature") | ||
} | ||
|
||
// Extract the signature | ||
signature = payload[currentPos : currentPos+int(signatureSize)] | ||
currentPos += int(signatureSize) | ||
|
||
indices = []uint64{} | ||
messages = [][]byte{} | ||
|
||
// Parse messages | ||
for { | ||
if currentPos == len(payload) { | ||
break | ||
} | ||
if len(payload[currentPos:]) < LEN_SIZE+INDEX_SIZE { | ||
return nil, nil, nil, errors.New("remaining bytes") | ||
} | ||
|
||
// Extract the index | ||
index := binary.BigEndian.Uint64(payload[currentPos : currentPos+INDEX_SIZE]) | ||
currentPos += INDEX_SIZE | ||
|
||
// Extract the message size | ||
messageSize := binary.BigEndian.Uint64(payload[currentPos : currentPos+LEN_SIZE]) | ||
currentPos += LEN_SIZE | ||
|
||
if len(payload[currentPos:]) < int(messageSize) { | ||
return nil, nil, nil, errors.New("message size mismatch") | ||
} | ||
|
||
// Extract the message | ||
message := payload[currentPos : currentPos+int(messageSize)] | ||
currentPos += int(messageSize) | ||
|
||
indices = append(indices, index) | ||
messages = append(messages, message) | ||
} | ||
|
||
return signature, indices, messages, nil | ||
} |
Oops, something went wrong.