Skip to content

Commit

Permalink
Merge branch 'main' into xiaodino/fix-decode-message-1
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Mar 11, 2024
2 parents c602cad + 627bf01 commit 7e36263
Show file tree
Hide file tree
Showing 24 changed files with 197 additions and 192 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/prometheus/client_golang v1.19.0
github.com/rabbitmq/amqp091-go v1.9.0
github.com/shopspring/decimal v1.3.1
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/swaggo/swag v1.16.3
github.com/testcontainers/testcontainers-go v0.28.0
github.com/urfave/cli/v2 v2.27.1
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,9 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4=
github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/swaggo/swag v1.16.3 h1:PnCYjPCah8FK4I26l2F/KQ4yz3sILcVUN3cTlBFA9Pg=
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@wagmi/cli": "^2.1.1",
"abitype": "^1.0.0",
"ajv": "^8.12.0",
"autoprefixer": "^10.4.17",
"autoprefixer": "^10.4.18",
"daisyui": "^4.7.2",
"dotenv": "^16.4.5",
"eslint": "^8.56.0",
Expand Down
26 changes: 22 additions & 4 deletions packages/eventindexer/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion packages/eventindexer/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}
}
},
"/chartByTask": {
"/chart/chartByTask": {
"get": {
"consumes": ["application/json"],
"produces": ["application/json"],
Expand All @@ -53,6 +53,20 @@
"name": "task",
"in": "query",
"required": true
},
{
"type": "string",
"description": "start date",
"name": "start",
"in": "query",
"required": true
},
{
"type": "string",
"description": "end date",
"name": "end",
"in": "query",
"required": true
}
],
"responses": {
Expand Down Expand Up @@ -280,6 +294,12 @@
"paginate.Page": {
"type": "object",
"properties": {
"error": {
"type": "boolean"
},
"error_message": {
"type": "string"
},
"first": {
"type": "boolean"
},
Expand Down
16 changes: 15 additions & 1 deletion packages/eventindexer/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ definitions:
type: object
paginate.Page:
properties:
error:
type: boolean
error_message:
type: string
first:
type: boolean
items: {}
Expand Down Expand Up @@ -113,7 +117,7 @@ paths:
schema:
$ref: "#/definitions/paginate.Page"
summary: Get assigned blocks by prover address
/chartByTask:
/chart/chartByTask:
get:
consumes:
- application/json
Expand All @@ -124,6 +128,16 @@ paths:
name: task
required: true
type: string
- description: start date
in: query
name: start
required: true
type: string
- description: end date
in: query
name: end
required: true
type: string
produces:
- application/json
responses:
Expand Down
13 changes: 10 additions & 3 deletions packages/eventindexer/pkg/http/get_chart_by_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ import (
// @Summary Get time series data for displaying charts
// @ID get-charts-by-task
// @Param task query string true "task to query"
// @Param start query string true "start date"
// @Param end query string true "end date"
// @Accept json
// @Produce json
// @Success 200 {object} eventindexer.ChartResponse
// @Router /chartByTask [get]
// @Router /chart/chartByTask [get]
func (srv *Server) GetChartByTask(c echo.Context) error {
cached, found := srv.cache.Get(c.QueryParam("task") + c.QueryParam("fee_token_address") + c.QueryParam("tier"))
cacheKey := c.QueryParam("task") +
c.QueryParam("fee_token_address") +
c.QueryParam("tier") +
c.QueryParam("start") +
c.QueryParam("end")
cached, found := srv.cache.Get(cacheKey)

var chart *eventindexer.ChartResponse

Expand All @@ -43,7 +50,7 @@ func (srv *Server) GetChartByTask(c echo.Context) error {
}

srv.cache.Set(
c.QueryParam("task")+c.QueryParam("fee_token_address")+c.QueryParam("tier"),
cacheKey,
chart,
cache.DefaultExpiration,
)
Expand Down
2 changes: 1 addition & 1 deletion packages/guardian-prover-health-check-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@tailwindcss/nesting": "0.0.0-insiders.565cd3e",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.0.2",
"autoprefixer": "^10.4.17",
"autoprefixer": "^10.4.18",
"daisyui": "^4.7.2",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
54 changes: 20 additions & 34 deletions packages/protocol/contracts/L1/gov/TaikoGovernor.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "@openzeppelin/contracts-upgradeable/governance/GovernorUpgradeable.sol";
import
"@openzeppelin/contracts-upgradeable/governance/compatibility/GovernorCompatibilityBravoUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesUpgradeable.sol";
import
"@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol";
import
"@openzeppelin/contracts-upgradeable/governance/extensions/GovernorTimelockControlUpgradeable.sol";
import "../../common/EssentialContract.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

/// @title TaikoGovernor
/// @custom:security-contact [email protected]
contract TaikoGovernor is
EssentialContract,
Ownable2StepUpgradeable,
GovernorCompatibilityBravoUpgradeable,
GovernorVotesUpgradeable,
GovernorVotesQuorumFractionUpgradeable,
GovernorTimelockControlUpgradeable
{
Expand All @@ -36,9 +33,8 @@ contract TaikoGovernor is
external
initializer
{
__Essential_init(_owner);
_transferOwnership(_owner == address(0) ? msg.sender : _owner);
__Governor_init("TaikoGovernor");
__GovernorCompatibilityBravo_init();
__GovernorVotes_init(_token);
__GovernorVotesQuorumFraction_init(4);
__GovernorTimelockControl_init(_timelock);
Expand All @@ -58,33 +54,6 @@ contract TaikoGovernor is
return super.propose(_targets, _values, _calldatas, _description);
}

/// @notice An overwrite of GovernorCompatibilityBravoUpgradeable's propose() as that one does
/// not check that the length of signatures equal the calldata.
/// @dev See vulnerability description here:
/// https://github.com/taikoxyz/taiko-mono/security/dependabot/114
/// See fix in OZ 4.8.3 here (URL broken down for readability):
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/
/// 0a25c1940ca220686588c4af3ec526f725fe2582/contracts/governance/compatibility/GovernorCompatibilityBravo.sol#L72
/// See {GovernorCompatibilityBravoUpgradeable-propose}
function propose(
address[] memory _targets,
uint256[] memory _values,
string[] memory _signatures,
bytes[] memory _calldatas,
string memory _description
)
public
virtual
override(GovernorCompatibilityBravoUpgradeable)
returns (uint256)
{
if (_signatures.length != _calldatas.length) revert TG_INVALID_SIGNATURES_LENGTH();

return GovernorCompatibilityBravoUpgradeable.propose(
_targets, _values, _signatures, _calldatas, _description
);
}

/// @dev See {GovernorUpgradeable-supportsInterface}
function supportsInterface(bytes4 _interfaceId)
public
Expand Down Expand Up @@ -124,6 +93,23 @@ contract TaikoGovernor is
return 1_000_000_000 ether / 10_000; // 0.01% of Taiko Token
}

/// @dev Cancel a proposal with GovernorBravo logic.
function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
)
public
virtual
override(IGovernorUpgradeable, GovernorUpgradeable, GovernorCompatibilityBravoUpgradeable)
returns (uint256)
{
return GovernorCompatibilityBravoUpgradeable.cancel(
targets, values, calldatas, descriptionHash
);
}

function _execute(
uint256 _proposalId,
address[] memory _targets,
Expand Down
10 changes: 7 additions & 3 deletions packages/protocol/contracts/L1/hooks/AssignmentHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ contract AssignmentHook is EssentialContract, IHook {
uint256 tip; // A tip to L1 block builder
}

event EtherPaymentFailed(address to, uint256 maxGas);

/// @notice Max gas paying the prover.
/// @dev This should be large enough to prevent the worst cases for the prover.
/// To assure a trustless relationship between the proposer and the prover it's
Expand Down Expand Up @@ -112,7 +114,9 @@ contract AssignmentHook is EssentialContract, IHook {
// Ether or ERC20 tokens.
if (assignment.feeToken == address(0)) {
// Paying Ether
_blk.assignedProver.sendEther(proverFee, MAX_GAS_PAYING_PROVER);
// Note that this payment may fail if it cost more gas
bool success = _blk.assignedProver.sendEther(proverFee, MAX_GAS_PAYING_PROVER, "");
if (!success) emit EtherPaymentFailed(_blk.assignedProver, MAX_GAS_PAYING_PROVER);
} else {
// Paying ERC20 tokens
IERC20(assignment.feeToken).safeTransferFrom(
Expand All @@ -122,12 +126,12 @@ contract AssignmentHook is EssentialContract, IHook {

// block.coinbase can be address(0) in tests
if (input.tip != 0 && block.coinbase != address(0)) {
address(block.coinbase).sendEther(input.tip);
address(block.coinbase).sendEtherAndVerify(input.tip);
}

// Send all remaining Ether back to TaikoL1 contract
if (address(this).balance > 0) {
taikoL1Address.sendEther(address(this).balance);
taikoL1Address.sendEtherAndVerify(address(this).balance);
}

emit BlockAssigned(_blk.assignedProver, _meta, assignment);
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibDepositing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ library LibDepositing {
revert L1_INVALID_ETH_DEPOSIT();
}

_resolver.resolve("bridge", false).sendEther(msg.value);
_resolver.resolve("bridge", false).sendEtherAndVerify(msg.value);

// Append the deposit to the queue.
address recipient_ = _recipient == address(0) ? msg.sender : _recipient;
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ library LibProposing {
}
// Refund Ether
if (address(this).balance != 0) {
msg.sender.sendEther(address(this).balance);
msg.sender.sendEtherAndVerify(address(this).balance);
}

// Check that after hooks, the Taiko Token balance of this contract
Expand Down
11 changes: 3 additions & 8 deletions packages/protocol/contracts/L1/provers/Guardians.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import "../../common/EssentialContract.sol";
/// @notice A contract that manages a set of guardians and their approvals.
/// @custom:security-contact [email protected]
abstract contract Guardians is EssentialContract {
/// @notice The minimum number of guardians
uint256 public constant MIN_NUM_GUARDIANS = 5;

/// @notice Contains the index of the guardian in `guardians` plus one (zero means not a
/// guardian)
/// @dev Slot 1
Expand Down Expand Up @@ -58,15 +55,13 @@ abstract contract Guardians is EssentialContract {
onlyOwner
nonReentrant
{
// We need at least MIN_NUM_GUARDIANS and at most 255 guardians (so the approval bits fit in
// a uint256)
if (_newGuardians.length < MIN_NUM_GUARDIANS || _newGuardians.length > type(uint8).max) {
// We need at most 255 guardians (so the approval bits fit in a uint256)
if (_newGuardians.length == 0 || _newGuardians.length > type(uint8).max) {
revert INVALID_GUARDIAN_SET();
}
// Minimum number of guardians to approve is at least equal or greater than half the
// guardians (rounded up) and less or equal than the total number of guardians
if (_minGuardians < (_newGuardians.length + 1) >> 1 || _minGuardians > _newGuardians.length)
{
if (_minGuardians == 0 || _minGuardians > _newGuardians.length) {
revert INVALID_MIN_GUARDIANS();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ contract TaikoL2 is CrossChainOwned {
{
if (_to == address(0)) revert L2_INVALID_PARAM();
if (_token == address(0)) {
_to.sendEther(address(this).balance);
_to.sendEtherAndVerify(address(this).balance);
} else {
IERC20(_token).safeTransfer(_to, IERC20(_token).balanceOf(address(this)));
}
Expand Down
Loading

0 comments on commit 7e36263

Please sign in to comment.