Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add RIP-7212 P256Verify loadtest #434

Merged
merged 7 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bindings/tester/LoadTester.abi
Original file line number Diff line number Diff line change
Expand Up @@ -1097,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.

25 changes: 23 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:
leovct marked this conversation as resolved.
Show resolved Hide resolved
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
11 changes: 11 additions & 0 deletions contracts/src/tester/LoadTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -947,4 +947,15 @@ contract LoadTester {
}
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;
}
}
Loading