Skip to content

Commit

Permalink
Merge pull request #1743 from multiversx/crypto-opcodes
Browse files Browse the repository at this point in the history
impl new crypto opcodes
  • Loading branch information
andrei-marinica authored Sep 2, 2024
2 parents ddc233b + 0b43a3b commit c1a459a
Show file tree
Hide file tree
Showing 20 changed files with 757 additions and 18 deletions.
9 changes: 9 additions & 0 deletions contracts/feature-tests/basic-features/sc-config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[settings]
main = "basic-features"

[contracts.basic-features]

[contracts.basic-features.profile]
overflow-checks = true # needed for overflow tests

Expand All @@ -9,6 +11,13 @@ add-unlabelled = false
add-endpoints = ["init", "load_bytes", "store_bytes"]
kill_legacy_callback = true

[contracts.basic-features-crypto]
ei = "1.4"
add-unlabelled = false
add-endpoints = ["init"]
add-labels = ["crypto-ei-1.4"]
kill_legacy_callback = true

[[proxy]]
path = "src/basic_features_proxy.rs"
add-unlabelled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
{
"step": "scCall",
"id": "3",
"id": "verify_bls_signature - Ok",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features",
Expand All @@ -33,14 +33,36 @@
"gasPrice": "0"
},
"expect": {
"out": [
"0x01"
],
"out": [],
"status": "",
"logs": "*",
"gas": "*",
"refund": "*"
}
},
{
"step": "scCall",
"id": "verify_bls_signature - Fail",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features",
"function": "verify_bls_signature",
"arguments": [
"0xb5823f6e564251cc03ce7bad3da83e72576e92795d3500bba1acb30ec9a94dce87bb8aa794d67b2d61d15c33f28f6c0c23ba1dfcbf21e8f8b46286ff871afabac925303ddcaddce6254fcff6d3155797db40b3d3b5865e8fc0bd770b3d79b381",
"0x6d65737361676520746f206265207369676e6564",
"0x0032a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "10",
"message": "str:err blsSignatureDeserialize 0032a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696",
"logs": "*",
"gas": "*",
"refund": "*"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"name": "crypto",
"comment": "does not currently work with scenarios-rs, because verify_bls function is not yet mocked",
"gasSchedule": "v3",
"steps": [
{
"step": "setState",
"accounts": {
"sc:basic-features-crypto": {
"nonce": "0",
"balance": "0",
"code": "mxsc:../output/basic-features-crypto.mxsc.json"
},
"address:an_account": {
"nonce": "0",
"balance": "0"
}
}
},
{
"step": "scCall",
"id": "bls multi - ok",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features-crypto",
"function": "verify_bls_aggregated_signature",
"arguments": [
[
"nested:0x95f1d96b582f35294eb7dd4589b158e108e1d94cd0dd71ef16140e9b37126ec52dac6f57397f1e041acd7bb77df1d214f9f894e3b7fbf7abeaabc9fab8ff5c2ef05f9841322f301fdb900ac59479c334ac76a2d4ff992cd49bc9b530c25ee293",
"nested:0x97aa2862418eb4ea74fddcb511eef9b771e07ff901e7e6abb35847a4bb81e58f189fc9bce4186c6129014fb43002300e959702ef4b9d0c32ebe4d795457095d65b5414efb36edbb8dc66d84a445a92472d4a31cedd4700d5ebb885eb11d3430b",
"nested:0x37b73265936a2aaafe652a4dd451a1851c2dbbb32208604787479b31033e2a354615562ea2a5488f9134843362477a139050a0e798dd5ce0f01b35b8d473454ae99633aadde9237f84c87eb366144cca4de3d2cc6acc35e522a3294bf1186800",
"nested:0xf46c10d114dcd3019dd4bcd4152fda678c56144eb177c67a6411213b86e206e4e56a9aad1eab0313b13031fda046d715ec4a02612b083dfae0d82a23b643e1a89756c0df3d65c27e87a9c1289628d1a8404f0668a3d87c7451ba1c78fc452693",
"nested:0xaa0a97917df9240c537c89e873d7baa5ce1796e8fedfb23cf682b80fa19b8baae35af3754f9b8149985cb2a1fbda0f02c2942d2c99d9af556c9a5e90b8170e6a96379a45dd69351abfb814a16b5665abb7ddb8b096ee9f273de81845cda9728a"
],
"str:message0",
"0xae12858363e8caa5b398d3febdd7bc01bc2fae1fef8f486ff4d84a5f3342f2d38085904eb10b73c0879a45d23585ce8f"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "",
"logs": "*",
"gas": "*",
"refund": "*"
}
},
{
"step": "scCall",
"id": "bls multi - fail",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features-crypto",
"function": "verify_bls_aggregated_signature",
"arguments": [
[
"nested:0x95f1d96b582f35294eb7dd4589b158e108e1d94cd0dd71ef16140e9b37126ec52dac6f57397f1e041acd7bb77df1d214f9f894e3b7fbf7abeaabc9fab8ff5c2ef05f9841322f301fdb900ac59479c334ac76a2d4ff992cd49bc9b530c25ee293",
"nested:0x97aa2862418eb4ea74fddcb511eef9b771e07ff901e7e6abb35847a4bb81e58f189fc9bce4186c6129014fb43002300e959702ef4b9d0c32ebe4d795457095d65b5414efb36edbb8dc66d84a445a92472d4a31cedd4700d5ebb885eb11d3430b",
"nested:0x37b73265936a2aaafe652a4dd451a1851c2dbbb32208604787479b31033e2a354615562ea2a5488f9134843362477a139050a0e798dd5ce0f01b35b8d473454ae99633aadde9237f84c87eb366144cca4de3d2cc6acc35e522a3294bf1186800",
"nested:0xf46c10d114dcd3019dd4bcd4152fda678c56144eb177c67a6411213b86e206e4e56a9aad1eab0313b13031fda046d715ec4a02612b083dfae0d82a23b643e1a89756c0df3d65c27e87a9c1289628d1a8404f0668a3d87c7451ba1c78fc452693",
"nested:0xaa0a97917df9240c537c89e873d7baa5ce1796e8fedfb23cf682b80fa19b8baae35af3754f9b8149985cb2a1fbda0f02c2942d2c99d9af556c9a5e90b8170e6a96379a45dd69351abfb814a16b5665abb7ddb8b096ee9f273de81845cda9728a"
],
"str:message0",
"0x0012858363e8caa5b398d3febdd7bc01bc2fae1fef8f486ff4d84a5f3342f2d38085904eb10b73c0879a45d23585ce8f"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "10",
"message": "str:err blsSignatureDeserialize 0012858363e8caa5b398d3febdd7bc01bc2fae1fef8f486ff4d84a5f3342f2d38085904eb10b73c0879a45d23585ce8f",
"logs": "*",
"gas": "*",
"refund": "*"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "crypto",
"comment": "does not currently work with scenarios-rs, because function is not yet mocked",
"gasSchedule": "v3",
"steps": [
{
"step": "setState",
"accounts": {
"sc:basic-features-crypto": {
"nonce": "0",
"balance": "0",
"code": "mxsc:../output/basic-features-crypto.mxsc.json"
},
"address:an_account": {
"nonce": "0",
"balance": "0"
}
}
},
{
"step": "scCall",
"id": "verify_bls_signature_share - Ok",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features-crypto",
"function": "verify_bls_signature_share",
"arguments": [
"0x3e886a4c6e109a151f4105aee65a5192d150ef1fa68d3cd76964a0b086006dbe4324c989deb0e4416c6d6706db1b1910eb2732f08842fb4886067b9ed191109ac2188d76002d2e11da80a3f0ea89fee6b59c834cc478a6bd49cb8a193b1abb16",
"0xe96bd0f36b70c5ccc0c4396343bd7d8255b8a526c55fa1e218511fafe6539b8e",
"0x04725db195e37aa237cdbbda76270d4a229b6e7a3651104dc58c4349c0388e8546976fe54a04240530b99064e434c90f"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "",
"logs": "*",
"gas": "*",
"refund": "*"
}
},
{
"step": "scCall",
"id": "verify_bls_signature_share - Fail",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features-crypto",
"function": "verify_bls_signature_share",
"arguments": [
"0x3e886a4c6e109a151f4105aee65a5192d150ef1fa68d3cd76964a0b086006dbe4324c989deb0e4416c6d6706db1b1910eb2732f08842fb4886067b9ed191109ac2188d76002d2e11da80a3f0ea89fee6b59c834cc478a6bd49cb8a193b1abb16",
"0xe96bd0f36b70c5ccc0c4396343bd7d8255b8a526c55fa1e218511fafe6539b8e",
"0xff725db195e37aa237cdbbda76270d4a229b6e7a3651104dc58c4349c0388e8546976fe54a04240530b99064e434c90f"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "10",
"message": "str:err blsSignatureDeserialize ff725db195e37aa237cdbbda76270d4a229b6e7a3651104dc58c4349c0388e8546976fe54a04240530b99064e434c90f",
"logs": "*",
"gas": "*",
"refund": "*"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "crypto",
"gasSchedule": "v3",
"steps": [
{
"step": "setState",
"accounts": {
"sc:basic-features-crypto": {
"nonce": "0",
"balance": "0",
"code": "mxsc:../output/basic-features-crypto.mxsc.json"
},
"address:an_account": {
"nonce": "0",
"balance": "0"
}
}
},
{
"step": "scCall",
"id": "secp256r1 - ok",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features-crypto",
"function": "verify_secp256r1_signature",
"arguments": [
"0x02bc52274edebbef8878eacc4d1e0ed4fb213e5b0737389701ae8d59c403325720",
"0xbf9facf48b2219db73b50c7ff59ceef2ada56632c71afc555d6bb4072d7634d1d9353acd53517ffb9a06935a89a6454fcaa40c69becf9f8029a271fd252ea55307d00d6e97a30719d48d6b7f993af24e9c54381cba02a113238eaee9d741cababeb21aaf",
"0xc7877497444274267a4ea6f42deefde23a12e44f1ec1b437018e5c0e2834ce376dec1b81ebeacf5fbc6882e69af7cafad47bbb96cfb09e8d77d12afff7543052"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "",
"logs": "*",
"gas": "*",
"refund": "*"
}
},
{
"step": "scCall",
"id": "secp256r1 - fail",
"tx": {
"from": "address:an_account",
"to": "sc:basic-features-crypto",
"function": "verify_secp256r1_signature",
"arguments": [
"0x02bc52274edebbef8878eacc4d1e0ed4fb213e5b0737389701ae8d59c403325720",
"0xbf9facf48b2219db73b50c7ff59ceef2ada56632c71afc555d6bb4072d7634d1d9353acd53517ffb9a06935a89a6454fcaa40c69becf9f8029a271fd252ea55307d00d6e97a30719d48d6b7f993af24e9c54381cba02a113238eaee9d741cababeb21aaf",
"0x00877497444274267a4ea6f42deefde23a12e44f1ec1b437018e5c0e2834ce376dec1b81ebeacf5fbc6882e69af7cafad47bbb96cfb09e8d77d12afff7543052"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "10",
"message": "str:signature verification failed",
"logs": "*",
"gas": "*",
"refund": "*"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"arguments": [
"23,000000000"
],
"gasLimit": "9,000,000",
"gasLimit": "25,000,000",
"gasPrice": "0"
},
"expect": {
Expand Down Expand Up @@ -107,4 +107,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@
}
}
]
}
}
37 changes: 36 additions & 1 deletion contracts/feature-tests/basic-features/src/crypto_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait CryptoFeatures {
key: ManagedBuffer,
message: ManagedBuffer,
signature: ManagedBuffer,
) -> bool {
) {
self.crypto().verify_bls(&key, &message, &signature)
}

Expand Down Expand Up @@ -64,4 +64,39 @@ pub trait CryptoFeatures {
fn compute_secp256k1_der_signature(&self, r: ManagedBuffer, s: ManagedBuffer) -> ManagedBuffer {
self.crypto().encode_secp256k1_der_signature(&r, &s)
}

#[endpoint]
#[label("crypto-ei-1.4")]
fn verify_secp256r1_signature(
&self,
key: ManagedBuffer,
message: ManagedBuffer,
signature: ManagedBuffer,
) {
self.crypto().verify_secp256r1(&key, &message, &signature)
}

#[endpoint]
#[label("crypto-ei-1.4")]
fn verify_bls_signature_share(
&self,
key: ManagedBuffer,
message: ManagedBuffer,
signature: ManagedBuffer,
) {
self.crypto()
.verify_bls_signature_share(&key, &message, &signature)
}

#[endpoint]
#[label("crypto-ei-1.4")]
fn verify_bls_aggregated_signature(
&self,
key: ManagedVec<ManagedBuffer>,
message: ManagedBuffer,
signature: ManagedBuffer,
) {
self.crypto()
.verify_bls_aggregated_signature(&key, &message, &signature)
}
}
Loading

0 comments on commit c1a459a

Please sign in to comment.