Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
test(prover): rename some variables
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Oct 9, 2023
1 parent c25845a commit f8f09dd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
8 changes: 4 additions & 4 deletions pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func CheckProverBalance(
rpc *Client,
prover common.Address,
taikoL1Address common.Address,
bond *big.Int,
livenessBond *big.Int,
) (bool, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
defer cancel()
Expand All @@ -57,7 +57,7 @@ func CheckProverBalance(

log.Info("Prover's deposited taikoTokenBalance", "balance", depositedBalance.String(), "address", prover.Hex())

if bond.Cmp(depositedBalance) > 0 {
if livenessBond.Cmp(depositedBalance) > 0 {
// Check allowance on taiko token contract
allowance, err := rpc.TaikoToken.Allowance(&bind.CallOpts{Context: ctxWithTimeout}, prover, taikoL1Address)
if err != nil {
Expand All @@ -74,14 +74,14 @@ func CheckProverBalance(

log.Info("Prover's wallet taiko token balance", "balance", balance.String(), "address", prover.Hex())

if bond.Cmp(allowance) > 0 || bond.Cmp(balance) > 0 {
if livenessBond.Cmp(allowance) > 0 || livenessBond.Cmp(balance) > 0 {
log.Info(
"Assigned prover does not have required on-chain token balance or allowance",
"providedProver", prover.Hex(),
"depositedBalance", depositedBalance.String(),
"taikoTokenBalance", balance,
"allowance", allowance.String(),
"proofBond", bond,
"proofBond", livenessBond,
)
return false, nil
}
Expand Down
34 changes: 21 additions & 13 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) {
CapacityManager: p.capacityManager,
TaikoL1Address: p.cfg.TaikoL1Address,
Rpc: p.rpc,
Bond: protocolConfigs.LivenessBond,
LivenessBond: protocolConfigs.LivenessBond,
IsGuardian: p.cfg.GuardianProver,
}
if p.cfg.GuardianProver {
Expand Down Expand Up @@ -667,25 +667,36 @@ func (p *Prover) closeSubscription() {
// isValidProof checks if the given proof is a valid one.
func (p *Prover) isValidProof(
ctx context.Context,
blockID uint64,
parentHash common.Hash,
blockHash common.Hash,
event *bindings.TaikoL1ClientTransitionProved,
) (bool, error) {
parent, err := p.rpc.L2ParentByBlockId(ctx, new(big.Int).SetUint64(blockID))
parent, err := p.rpc.L2ParentByBlockId(ctx, event.BlockId)
if err != nil {
return false, err
}

block, err := p.rpc.L2.BlockByNumber(ctx, new(big.Int).SetUint64(blockID))
block, err := p.rpc.L2.BlockByNumber(ctx, event.BlockId)
if err != nil {
return false, err
}

if parent.Hash() == parentHash && blockHash == block.Hash() {
return true, nil
l2SignalService, err := p.rpc.TaikoL2.Resolve0(nil, rpc.StringToBytes32("signal_service"), false)
if err != nil {
return false, err
}

signalRoot, err := p.rpc.GetStorageRoot(
ctx,
p.rpc.L2GethClient,
l2SignalService,
event.BlockId,
)
if err != nil {
return false, err
}

return false, nil
return parent.Hash() == event.ParentHash &&
block.Hash() == event.BlockHash &&
signalRoot == event.SignalRoot, nil
}

// onTransitionProved verifies the proven block hash and will try contesting it if the block hash is wrong.
Expand All @@ -709,12 +720,9 @@ func (p *Prover) onTransitionProved(ctx context.Context, event *bindings.TaikoL1
return nil
}

// TODO(david): check signalRoot
isValidProof, err := p.isValidProof(
ctx,
event.BlockId.Uint64(),
event.ParentHash,
event.BlockHash,
event,
)
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions prover/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ func (srv *ProverServer) CreateAssignment(c echo.Context) error {
}

if !srv.isGuardian {
// TODO: use tier bond
ok, err := rpc.CheckProverBalance(c.Request().Context(), srv.rpc, srv.proverAddress, srv.taikoL1Address, srv.bond)
ok, err := rpc.CheckProverBalance(
c.Request().Context(),
srv.rpc,
srv.proverAddress,
srv.taikoL1Address,
srv.livenessBond,
)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
Expand Down
6 changes: 3 additions & 3 deletions prover/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ProverServer struct {
capacityManager *capacity.CapacityManager
taikoL1Address common.Address
rpc *rpc.Client
bond *big.Int
livenessBond *big.Int
isGuardian bool
}

Expand All @@ -54,7 +54,7 @@ type NewProverServerOpts struct {
CapacityManager *capacity.CapacityManager
TaikoL1Address common.Address
Rpc *rpc.Client
Bond *big.Int
LivenessBond *big.Int
IsGuardian bool
}

Expand All @@ -71,7 +71,7 @@ func New(opts *NewProverServerOpts) (*ProverServer, error) {
capacityManager: opts.CapacityManager,
taikoL1Address: opts.TaikoL1Address,
rpc: opts.Rpc,
bond: opts.Bond,
livenessBond: opts.LivenessBond,
isGuardian: opts.IsGuardian,
}

Expand Down
2 changes: 1 addition & 1 deletion prover/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *ProverServerTestSuite) SetupTest() {
CapacityManager: capacity.New(1024),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
Rpc: rpcClient,
Bond: common.Big0,
LivenessBond: common.Big0,
IsGuardian: false,
})
s.Nil(err)
Expand Down
2 changes: 1 addition & 1 deletion testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func NewTestProverServer(
CapacityManager: capacityManager,
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
Rpc: s.RpcClient,
Bond: protocolConfig.LivenessBond,
LivenessBond: protocolConfig.LivenessBond,
IsGuardian: true,
})
s.Nil(err)
Expand Down

0 comments on commit f8f09dd

Please sign in to comment.