Skip to content

Commit

Permalink
Merge branch 'main' into jihwan/pgdn-monitor-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jhkimqd committed Nov 22, 2024
2 parents 2da5562 + 8a74ec8 commit 087615d
Show file tree
Hide file tree
Showing 13 changed files with 366 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ coverage.out
*.swo

wallets.json

*.key
58 changes: 58 additions & 0 deletions bindings/tester/LoadTester.abi
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
[
{
"type": "function",
"name": "F",
"inputs": [
{
"name": "rounds",
"type": "uint32",
"internalType": "uint32"
},
{
"name": "h",
"type": "bytes32[2]",
"internalType": "bytes32[2]"
},
{
"name": "m",
"type": "bytes32[4]",
"internalType": "bytes32[4]"
},
{
"name": "t",
"type": "bytes8[2]",
"internalType": "bytes8[2]"
},
{
"name": "f",
"type": "bool",
"internalType": "bool"
}
],
"outputs": [
{
"name": "",
"type": "bytes32[2]",
"internalType": "bytes32[2]"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "dumpster",
Expand Down Expand Up @@ -1058,6 +1097,25 @@
],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "testP256Verify",
"inputs": [
{
"name": "inputData",
"type": "bytes",
"internalType": "bytes"
}
],
"outputs": [
{
"name": "",
"type": "bool",
"internalType": "bool"
}
],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "testRETURNDATACOPY",
Expand Down
2 changes: 1 addition & 1 deletion bindings/tester/LoadTester.bin

Large diffs are not rendered by default.

56 changes: 54 additions & 2 deletions bindings/tester/loadTester.go

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions bindings/tester/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ func GenerateBlake2FInput() []byte {
return inputData
}

func GenerateP256VerifyInput() []byte {
// Ethereum benchmark input for P256Verify
// https://github.com/ethereum/go-ethereum/pull/30043/files#diff-b8e213cc8b44bc7d5d5e727524d63e19dd0f21312713ce2471948d1f64db212cR404
ethBenchmarkInput := "4cee90eb86eaa050036147a12d49004b6b9c72bd725d39d4785011fe190f0b4da73bd4903f0ce3b639bbbf6e8e80d16931ff4bcf5993d58468e8fb19086e8cac36dbcd03009df8c59286b162af3bd7fcc0450c9aa81be5d10d312af6c66b1d604aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff37618b065f9832de4ca6ca971a7a1adc826d0f7c00181a5fb2ddf79ae00b4e10e"
inputData, err := hex.DecodeString(ethBenchmarkInput)
if err != nil {
panic(err)
}

return inputData
}

func CallPrecompiledContracts(address int, lt *LoadTester, opts *bind.TransactOpts, iterations uint64, privateKey *ecdsa.PrivateKey) (*ethtypes.Transaction, error) {
var inputData []byte

Expand Down Expand Up @@ -202,6 +214,10 @@ func CallPrecompiledContracts(address int, lt *LoadTester, opts *bind.TransactOp
log.Trace().Str("method", "TestBlake2f").Msg("Executing contract method")
inputData = GenerateECPairingInput()
return lt.TestBlake2f(opts, inputData)
case 100:
log.Trace().Str("method", "TestP256Verify").Msg("Executing contract method")
inputData = GenerateP256VerifyInput()
return lt.TestP256Verify(opts, inputData)
}

return nil, fmt.Errorf("unrecognized precompiled address %d", address)
Expand All @@ -218,6 +234,7 @@ func GetRandomPrecompiledContractAddress() int {
// 7, // NOTE: ecMul requires a lot of gas and buggy
8,
9,
// 100, // P256Verify haven't been implemented on Ethereum yet
}

return codes[rand.Intn(len(codes))]
Expand Down
4 changes: 2 additions & 2 deletions cmd/loadtest/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,9 @@ func mainLoop(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) erro
case loadTestModeIncrement:
startReq, endReq, tErr = loadTestIncrement(ctx, c, myNonceValue, ltContract)
case loadTestModeRandomPrecompiledContract:
startReq, endReq, tErr = loadTestCallPrecompiledContract(ctx, c, myNonceValue, ltContract, true)
case loadTestModeSpecificPrecompiledContract:
startReq, endReq, tErr = loadTestCallPrecompiledContract(ctx, c, myNonceValue, ltContract, false)
case loadTestModeSpecificPrecompiledContract:
startReq, endReq, tErr = loadTestCallPrecompiledContract(ctx, c, myNonceValue, ltContract, true)
case loadTestModeRecall:
startReq, endReq, tErr = loadTestRecall(ctx, c, myNonceValue, recallTransactions[int(currentNonce)%len(recallTransactions)])
case loadTestModeRPC:
Expand Down
60 changes: 38 additions & 22 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,33 @@ var (

type (
monitorStatus struct {
TopDisplayedBlock *big.Int
UpperBlock *big.Int
LowerBlock *big.Int
ChainID *big.Int
ForkID uint64
HeadBlock *big.Int
PeerCount uint64
GasPrice *big.Int
TxPoolStatus txPoolStatus
ZkEVMBatches zkEVMBatches
SelectedBlock rpctypes.PolyBlock
SelectedTransaction rpctypes.PolyTransaction
BlockCache *lru.Cache `json:"-"`
BlocksLock sync.RWMutex `json:"-"`
TopDisplayedBlock *big.Int
UpperBlock *big.Int
LowerBlock *big.Int
ChainID *big.Int
ForkID uint64
HeadBlock *big.Int
PeerCount uint64
GasPrice *big.Int
TxPoolStatus txPoolStatus
ZkEVMBatches zkEVMBatches
SelectedBlock rpctypes.PolyBlock
SelectedTransaction rpctypes.PolyTransaction
BlockCache *lru.Cache `json:"-"`
BlocksLock sync.RWMutex `json:"-"`
RollupAddress string
RollupManagerAddress string
}
chainState struct {
HeadBlock uint64
ChainID *big.Int
PeerCount uint64
GasPrice *big.Int
TxPoolStatus txPoolStatus
ZkEVMBatches zkEVMBatches
ForkID uint64
HeadBlock uint64
ChainID *big.Int
PeerCount uint64
GasPrice *big.Int
TxPoolStatus txPoolStatus
ZkEVMBatches zkEVMBatches
ForkID uint64
RollupAddress string
RollupManagerAddress string
}
txPoolStatus struct {
pending uint64
Expand Down Expand Up @@ -241,6 +245,16 @@ func getChainState(ctx context.Context, ec *ethclient.Client) (*chainState, erro
log.Debug().Err(err).Msg("Unable to get fork id")
}

cs.RollupAddress, err = util.GetRollupAddress(ec.Client())
if err != nil {
log.Debug().Err(err).Msg("Unable to get rollup address")
}

cs.RollupManagerAddress, err = util.GetRollupManagerAddress(ec.Client())
if err != nil {
log.Debug().Err(err).Msg("Unable to get rollup manager address")
}

return cs, nil

}
Expand Down Expand Up @@ -284,6 +298,8 @@ func fetchCurrentBlockData(ctx context.Context, ec *ethclient.Client, ms *monito
ms.TxPoolStatus = cs.TxPoolStatus
ms.ZkEVMBatches = cs.ZkEVMBatches
ms.ForkID = cs.ForkID
ms.RollupAddress = cs.RollupAddress
ms.RollupManagerAddress = cs.RollupManagerAddress

return
}
Expand Down Expand Up @@ -608,7 +624,7 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
if zkEVMBatchesSupported {
skeleton.ZkEVM.Text = ui.GetZkEVMText(skeleton.ZkEVM, ms.ZkEVMBatches.trusted, ms.ZkEVMBatches.virtual, ms.ZkEVMBatches.verified)

skeleton.Rollup.Text = ui.GetRollupText(skeleton.Rollup, ms.ForkID)
skeleton.Rollup.Text = ui.GetRollupText(skeleton.Rollup, ms.ForkID, ms.RollupAddress, ms.RollupManagerAddress)
}

skeleton.TxPerBlockChart.Data = metrics.GetTxsPerBlock(renderedBlocks)
Expand Down
7 changes: 5 additions & 2 deletions cmd/monitor/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ func GetZkEVMText(widget *widgets.Paragraph, trustedBatchesCount, virtualBatches
return formatParagraph(widget, []string{trustedBatches, virtualBatches, verifiedBatches})
}

func GetRollupText(widget *widgets.Paragraph, forkID uint64) string {
func GetRollupText(widget *widgets.Paragraph, forkID uint64, rollupAddress string, rollupManagerAddress string) string {
forkIDString := fmt.Sprintf("ForkID: %d", forkID)
return formatParagraph(widget, []string{forkIDString})
rollupAddressString := fmt.Sprintf("RollupAddress: %s", rollupAddress)
rollupManagerAddressString := fmt.Sprintf("RollupManagerAddress: %s", rollupManagerAddress)

return formatParagraph(widget, []string{forkIDString, rollupAddressString, rollupManagerAddressString})
}

func formatParagraph(widget *widgets.Paragraph, content []string) string {
Expand Down
53 changes: 41 additions & 12 deletions contracts/src/tester/LoadTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -911,22 +911,51 @@ contract LoadTester {
}
}

// https://eips.ethereum.org/EIPS/eip-152#example-usage-in-solidity
function testBlake2f(bytes memory inputData) public returns (bytes memory result) {
address BLAKE_2F_PRECOMPILED_CONTRACT = 0x0000000000000000000000000000000000000008;
bytes32[2] memory h;
h[0] = hex"48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5";
h[1] = hex"d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b";

bytes32[4] memory m;
m[0] = hex"6162630000000000000000000000000000000000000000000000000000000000";
m[1] = hex"0000000000000000000000000000000000000000000000000000000000000000";
m[2] = hex"0000000000000000000000000000000000000000000000000000000000000000";
m[3] = hex"0000000000000000000000000000000000000000000000000000000000000000";

bytes8[2] memory t;
t[0] = hex"0300000000000000";
t[1] = hex"0000000000000000";

bytes32[2] memory result = F(12, h, m, t, true);
bytes32[2] memory expected;
expected[0] = hex"ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1";
expected[1] = hex"7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
require(result[0] == expected[0], "TestBlake2f - First hash doesn't match");
require(result[1] == expected[1], "TestBlake2f - Second hash doesn't match");
}

function F(uint32 rounds, bytes32[2] memory h, bytes32[4] memory m, bytes8[2] memory t, bool f) public view returns (bytes32[2] memory) {
address BLAKE_2F_PRECOMPILED_CONTRACT = 0x0000000000000000000000000000000000000009;

bytes32[2] memory output;
bytes memory args = abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f);
assembly {
let success := call(
gas(),
BLAKE_2F_PRECOMPILED_CONTRACT,
0, // no ether transfer
add(inputData, 32), // inputData offset
mload(inputData), // inputData length
result, // output area
64 // output area size (2 * 32 bytes)
)
if iszero(success) {
revert(0, 0)
if iszero(staticcall(not(0), BLAKE_2F_PRECOMPILED_CONTRACT, add(args, 32), 0xd5, output, 0x40)) {
revert(0, 0)
}
}
return output;
}

// RIP-7212 Precompile for secp256r1 Curve Support
// https://github.com/ethereum/RIPs/blob/master/RIPS/rip-7212.md
// Ref: https://github.com/daimo-eth/p256-verifier/blob/607d3ec8377a3f59d65eca60d87dee8485d2ebcc/src/P256.sol
function testP256Verify(bytes memory inputData) public returns (bool) {
address P256VERIFY_PRECOMPILED_CONTRACT = 0x0000000000000000000000000000000000000100;
(bool success, bytes memory ret) = P256VERIFY_PRECOMPILED_CONTRACT.staticcall(inputData);
assert(success); // never reverts, always returns 0 or 1

return abi.decode(ret, (uint256)) == 1;
}
}
36 changes: 18 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.60.1
github.com/rs/zerolog v1.33.0
github.com/schollz/progressbar/v3 v3.17.0
github.com/schollz/progressbar/v3 v3.17.1
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
Expand All @@ -30,12 +30,12 @@ require (
github.com/tyler-smith/go-bip32 v1.0.0
github.com/tyler-smith/go-bip39 v1.1.0
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/crypto v0.28.0
golang.org/x/crypto v0.29.0
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
golang.org/x/text v0.19.0
golang.org/x/time v0.7.0
google.golang.org/api v0.204.0
google.golang.org/protobuf v1.35.1
golang.org/x/text v0.20.0
golang.org/x/time v0.8.0
google.golang.org/api v0.206.0
google.golang.org/protobuf v1.35.2
)

require github.com/alecthomas/participle/v2 v2.1.1
Expand Down Expand Up @@ -75,7 +75,7 @@ require (
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
Expand Down Expand Up @@ -130,14 +130,14 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
google.golang.org/genproto v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
google.golang.org/genproto v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/grpc v1.67.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -154,10 +154,10 @@ require (
)

require (
cloud.google.com/go/auth v0.10.0 // indirect
cloud.google.com/go/auth v0.10.2 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect
cloud.google.com/go/iam v1.2.1 // indirect
cloud.google.com/go/longrunning v0.6.1 // indirect
cloud.google.com/go/iam v1.2.2 // indirect
cloud.google.com/go/longrunning v0.6.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
Expand Down
Loading

0 comments on commit 087615d

Please sign in to comment.