Skip to content

Commit f77444a

Browse files
authored
feat(loadtest): add RIP-7212 P256Verify precompile (#434)
* add 7212 p256verify loadtest * update loadtest contract * use benchmark input from https://github.com/ethereum/go-ethereum/pull/30043/files#diff-b8e213cc8b44bc7d5d5e727524d63e19dd0f21312713ce2471948d1f64db212cR404 * delete unused comment * add source * disable P256Verify in GetRandomPrecompiledContractAddress
1 parent 3fee0b7 commit f77444a

File tree

5 files changed

+71
-3
lines changed

5 files changed

+71
-3
lines changed

bindings/tester/LoadTester.abi

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,25 @@
10971097
],
10981098
"stateMutability": "nonpayable"
10991099
},
1100+
{
1101+
"type": "function",
1102+
"name": "testP256Verify",
1103+
"inputs": [
1104+
{
1105+
"name": "inputData",
1106+
"type": "bytes",
1107+
"internalType": "bytes"
1108+
}
1109+
],
1110+
"outputs": [
1111+
{
1112+
"name": "",
1113+
"type": "bool",
1114+
"internalType": "bool"
1115+
}
1116+
],
1117+
"stateMutability": "nonpayable"
1118+
},
11001119
{
11011120
"type": "function",
11021121
"name": "testRETURNDATACOPY",

bindings/tester/LoadTester.bin

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

bindings/tester/loadTester.go

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/tester/precompiles.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ func GenerateBlake2FInput() []byte {
162162
return inputData
163163
}
164164

165+
func GenerateP256VerifyInput() []byte {
166+
// Ethereum benchmark input for P256Verify
167+
// https://github.com/ethereum/go-ethereum/pull/30043/files#diff-b8e213cc8b44bc7d5d5e727524d63e19dd0f21312713ce2471948d1f64db212cR404
168+
ethBenchmarkInput := "4cee90eb86eaa050036147a12d49004b6b9c72bd725d39d4785011fe190f0b4da73bd4903f0ce3b639bbbf6e8e80d16931ff4bcf5993d58468e8fb19086e8cac36dbcd03009df8c59286b162af3bd7fcc0450c9aa81be5d10d312af6c66b1d604aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff37618b065f9832de4ca6ca971a7a1adc826d0f7c00181a5fb2ddf79ae00b4e10e"
169+
inputData, err := hex.DecodeString(ethBenchmarkInput)
170+
if err != nil {
171+
panic(err)
172+
}
173+
174+
return inputData
175+
}
176+
165177
func CallPrecompiledContracts(address int, lt *LoadTester, opts *bind.TransactOpts, iterations uint64, privateKey *ecdsa.PrivateKey) (*ethtypes.Transaction, error) {
166178
var inputData []byte
167179

@@ -202,6 +214,10 @@ func CallPrecompiledContracts(address int, lt *LoadTester, opts *bind.TransactOp
202214
log.Trace().Str("method", "TestBlake2f").Msg("Executing contract method")
203215
inputData = GenerateECPairingInput()
204216
return lt.TestBlake2f(opts, inputData)
217+
case 100:
218+
log.Trace().Str("method", "TestP256Verify").Msg("Executing contract method")
219+
inputData = GenerateP256VerifyInput()
220+
return lt.TestP256Verify(opts, inputData)
205221
}
206222

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

223240
return codes[rand.Intn(len(codes))]

contracts/src/tester/LoadTester.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,4 +947,15 @@ contract LoadTester {
947947
}
948948
return output;
949949
}
950+
951+
// RIP-7212 Precompile for secp256r1 Curve Support
952+
// https://github.com/ethereum/RIPs/blob/master/RIPS/rip-7212.md
953+
// Ref: https://github.com/daimo-eth/p256-verifier/blob/607d3ec8377a3f59d65eca60d87dee8485d2ebcc/src/P256.sol
954+
function testP256Verify(bytes memory inputData) public returns (bool) {
955+
address P256VERIFY_PRECOMPILED_CONTRACT = 0x0000000000000000000000000000000000000100;
956+
(bool success, bytes memory ret) = P256VERIFY_PRECOMPILED_CONTRACT.staticcall(inputData);
957+
assert(success); // never reverts, always returns 0 or 1
958+
959+
return abi.decode(ret, (uint256)) == 1;
960+
}
950961
}

0 commit comments

Comments
 (0)