-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add evm EventWitness system contract (#1396)
* ttt * add evm EventWitness system contract * add license * use merkle leaf hash scheme in EventWitness.sol * update solc output * expose jsonrpc api
- Loading branch information
Showing
11 changed files
with
203 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"abi": [ | ||
{ | ||
"type": "function", | ||
"name": "witness", | ||
"inputs": [ | ||
{ | ||
"internalType": "bytes", | ||
"name": "evt", | ||
"type": "bytes" | ||
} | ||
], | ||
"outputs": [], | ||
"stateMutability": "nonpayable" | ||
}, | ||
{ | ||
"type": "event", | ||
"name": "EventWitnessed", | ||
"inputs": [ | ||
{ | ||
"name": "sender", | ||
"type": "address", | ||
"indexed": true | ||
}, | ||
{ | ||
"name": "hash", | ||
"type": "bytes32", | ||
"indexed": true | ||
} | ||
], | ||
"anonymous": false | ||
} | ||
], | ||
"bytecode": { | ||
"object": "0x608060405234801561001057600080fd5b50610232806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c806301520d3714610030575b600080fd5b61004361003e3660046100f8565b610045565b005b60405160009061005f90829033908690869060200161016a565b6040516020818303038152906040529050600060028260405161008291906101a8565b602060405180830381855afa15801561009f573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906100c291906101e3565b604051909150819033907f79898126427c5e89fd1ee4f972f2a7555a74aa1248b7a0e1e50b8e0180be00bd90600090a350505050565b6000806020838503121561010b57600080fd5b823567ffffffffffffffff8082111561012357600080fd5b818501915085601f83011261013757600080fd5b81358181111561014657600080fd5b86602082850101111561015857600080fd5b60209290920196919550909350505050565b6001600160f81b031985168152606084901b6bffffffffffffffffffffffff1916600182015281836015830137600091016015019081529392505050565b6000825160005b818110156101c957602081860181015185830152016101af565b818111156101d8576000828501525b509190910192915050565b6000602082840312156101f557600080fd5b505191905056fea2646970667358221220261559f20ea5fce40c92f04e51feb223d0c0b5ed0f4f82e98eda6922b001bb3f64736f6c634300080a0033", | ||
"sourceMap": "64:460:1:-:0;;;;;;;;;;;;;;;;;;;", | ||
"linkReferences": {} | ||
}, | ||
"deployed_bytecode": { | ||
"object": "0x608060405234801561001057600080fd5b506004361061002b5760003560e01c806301520d3714610030575b600080fd5b61004361003e3660046100f8565b610045565b005b60405160009061005f90829033908690869060200161016a565b6040516020818303038152906040529050600060028260405161008291906101a8565b602060405180830381855afa15801561009f573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906100c291906101e3565b604051909150819033907f79898126427c5e89fd1ee4f972f2a7555a74aa1248b7a0e1e50b8e0180be00bd90600090a350505050565b6000806020838503121561010b57600080fd5b823567ffffffffffffffff8082111561012357600080fd5b818501915085601f83011261013757600080fd5b81358181111561014657600080fd5b86602082850101111561015857600080fd5b60209290920196919550909350505050565b6001600160f81b031985168152606084901b6bffffffffffffffffffffffff1916600182015281836015830137600091016015019081529392505050565b6000825160005b818110156101c957602081860181015185830152016101af565b818111156101d8576000828501525b509190910192915050565b6000602082840312156101f557600080fd5b505191905056fea2646970667358221220261559f20ea5fce40c92f04e51feb223d0c0b5ed0f4f82e98eda6922b001bb3f64736f6c634300080a0033", | ||
"sourceMap": "64:460:1:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;165:357;;;;;;:::i;:::-;;:::i;:::-;;;360:44;;333:24;;360:44;;333:24;;388:10;;400:3;;;;360:44;;;:::i;:::-;;;;;;;;;;;;;333:71;;414:22;439:19;446:11;439:19;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;473:42;;414:44;;-1:-1:-1;414:44:1;;488:10;;473:42;;;;;211:311;;165:357;;:::o;14:591:4:-;84:6;92;145:2;133:9;124:7;120:23;116:32;113:52;;;161:1;158;151:12;113:52;201:9;188:23;230:18;271:2;263:6;260:14;257:34;;;287:1;284;277:12;257:34;325:6;314:9;310:22;300:32;;370:7;363:4;359:2;355:13;351:27;341:55;;392:1;389;382:12;341:55;432:2;419:16;458:2;450:6;447:14;444:34;;;474:1;471;464:12;444:34;519:7;514:2;505:6;501:2;497:15;493:24;490:37;487:57;;;540:1;537;530:12;487:57;571:2;563:11;;;;;593:6;;-1:-1:-1;14:591:4;;-1:-1:-1;;;;14:591:4:o;610:474::-;-1:-1:-1;;;;;;833:26:4;;821:39;;897:2;893:15;;;-1:-1:-1;;889:53:4;885:1;876:11;;869:74;987:6;979;974:2;965:12;;952:42;803:3;1017:16;;1035:2;1013:25;1047:13;;;1013:25;610:474;-1:-1:-1;;;610:474:4:o;1089:426::-;1218:3;1256:6;1250:13;1281:1;1291:129;1305:6;1302:1;1299:13;1291:129;;;1403:4;1387:14;;;1383:25;;1377:32;1364:11;;;1357:53;1320:12;1291:129;;;1438:6;1435:1;1432:13;1429:48;;;1473:1;1464:6;1459:3;1455:16;1448:27;1429:48;-1:-1:-1;1493:16:4;;;;;1089:426;-1:-1:-1;;1089:426:4:o;1520:184::-;1590:6;1643:2;1631:9;1622:7;1618:23;1614:32;1611:52;;;1659:1;1656;1649:12;1611:52;-1:-1:-1;1682:16:4;;1520:184;-1:-1:-1;1520:184:4:o", | ||
"linkReferences": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.10; | ||
|
||
contract EventWitness { | ||
event EventWitnessed(address indexed sender, bytes32 indexed hash); | ||
|
||
function witness(bytes calldata evt) external { | ||
// ugly hack: append byte1(0) since we are hashing a merkle leaf. see: ontology/merkle/merkle_hasher.go | ||
bytes memory leafData = abi.encodePacked(bytes1(0), msg.sender, evt); | ||
bytes32 merkleLeafHash = sha256(leafData); | ||
emit EventWitnessed(msg.sender, merkleLeafHash); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (C) 2021 The Ontology Authors | ||
// Copyright 2016 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package witness | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ontio/ontology/common" | ||
"github.com/ontio/ontology/core/types" | ||
) | ||
|
||
const WitnessGlobalParamKey = "evm.witness" // value is the deployed hex addresss(evm form) of witness contract. | ||
|
||
var EventWitnessedEventID = crypto.Keccak256Hash([]byte("EventWitnessed(address,bytes32)")) | ||
|
||
type EventWitnessEvent struct { | ||
Sender common.Address | ||
Hash common.Uint256 | ||
} | ||
|
||
func DecodeEventWitness(log *types.StorageLog) (*EventWitnessEvent, error) { | ||
if len(log.Topics) != 3 { | ||
return nil, errors.New("witness: wrong topic number") | ||
} | ||
if log.Topics[0] != EventWitnessedEventID { | ||
return nil, errors.New("witness: wrong event id") | ||
} | ||
|
||
sender, err := common.AddressParseFromBytes(log.Topics[1][12:]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &EventWitnessEvent{ | ||
Sender: sender, | ||
Hash: common.Uint256(log.Topics[2]), | ||
}, nil | ||
} |