Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
Signed-off-by: Naohiro Yoshida <[email protected]>
  • Loading branch information
Naohiro Yoshida committed Aug 31, 2023
2 parents 7c61f75 + 601da3d commit c15074e
Show file tree
Hide file tree
Showing 12 changed files with 467 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ibc-parlia-relay
# ibc-parlia-relay

![CI](https://github.com/datachainlab/ibc-parlia-relay/workflows/CI/badge.svg?branch=main)

Expand Down
2 changes: 2 additions & 0 deletions e2e/chains/bsc/docker-compose.simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ services:
- ./scripts:/root/scripts
- ./config:/root/config
- ./init-holders:/root/init-holders
# - ./validators/keystore:/root/validators/keystore
command: /root/scripts/bootstrap.sh

bootstrap-simple2:
Expand All @@ -55,6 +56,7 @@ services:
- ./scripts:/root/scripts
- ./config:/root/config
- ./init-holders:/root/init-holders
# - ./validators/keystore:/root/validators/keystore
command: /root/scripts/bootstrap.sh

bsc-rpc: # This is the bootstrap node
Expand Down
3 changes: 3 additions & 0 deletions e2e/chains/bsc/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ function init_validator() {
node_id=$1
geth --datadir ${workspace}/storage/${node_id} account new --password /dev/null >${workspace}/storage/${node_id}Info
validatorAddr=$(cat ${workspace}/storage/${node_id}Info | grep 'Public address of the key' | awk '{print $6}')
#mkdir -p ${workspace}/storage/${node_id}/keystore
#cp ${workspace}/validators/keystore/${node_id} ${workspace}/storage/${node_id}/keystore/${node_id}
#validatorAddr="0xa7876ea32e7a748c697d01345145485561305b24"
echo "${validatorAddr},${validatorAddr},${validatorAddr},0x0000000010000000" >>${workspace}/genesis/validators.conf
echo ${validatorAddr} >${workspace}/storage/${node_id}/address
}
Expand Down
1 change: 1 addition & 0 deletions e2e/chains/bsc/validators/keystore/bsc-validator1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"a7876ea32e7a748c697d01345145485561305b24","crypto":{"cipher":"aes-128-ctr","ciphertext":"1cfb8bc7a6b6ddf56e54bf8aae6bd88279a64be887596b1e5a33156473062336","cipherparams":{"iv":"84c5d72baf65bf30dc4125e9e4142e67"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"f16e1f5d9821e74f33901deb22b7935621f8346e9d82f7588c1463de2b6b70fb"},"mac":"f498815391cc13b4d0d3026184fecdbf49ddd264eff1aa0f5591822f37feb9cb"},"id":"4980ec3a-6e91-4929-a21d-d3d231453029","version":3}
308 changes: 307 additions & 1 deletion e2e/contracts/contracts/ibc/lightclients/parlia/v1/parlia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1777,4 +1777,310 @@ library IbcLightclientsParliaV1ConsensusState {
}
}
}
//library IbcLightclientsParliaV1ConsensusState
//library IbcLightclientsParliaV1ConsensusState

