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

TRC-60:Precompiled contract function for multi-signature verification #60

Closed
Sh11thead opened this issue Sep 20, 2019 · 1 comment
Closed

Comments

@Sh11thead
Copy link
Contributor

Sh11thead commented Sep 20, 2019

tip: 60
title: TRC-60:Precompiled contract function for multi-signature verification
author: Sh11thead <ksl2945@gmail.com>
discussions to: https://github.com/tronprotocol/TIPs/issues/60
category: TRC
status: accepted
created: 2019-09-20

Simple Summary

This doc describes a native TVM function which is used to validate multi-signature for a provided account.

Abstract

TRON provided multiple signature functions allowing for permission grading, and each permission can correspond to multiple private keys. But in TVM, currently we only have ecrecover() function to verify single-signed message.But multiple-signed message can not be verified in TVM ,to solve this case, we need a new function to support multiple-sign verification .

Motivation

Developer hope to validate multi-sign for account with specific permission in smart contracts.

Specification

Add a new function named validatemultisign in solidity compiler .

This function could takes 4 parameters:

validatemultisign(
address accountAddress, // account address  
uint256 permissionId, //permissionId for account
bytes32 content, //content for verifying
bytes[] signatures//signatures to be verified
)

Pay special attention to the parameter signatures,
The specific signature method is implemented in java code as follows:

//parameters address,permissionId ,hash
byte[] address  = address
int permissionId = permissionId ;
byte[] hash= originData;

//merge
byte[] merged =  ByteUtil.merge(address,ByteArray.fromInt(permissionId),data);
//get the content to sign
byte[] toSign = Sha256Hash.hash(merged);


//sign content
List<Object> signs = new ArrayList<>();
signs.add(Hex.toHexString(key1.sign(toSign).toByteArray()));
signs.add(Hex.toHexString(key2.sign(toSign).toByteArray()));

This function will call to a specific address (for example,0x000000000000000000000000000000000000000a) which will executed precompiledContracts in TVM to validate multi-sign.Since in TRON, one transaction allow max up to 5 different account to sign,the parameter signatures is allow max up to 5.

In TVM , we could reuse ECKey.ECDSASignature.fromComponents(r, s, v)method,which is already used by ecrecover() to recover address for signature.

Energy cost

energy charge for the execution cost 1500 per signature

Rationale

This function allows validating multi-sign in TVM could improve smart contract access to TRON blockchain which is good for both DApp developer and users.

Backwards Compatibility

Adding a new precompiledContract cause no backwards compatibility concerns.

Test Cases

1.Verifying both correct and incorrect signatures in smart contract.
2.Verifying duplicate signatures.
3.Verifying more than 5 signatures.

@Sh11thead Sh11thead changed the title TRC:Precompiled contract function for multi-signature validation TRC-60:Precompiled contract function for multi-signature validation Sep 20, 2019
@Sh11thead Sh11thead changed the title TRC-60:Precompiled contract function for multi-signature validation TRC-60:Precompiled contract function for multi-signature verification Sep 23, 2019
@hamid22amiri
Copy link

//sign content
List signs = new ArrayList<>();
signs.add(Hex.toHexString(key1.sign(toSign).toByteArray()));
signs.add(Hex.toHexString(key2.sign(toSign).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants