forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'zkevm' into 1298-acl-access-control-list-augmentation
- Loading branch information
Showing
12 changed files
with
548 additions
and
15 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
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,2 @@ | ||
rpc_url="http://0.0.0.0:8467" | ||
private_key="" |
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,21 @@ | ||
set -a # automatically export all variables | ||
source .env | ||
set +a | ||
|
||
if [ -z "$rpc_url" ]; then | ||
echo "Please fill "rpc_url" in the .env file" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$private_key" ]; then | ||
echo "Please fill "private_key" in the .env file" | ||
exit 1 | ||
fi | ||
# balance before sending funds | ||
echo "Balance before sending funds $(cast balance --rpc-url $rpc_url 0x5e8f0f2f8b364e2f0f3f1f1f1f1f1f1f1f1f1f1f)" | ||
|
||
# send some funds | ||
cast send --rpc-url $rpc_url --legacy --value 0.1ether --private-key $private_key 0x5e8f0f2f8b364e2f0f3f1f1f1f1f1f1f1f1f1f1f | ||
|
||
# now get the balance of the accounts | ||
echo "Balance after sending funds $(cast balance --rpc-url $rpc_url 0x5e8f0f2f8b364e2f0f3f1f1f1f1f1f1f1f1f1f1f)" |
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,19 @@ | ||
set -a # automatically export all variables | ||
source .env | ||
set +a | ||
|
||
if [ -z "$rpc_url" ]; then | ||
echo "Please fill "rpc_url" in the .env file" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$private_key" ]; then | ||
echo "Please fill "private_key" in the .env file" | ||
exit 1 | ||
fi | ||
|
||
addr=$(cast wallet address --private-key $private_key) | ||
nonce=$(cast nonce --rpc-url $rpc_url $addr) | ||
|
||
echo "Test address: $addr (nonce: $nonce) balance $(cast balance --rpc-url $rpc_url $addr)" | ||
cast send --legacy --rpc-url $rpc_url --private-key $private_key --async --create 0x5b3456 |
25 changes: 25 additions & 0 deletions
25
zk/debug_tools/cast-scripts/nonce-with-infinite-loop-sc.sh
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,25 @@ | ||
set -a # automatically export all variables | ||
source .env | ||
set +a | ||
|
||
if [ -z "$rpc_url" ]; then | ||
echo "Please fill "rpc_url" in the .env file" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$private_key" ]; then | ||
echo "Please fill "private_key" in the .env file" | ||
exit 1 | ||
fi | ||
|
||
addr=$(cast wallet address --private-key $private_key) | ||
nonce=$(cast nonce --rpc-url $rpc_url $addr) | ||
|
||
echo "Test address: $addr (nonce: $nonce) balance $(cast balance --rpc-url $rpc_url $addr)" | ||
cast send --legacy --rpc-url $rpc_url --private-key $private_key --gas-limit 5000000000000000000 --gas-price 1100 --async --create 0x5b3456 | ||
echo "Test address: $addr (nonce: $(cast nonce --rpc-url $rpc_url $addr)) balance $(cast balance --rpc-url $rpc_url $addr)" | ||
#sleep 5 seconds | ||
echo "Sleeping for 5 seconds..." | ||
sleep 5 | ||
|
||
echo "Test address: $addr (nonce: $(cast nonce --rpc-url $rpc_url $addr)) balance $(cast balance --rpc-url $rpc_url $addr)" |
105 changes: 105 additions & 0 deletions
105
zk/debug_tools/l1-sequences-downloader/acc-input-hash/main.go
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,105 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
"os" | ||
|
||
"github.com/ledgerwatch/erigon-lib/common" | ||
"github.com/ledgerwatch/erigon/zk/syncer" | ||
"github.com/ledgerwatch/erigon/zk/types" | ||
) | ||
|
||
func main() { | ||
fileSeq, err := os.Open("sequencesMainnet.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer fileSeq.Close() | ||
sequences := make([]types.L1BatchInfo, 0) | ||
|
||
encSeq := json.NewDecoder(fileSeq) | ||
if err := encSeq.Decode(&sequences); err != nil { | ||
panic(err) | ||
} | ||
fileSeq.Close() | ||
fileCalldata, err := os.Open("calldataMainnet.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer fileCalldata.Close() | ||
calldata := make(map[string]string) | ||
|
||
encCalldata := json.NewDecoder(fileCalldata) | ||
if err := encCalldata.Decode(&calldata); err != nil { | ||
panic(err) | ||
} | ||
fileCalldata.Close() | ||
fileAccInputHash, err := os.Open("accInputHashesMainnet.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer fileAccInputHash.Close() | ||
accInputHashes := make(map[uint64]string) | ||
|
||
encAccInputHash := json.NewDecoder(fileAccInputHash) | ||
if err := encAccInputHash.Decode(&accInputHashes); err != nil { | ||
panic(err) | ||
} | ||
fileAccInputHash.Close() | ||
|
||
for i := 0; i < 40000; i++ { | ||
delete(calldata, sequences[i].L1TxHash.String()) | ||
delete(accInputHashes, sequences[i].BatchNo) | ||
} | ||
|
||
prevSeq := sequences[40001] | ||
for i := 40002; i < len(sequences); i++ { | ||
nextSeq := sequences[i] | ||
nextCalldata, ok := calldata[nextSeq.L1TxHash.String()] | ||
if !ok { | ||
panic(fmt.Errorf("calldata for tx %s not found", nextSeq.L1TxHash.String())) | ||
} | ||
prevAccInputHash, ok := accInputHashes[prevSeq.BatchNo] | ||
if !ok { | ||
panic(fmt.Errorf("accInputHash for batch %d not found", prevSeq.BatchNo)) | ||
} | ||
lastAccInputHash, ok := accInputHashes[nextSeq.BatchNo] | ||
if !ok { | ||
panic(fmt.Errorf("accInputHash for batch %d not found", nextSeq.BatchNo)) | ||
} | ||
|
||
decodedSequenceInterface, err := syncer.DecodeSequenceBatchesCalldata(common.FromHex(nextCalldata)) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to decode calldata for tx %s: %w", nextSeq.L1TxHash, err)) | ||
} | ||
|
||
accInputHashCalcFn, totalSequenceBatches, err := syncer.GetAccInputDataCalcFunction(nextSeq.L1InfoRoot, decodedSequenceInterface) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to get accInputHash calculation func: %w", err)) | ||
} | ||
|
||
if totalSequenceBatches == 0 || nextSeq.BatchNo-prevSeq.BatchNo > uint64(totalSequenceBatches) { | ||
panic(fmt.Errorf("batch %d is out of range of sequence calldata: %d %d", nextSeq.BatchNo, prevSeq.BatchNo, totalSequenceBatches)) | ||
} | ||
|
||
prevAccInputBigInt := new(big.Int).SetBytes(common.FromHex(prevAccInputHash)) | ||
preVAccInputHash := common.BigToHash(prevAccInputBigInt) | ||
accInputHash := &preVAccInputHash | ||
// calculate acc input hash | ||
for i := 0; i < int(nextSeq.BatchNo-prevSeq.BatchNo); i++ { | ||
accInputHash = accInputHashCalcFn(*accInputHash, i) | ||
} | ||
|
||
if accInputHash.Hex() != lastAccInputHash { | ||
panic(fmt.Errorf("accInputHash for tx %s and batchNum %d does not match", nextSeq.L1TxHash.String(), nextSeq.BatchNo)) | ||
} | ||
|
||
prevSeq = nextSeq | ||
if i%1000 == 0 { | ||
fmt.Println(i, " sequence checked: ", nextSeq.BatchNo) | ||
} | ||
} | ||
|
||
} |
150 changes: 150 additions & 0 deletions
150
zk/debug_tools/l1-sequences-downloader/sequence-accinputhash/main.go
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,150 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/binary" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
ethereum "github.com/ledgerwatch/erigon" | ||
"github.com/ledgerwatch/erigon-lib/common" | ||
|
||
"github.com/iden3/go-iden3-crypto/keccak256" | ||
"github.com/ledgerwatch/erigon/ethclient" | ||
"github.com/ledgerwatch/erigon/zk/debug_tools" | ||
"github.com/ledgerwatch/erigon/zk/types" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
cfg, err := debug_tools.GetConf() | ||
if err != nil { | ||
panic(fmt.Sprintf("RPGCOnfig: %s", err)) | ||
} | ||
|
||
file, err := os.Open("sequencesMainnet.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer file.Close() | ||
sequences := make([]types.L1BatchInfo, 0) | ||
|
||
enc := json.NewDecoder(file) | ||
if err := enc.Decode(&sequences); err != nil { | ||
panic(err) | ||
} | ||
|
||
ethClient, err := ethclient.Dial(cfg.L1Url) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
emptyHash := common.Hash{} | ||
rollupAddr := common.HexToAddress(cfg.AddressRollup) | ||
accInputHashes := make(map[uint64]string) | ||
index := 0 | ||
for { | ||
seq := sequences[index] | ||
// get call data for tx | ||
|
||
var accInputHash common.Hash | ||
var err error | ||
if seq.BatchNo < cfg.ElderberryBachNo { | ||
accInputHash, err = callSequencedBatchesMap(ctx, ethClient, &rollupAddr, seq.BatchNo) | ||
} else { | ||
accInputHash, _, err = callGetRollupSequencedBatches(ctx, ethClient, &rollupAddr, cfg.RollupId, seq.BatchNo) | ||
} | ||
if err != nil { | ||
fmt.Println("Error fetching transaction: ", err, " for batch ", seq.BatchNo) | ||
continue | ||
} | ||
|
||
if accInputHash == emptyHash { | ||
fmt.Println("Error fetching transaction: accInputHash is empty for batch ", seq.BatchNo) | ||
panic("Error fetching transaction: accInputHash is empty for batch") | ||
} | ||
accInputHashes[seq.BatchNo] = accInputHash.Hex() | ||
|
||
index++ | ||
if index >= len(sequences) { | ||
break | ||
} | ||
|
||
if index%100 == 0 { | ||
fmt.Println("Processed ", index, "sequences from ", len(sequences)) | ||
} | ||
|
||
time.Sleep(2 * time.Millisecond) | ||
} | ||
|
||
// write l1BatchInfos to file | ||
file2, err := os.Create("accInputHashes.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer file2.Close() | ||
|
||
enc2 := json.NewEncoder(file2) | ||
enc2.SetIndent("", " ") | ||
if err := enc2.Encode(accInputHashes); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// calls the old rollup contract to get the accInputHash for a certain batch | ||
// returns the accInputHash and lastBatchNumber | ||
func callSequencedBatchesMap(ctx context.Context, client *ethclient.Client, addr *common.Address, batchNum uint64) (accInputHash common.Hash, err error) { | ||
mapKeyHex := fmt.Sprintf("%064x%064x", batchNum, 114 /* _legacySequencedBatches slot*/) | ||
mapKey := keccak256.Hash(common.FromHex(mapKeyHex)) | ||
mkh := common.BytesToHash(mapKey) | ||
|
||
resp, err := client.StorageAt(ctx, *addr, mkh, nil) | ||
if err != nil { | ||
return | ||
} | ||
|
||
if err != nil { | ||
return | ||
} | ||
|
||
if len(resp) < 32 { | ||
return | ||
} | ||
accInputHash = common.BytesToHash(resp[:32]) | ||
|
||
return | ||
} | ||
|
||
var ( | ||
errorShortResponseLT32 = fmt.Errorf("response length is less than 32 bytes") | ||
errorShortResponseLT96 = fmt.Errorf("response length is less than 96 bytes") | ||
rollupSequencedBatchesSignature = "0x25280169" // hardcoded abi signature | ||
) | ||
|
||
func callGetRollupSequencedBatches(ctx context.Context, client *ethclient.Client, addr *common.Address, rollupId, batchNum uint64) (common.Hash, uint64, error) { | ||
rollupID := fmt.Sprintf("%064x", rollupId) | ||
batchNumber := fmt.Sprintf("%064x", batchNum) | ||
|
||
resp, err := client.CallContract(ctx, ethereum.CallMsg{ | ||
To: addr, | ||
Data: common.FromHex(rollupSequencedBatchesSignature + rollupID + batchNumber), | ||
}, nil) | ||
|
||
if err != nil { | ||
return common.Hash{}, 0, err | ||
} | ||
|
||
if len(resp) < 32 { | ||
return common.Hash{}, 0, errorShortResponseLT32 | ||
} | ||
h := common.BytesToHash(resp[:32]) | ||
|
||
if len(resp) < 96 { | ||
return common.Hash{}, 0, errorShortResponseLT96 | ||
} | ||
lastBatchNumber := binary.BigEndian.Uint64(resp[88:96]) | ||
|
||
return h, lastBatchNumber, nil | ||
} |
Oops, something went wrong.