library IbcLightclientsParliaV1Misbehaviour {


//struct definition
struct Data {
string client_id;
IbcLightclientsParliaV1Header.Data header_1;
IbcLightclientsParliaV1Header.Data header_2;
}

// Decoder section

/**
* @dev The main decoder for memory
* @param bs The bytes array to be decoded
* @return The decoded struct
*/
function decode(bytes memory bs) internal pure returns (Data memory) {
(Data memory x, ) = _decode(32, bs, bs.length);
return x;
}

/**
* @dev The main decoder for storage
* @param self The in-storage struct
* @param bs The bytes array to be decoded
*/
function decode(Data storage self, bytes memory bs) internal {
(Data memory x, ) = _decode(32, bs, bs.length);
store(x, self);
}
// inner decoder

/**
* @dev The decoder for internal usage
* @param p The offset of bytes array to start decode
* @param bs The bytes array to be decoded
* @param sz The number of bytes expected
* @return The decoded struct
* @return The number of bytes decoded
*/
function _decode(uint256 p, bytes memory bs, uint256 sz)
internal
pure
returns (Data memory, uint)
{
Data memory r;
uint256 fieldId;
ProtoBufRuntime.WireType wireType;
uint256 bytesRead;
uint256 offset = p;
uint256 pointer = p;
while (pointer < offset + sz) {
(fieldId, wireType, bytesRead) = ProtoBufRuntime._decode_key(pointer, bs);
pointer += bytesRead;
if (fieldId == 1) {
pointer += _read_client_id(pointer, bs, r);
} else
if (fieldId == 2) {
pointer += _read_header_1(pointer, bs, r);
} else
if (fieldId == 3) {
pointer += _read_header_2(pointer, bs, r);
} else
{
pointer += ProtoBufRuntime._skip_field_decode(wireType, pointer, bs);
}

}
return (r, sz);
}

// field readers

/**
* @dev The decoder for reading a field
* @param p The offset of bytes array to start decode
* @param bs The bytes array to be decoded
* @param r The in-memory struct
* @return The number of bytes decoded
*/
function _read_client_id(
uint256 p,
bytes memory bs,
Data memory r
) internal pure returns (uint) {
(string memory x, uint256 sz) = ProtoBufRuntime._decode_string(p, bs);
r.client_id = x;
return sz;
}

/**
* @dev The decoder for reading a field
* @param p The offset of bytes array to start decode
* @param bs The bytes array to be decoded
* @param r The in-memory struct
* @return The number of bytes decoded
*/
function _read_header_1(
uint256 p,
bytes memory bs,
Data memory r
) internal pure returns (uint) {
(IbcLightclientsParliaV1Header.Data memory x, uint256 sz) = _decode_IbcLightclientsParliaV1Header(p, bs);
r.header_1 = x;
return sz;
}

/**
* @dev The decoder for reading a field
* @param p The offset of bytes array to start decode
* @param bs The bytes array to be decoded
* @param r The in-memory struct
* @return The number of bytes decoded
*/
function _read_header_2(
uint256 p,
bytes memory bs,
Data memory r
) internal pure returns (uint) {
(IbcLightclientsParliaV1Header.Data memory x, uint256 sz) = _decode_IbcLightclientsParliaV1Header(p, bs);
r.header_2 = x;
return sz;
}

// struct decoder
/**
* @dev The decoder for reading a inner struct field
* @param p The offset of bytes array to start decode
* @param bs The bytes array to be decoded
* @return The decoded inner-struct
* @return The number of bytes used to decode
*/
function _decode_IbcLightclientsParliaV1Header(uint256 p, bytes memory bs)
internal
pure
returns (IbcLightclientsParliaV1Header.Data memory, uint)
{
uint256 pointer = p;
(uint256 sz, uint256 bytesRead) = ProtoBufRuntime._decode_varint(pointer, bs);
pointer += bytesRead;
(IbcLightclientsParliaV1Header.Data memory r, ) = IbcLightclientsParliaV1Header._decode(pointer, bs, sz);
return (r, sz + bytesRead);
}


// Encoder section

/**
* @dev The main encoder for memory
* @param r The struct to be encoded
* @return The encoded byte array
*/
function encode(Data memory r) internal pure returns (bytes memory) {
bytes memory bs = new bytes(_estimate(r));
uint256 sz = _encode(r, 32, bs);
assembly {
mstore(bs, sz)
}
return bs;
}
// inner encoder

/**
* @dev The encoder for internal usage
* @param r The struct to be encoded
* @param p The offset of bytes array to start decode
* @param bs The bytes array to be decoded
* @return The number of bytes encoded
*/
function _encode(Data memory r, uint256 p, bytes memory bs)
internal
pure
returns (uint)
{
uint256 offset = p;
uint256 pointer = p;

if (bytes(r.client_id).length != 0) {
pointer += ProtoBufRuntime._encode_key(
1,
ProtoBufRuntime.WireType.LengthDelim,
pointer,
bs
);
pointer += ProtoBufRuntime._encode_string(r.client_id, pointer, bs);
}

pointer += ProtoBufRuntime._encode_key(
2,
ProtoBufRuntime.WireType.LengthDelim,
pointer,
bs
);
pointer += IbcLightclientsParliaV1Header._encode_nested(r.header_1, pointer, bs);


pointer += ProtoBufRuntime._encode_key(
3,
ProtoBufRuntime.WireType.LengthDelim,
pointer,
bs
);
pointer += IbcLightclientsParliaV1Header._encode_nested(r.header_2, pointer, bs);

return pointer - offset;
}
// nested encoder

/**
* @dev The encoder for inner struct
* @param r The struct to be encoded
* @param p The offset of bytes array to start decode
* @param bs The bytes array to be decoded
* @return The number of bytes encoded
*/
function _encode_nested(Data memory r, uint256 p, bytes memory bs)
internal
pure
returns (uint)
{
/**
* First encoded `r` into a temporary array, and encode the actual size used.
* Then copy the temporary array into `bs`.
*/
uint256 offset = p;
uint256 pointer = p;
bytes memory tmp = new bytes(_estimate(r));
uint256 tmpAddr = ProtoBufRuntime.getMemoryAddress(tmp);
uint256 bsAddr = ProtoBufRuntime.getMemoryAddress(bs);
uint256 size = _encode(r, 32, tmp);
pointer += ProtoBufRuntime._encode_varint(size, pointer, bs);
ProtoBufRuntime.copyBytes(tmpAddr + 32, bsAddr + pointer, size);
pointer += size;
delete tmp;
return pointer - offset;
}
// estimator

/**
* @dev The estimator for a struct
* @param r The struct to be encoded
* @return The number of bytes encoded in estimation
*/
function _estimate(
Data memory r
) internal pure returns (uint) {
uint256 e;
e += 1 + ProtoBufRuntime._sz_lendelim(bytes(r.client_id).length);
e += 1 + ProtoBufRuntime._sz_lendelim(IbcLightclientsParliaV1Header._estimate(r.header_1));
e += 1 + ProtoBufRuntime._sz_lendelim(IbcLightclientsParliaV1Header._estimate(r.header_2));
return e;
}
// empty checker

function _empty(
Data memory r
) internal pure returns (bool) {

if (bytes(r.client_id).length != 0) {
return false;
}

return true;
}


//store function
/**
* @dev Store in-memory struct to storage
* @param input The in-memory struct
* @param output The in-storage struct
*/
function store(Data memory input, Data storage output) internal {
output.client_id = input.client_id;
IbcLightclientsParliaV1Header.store(input.header_1, output.header_1);
IbcLightclientsParliaV1Header.store(input.header_2, output.header_2);

}



//utility functions
/**
* @dev Return an empty struct
* @return r The empty struct
*/
function nil() internal pure returns (Data memory r) {
assembly {
r := 0
}
}

/**
* @dev Test whether a struct is empty
* @param x The struct to be tested
* @return r True if it is empty
*/
function isNil(Data memory x) internal pure returns (bool r) {
assembly {
r := iszero(x)
}
}
}
//library IbcLightclientsParliaV1Misbehaviour
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ require (
github.com/datachainlab/ethereum-ibc-relay-chain v0.2.1
github.com/ethereum/go-ethereum v1.12.0
github.com/hyperledger-labs/yui-relayer v0.4.2
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
)

Expand Down Expand Up @@ -157,8 +155,10 @@ require (
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion module/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func extractValidatorSet(h *types.Header) ([][]byte, error) {
for i := 0; i < validatorCount; i++ {
start := validatorBytesLength * i
validatorWithBLS := validatorsWithBLS[start : start+validatorBytesLength]
validatorSet = append(validatorSet, validatorWithBLS[:validatorBytesLengthBeforeLuban])
validatorSet = append(validatorSet, validatorWithBLS)
}

return validatorSet, nil
Expand Down
19 changes: 19 additions & 0 deletions module/misbehaviour.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package module

func (*Misbehaviour) ClientType() string {
return Parlia
}

func (h *Misbehaviour) GetClientID() string {
return h.ClientId
}

func (h *Misbehaviour) ValidateBasic() error {
if err := h.Header_1.ValidateBasic(); err != nil {
return err
}
if err := h.Header_2.ValidateBasic(); err != nil {
return err
}
return nil
}
Loading

0 comments on commit c15074e

Please sign in to comment.